Skip to content

Commit

Permalink
[jdbc] Changed sharded url delimiter to semicolon (#1233)
Browse files Browse the repository at this point in the history
* changed the url splitting delimiter from , to ; to enable fail-over connection strings for JDBC
* included jdbc cluster connection strings in README

Co-authored-by: Sean Busbey <[email protected]>
  • Loading branch information
seybi87 and busbey committed Sep 8, 2019
1 parent fc9f1a2 commit 77080a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
23 changes: 18 additions & 5 deletions jdbc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`





5 changes: 4 additions & 1 deletion jdbc/src/main/java/com/yahoo/ycsb/db/JdbcDBClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ public void init() throws DBException {
}
int shardCount = 0;
conns = new ArrayList<Connection>(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);
Expand Down

0 comments on commit 77080a3

Please sign in to comment.