Skip to content

Commit

Permalink
Fix intermittent failure in examples. Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
ashetkar committed May 3, 2024
1 parent b3614e3 commit 1b4413e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<dependency>
<groupId>com.yugabyte</groupId>
<artifactId>jdbc-yugabytedb</artifactId>
<version>42.3.5-yb-4-SNAPSHOT</version>
<version>42.3.5-yb-5-SNAPSHOT</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
Expand Down
2 changes: 1 addition & 1 deletion examples/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ echo "Choose one of the below options"
echo "1. Demonstrate Uniform Load Balance"
echo "2. Demonstrate Topology Aware Load Balance"
echo "3. Demonstrate Fallback feature of Topology Aware Load Balance"
read -p "Please enter your option and then press enter:" choice
read -p "Please enter your option and then press enter: " choice
echo ""

case $choice in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ public static void main(String[] args) {
String controlHost = "127.0.0.1";
String controlPort = "5433";

controlUrl = "jdbc:yugabytedb://" + controlHost + ":" + controlPort
+ "/yugabyte?user=yugabyte&password=yugabyte&load-balance=true"
+ "&yb-servers-refresh-interval=0";
if (debugLogging) {
controlUrl = "jdbc:yugabytedb://" + controlHost
+ ":" + controlPort + "/yugabyte?user=yugabyte&password=yugabyte&load-balance=true&loggerLevel=debug&yb-servers-refresh-interval=0";
} else {
controlUrl = "jdbc:yugabytedb://" + controlHost
+ ":" + controlPort + "/yugabyte?user=yugabyte&password=yugabyte&load-balance=true&yb-servers-refresh-interval=0";
controlUrl = controlUrl + "&loggerLevel=debug";
}

System.out.println("Setting up the connection pool having 6 connections.......");
Expand Down Expand Up @@ -83,6 +82,7 @@ protected static void testUsingHikariPool(String poolName, String lbpropvalue, S
if (!lbpropvalue.equals("true")) {
poolProperties.setProperty("dataSource.topologyKeys", lookupKey);
}
poolProperties.setProperty("dataSource.ybServersRefreshInterval", "0");

HikariConfig hikariConfig = new HikariConfig(poolProperties);
hikariConfig.validate();
Expand Down
13 changes: 7 additions & 6 deletions examples/uniform_load_balance_run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash

# Copyright (c) YugaByte, Inc.
#
Expand Down Expand Up @@ -41,15 +41,15 @@ finish() {
kill -9 $2 >> yb-ctl.log 2>&1

#deleting the temporary files
rm -rf .jdbc_example_app_checker
rm -rf .jdbc_example_app_checker
rm -rf .jdbc_example_app_checker2
rm -rf .jdbc_example_app_checker3
rm -rf .jdbc_example_app_checker3
rm -rf .notify_shell_script
}

#this function basically checks the $file content and keep it paused until required content is present
pauseScript() {
#just creating the file if it doesn't exsits
#just creating the file if it doesn't exist
file=.notify_shell_script
touch $file

Expand Down Expand Up @@ -80,11 +80,11 @@ $INSTALL_DIR/bin/yb-ctl destroy > yb-ctl.log 2>&1

echo "Creating a 3-node, RF-3 cluster (live nodes: 1,2,3)"
$INSTALL_DIR/bin/yb-ctl create --rf 3 >> yb-ctl.log 2>&1

SLEEP 5

#deleting the checker file if exists
verbosePrint $VERBOSE "Deleting all the temporary checker files if exists"
rm -rf .jdbc_example_app_checker
rm -rf .jdbc_example_app_checker
rm -rf .jdbc_example_app_checker2
rm -rf .jdbc_example_app_checker3 #to keep the java app running until killed
rm -rf .notify_shell_script
Expand All @@ -106,6 +106,7 @@ interact $INTERACTIVE

echoSleep "Adding Node-4 to the cluster (live nodes: 1,2,3,4)"
$INSTALL_DIR/bin/yb-ctl add_node >> yb-ctl.log 2>&1
SLEEP 5

touch .jdbc_example_app_checker #resuming the java app

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ public static ClusterAwareLoadBalancer getInstance(int refreshListSeconds) {
if (instance == null) {
instance = new ClusterAwareLoadBalancer();
instance.refreshListSeconds =
refreshListSeconds > 0 && refreshListSeconds <= LoadBalanceProperties.MAX_REFRESH_INTERVAL ?
refreshListSeconds >= 0 && refreshListSeconds <= LoadBalanceProperties.MAX_REFRESH_INTERVAL ?
refreshListSeconds : LoadBalanceProperties.DEFAULT_REFRESH_INTERVAL;
LOGGER.fine("Created a new cluster-aware LB instance with refresh" +
" interval " + instance.refreshListSeconds + " seconds");
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions pgjdbc/src/main/java/com/yugabyte/ysql/LoadBalanceProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,16 @@ public String processURLAndProperties() {
try {
refreshInterval = Integer.parseInt(lbParts[1]);
if (refreshInterval < 0 || refreshInterval > MAX_REFRESH_INTERVAL) {
LOGGER.warning("Provided yb-servers-refresh-interval ("
+ refreshInterval + ") is outside the permissible range,"
+ " setting it to 300 seconds");
refreshInterval = DEFAULT_REFRESH_INTERVAL;
} else {
refreshIntervalSpecified = true;
}
} catch (NumberFormatException nfe) {
LOGGER.warning("Provided yb-servers-refresh-interval ("
+ refreshInterval + ") is invalid, setting it to 300 seconds");
refreshInterval = DEFAULT_REFRESH_INTERVAL;
}
} else if (part.startsWith(explicitFallbackOnlyKey)) {
Expand Down Expand Up @@ -194,11 +199,16 @@ public String processURLAndProperties() {
try {
refreshInterval = Integer.parseInt(propValue);
if (refreshInterval < 0 || refreshInterval > MAX_REFRESH_INTERVAL) {
LOGGER.warning("Provided yb-servers-refresh-interval ("
+ refreshInterval + ") is outside the permissible range,"
+ " setting it to 300 seconds");
refreshInterval = DEFAULT_REFRESH_INTERVAL;
} else {
refreshIntervalSpecified = true;
}
} catch (NumberFormatException nfe) {
LOGGER.warning("Provided yb-servers-refresh-interval ("
+ refreshInterval + ") is invalid, setting it to 300 seconds");
refreshInterval = DEFAULT_REFRESH_INTERVAL;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ public void setAdditionalEndpoints(String value) {
public String getAdditionalEndPoints() {
return additionalEndPoints;
}

public String getDescription() {
return "YB cluster-aware DataSource from YugabyteDB JDBC Driver (YSQL)";
}
}

0 comments on commit 1b4413e

Please sign in to comment.