diff --git a/jdbc/README.md b/jdbc/README.md index c8b6ac5612..75f9babc91 100644 --- a/jdbc/README.md +++ b/jdbc/README.md @@ -73,6 +73,24 @@ db.passwd=admin Be sure to use your driver class, a valid JDBC connection string, and credentials to your database. +For connection fail-over in a DBMS cluster specify the connection string as follows (example based on Postgres): + +```sh +db.driver=org.postgresql.Driver +db.url=jdbc:postgresql://IP1:PORT1,IP2:PORT2,IP3:PORT3/ycsb +db.user=admin +db.passwd=admin +``` + +For using multiple shards in a DBMS cluster specify the connection string as follows by using `;`as delimiter (example based on PostgreSQL): + +```sh +db.driver=org.postgresql.Driver +db.url=jdbc:postgresql://host1:port1/ycsb;jdbc:postgresql://host2:port2/ycsb +db.user=admin +db.passwd=admin +``` + You can add these to your workload configuration or a separate properties file and specify it with ```-P``` or you can add the properties individually to your ycsb command with ```-p```. ### 5. Add your JDBC Driver to the classpath @@ -115,8 +133,3 @@ Some JDBC drivers support re-writing batched insert statements into multi-row in - set JDBC driver specific connection parameter in **db.url** to enable the rewrite as shown in the examples below: * MySQL [rewriteBatchedStatements=true](https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-configuration-properties.html) with `db.url=jdbc:mysql://127.0.0.1:3306/ycsb?rewriteBatchedStatements=true` * Postgres [reWriteBatchedInserts=true](https://jdbc.postgresql.org/documentation/head/connect.html#connection-parameters) with `db.url=jdbc:postgresql://127.0.0.1:5432/ycsb?reWriteBatchedInserts=true` - - - - - diff --git a/jdbc/src/main/java/com/yahoo/ycsb/db/JdbcDBClient.java b/jdbc/src/main/java/com/yahoo/ycsb/db/JdbcDBClient.java index a48c3f5252..1a8ae51fbe 100644 --- a/jdbc/src/main/java/com/yahoo/ycsb/db/JdbcDBClient.java +++ b/jdbc/src/main/java/com/yahoo/ycsb/db/JdbcDBClient.java @@ -200,7 +200,10 @@ public void init() throws DBException { } int shardCount = 0; conns = new ArrayList(3); - final String[] urlArr = urls.split(","); + // for a longer explanation see the README.md + // semicolons aren't present in JDBC urls, so we use them to delimit + // multiple JDBC connections to shard across. + final String[] urlArr = urls.split(";"); for (String url : urlArr) { System.out.println("Adding shard node URL: " + url); Connection conn = DriverManager.getConnection(url, user, passwd);