Skip to content

Commit

Permalink
ENG-3059: Keep java client API to pass in number of tablets for redis…
Browse files Browse the repository at this point in the history
… table creation.

Summary:
To keep a backward compatible client app that can be called from newer YW on older versions of YB.

Test Plan:
Jenkins: java only

Created universe from UI/YW using this local java client with older "0.9.6.0-b8" YB, and redis got created correctly.

Reviewers: bogdan

Reviewed By: bogdan

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D4405
  • Loading branch information
bbaddepudi committed Mar 19, 2018
1 parent e321311 commit 28ca802
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions java/yb-client/src/main/java/org/yb/client/YBClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,40 @@ public YBClient(AsyncYBClient asyncClient) {
this.asyncClient = asyncClient;
}

/**
* Create redis table options object.
* @param numTablets number of pre-split tablets.
* @return an options object to be used during table creation.
*/
public static CreateTableOptions getRedisTableOptions(int numTablets) {
CreateTableOptions cto = new CreateTableOptions();
if (numTablets <= 0) {
String msg = "Number of tablets " + numTablets + " cannot be less than one.";
LOG.error(msg);
throw new RuntimeException(msg);
}

cto.setTableType(TableType.REDIS_TABLE_TYPE)
.setNumTablets(numTablets);
return cto;
}

/**
* Create a redis table on the cluster with the specified name and tablet count.
* @param name Tables name
* @param numTablets number of pre-split tablets
* @return an object to communicate with the created table.
*/
public YBTable createRedisTable(String name, int numTablets) throws Exception {
CreateKeyspaceResponse resp = this.createKeyspace(REDIS_KEYSPACE_NAME);
if (resp.hasError()) {
throw new RuntimeException("Could not create keyspace " + REDIS_KEYSPACE_NAME +
". Error :" + resp.errorMessage());
}
return createTable(REDIS_KEYSPACE_NAME, name, getRedisSchema(),
getRedisTableOptions(numTablets));
}

/**
* Create a redis table on the cluster with the specified name.
* @param name Table name
Expand All @@ -103,8 +137,8 @@ public YBClient(AsyncYBClient asyncClient) {
public YBTable createRedisTable(String name) throws Exception {
CreateKeyspaceResponse resp = this.createKeyspace(REDIS_KEYSPACE_NAME);
if (resp.hasError()) {
throw new RuntimeException("Could not create keyspace " + REDIS_KEYSPACE_NAME + ". Error :" +
resp.errorMessage());
throw new RuntimeException("Could not create keyspace " + REDIS_KEYSPACE_NAME +
". Error :" + resp.errorMessage());
}
return createTable(REDIS_KEYSPACE_NAME, name, getRedisSchema(),
new CreateTableOptions().setTableType(TableType.REDIS_TABLE_TYPE));
Expand Down

0 comments on commit 28ca802

Please sign in to comment.