Skip to content

Commit f728c29

Browse files
authored
CLIENT-3524 Fix the client info calls that are causing deprecation warning messages on server 8.1+
1 parent 79b4e0d commit f728c29

File tree

18 files changed

+87
-264
lines changed

18 files changed

+87
-264
lines changed

client/src/com/aerospike/client/AerospikeClient.java

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5334,7 +5334,7 @@ private String buildCreateIndexInfoCommand(
53345334
Expression exp
53355335
) {
53365336
StringBuilder sb = new StringBuilder(1024);
5337-
Version currentServerVersion = node.getVersion();
5337+
Version currentServerVersion = node.getServerVersion();
53385338
String createIndexCommand = currentServerVersion.isGreaterOrEqual(Version.SERVER_VERSION_8_1) ? "sindex-create:namespace=": "sindex-create:ns=";
53395339

53405340
sb.append(createIndexCommand);
@@ -5348,40 +5348,52 @@ private String buildCreateIndexInfoCommand(
53485348
sb.append(";indexname=");
53495349
sb.append(indexName);
53505350

5351-
if (ctx != null && ctx.length > 0) {
5352-
byte[] bytes = Pack.pack(ctx);
5353-
String base64 = Crypto.encodeBase64(bytes);
5354-
5355-
sb.append(";context=");
5356-
sb.append(base64);
5357-
}
5358-
53595351
if (exp != null && exp.size() > 0) {
53605352
String base64 = exp.getBase64();
53615353

53625354
sb.append(";exp=");
53635355
sb.append(base64);
5364-
}
53655356

5366-
if (indexCollectionType != IndexCollectionType.DEFAULT) {
5367-
sb.append(";indextype=");
5368-
sb.append(indexCollectionType);
5369-
}
5357+
if (indexCollectionType != IndexCollectionType.DEFAULT) {
5358+
sb.append(";indextype=");
5359+
sb.append(indexCollectionType);
5360+
}
53705361

5371-
if (binName != null) {
5372-
sb.append(";indexdata=");
5373-
sb.append(binName);
5374-
sb.append(",");
5375-
} else {
53765362
sb.append(";type=");
5363+
sb.append(indexType);
5364+
} else {
5365+
if (ctx != null && ctx.length > 0) {
5366+
byte[] bytes = Pack.pack(ctx);
5367+
String base64 = Crypto.encodeBase64(bytes);
5368+
5369+
sb.append(";context=");
5370+
sb.append(base64);
5371+
}
5372+
5373+
if (indexCollectionType != IndexCollectionType.DEFAULT) {
5374+
sb.append(";indextype=");
5375+
sb.append(indexCollectionType);
5376+
}
5377+
5378+
if (node.getServerVersion().isGreaterOrEqual(Version.SERVER_VERSION_8_1)) {
5379+
sb.append(";bin=");
5380+
sb.append(binName);
5381+
sb.append(";type=");
5382+
sb.append(indexType);
5383+
} else {
5384+
sb.append(";indexdata=");
5385+
sb.append(binName);
5386+
sb.append(',');
5387+
sb.append(indexType);
5388+
}
53775389
}
5378-
sb.append(indexType);
5390+
53795391
return sb.toString();
53805392
}
53815393

53825394
private String buildDropIndexInfoCommand(Node node, String namespace, String setName, String indexName) {
53835395
StringBuilder sb = new StringBuilder(500);
5384-
Version currentServerVersion = node.getVersion();
5396+
Version currentServerVersion = node.getServerVersion();
53855397
String deleteIndexCommand = currentServerVersion.isGreaterOrEqual(Version.SERVER_VERSION_8_1) ? "sindex-delete:namespace=": "sindex-delete:ns=";
53865398

53875399
sb.append(deleteIndexCommand);

client/src/com/aerospike/client/Info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public static Map<String,String> request(InfoPolicy policy, Node node, String...
126126
* @param policy info command configuration parameters, pass in null for defaults
127127
* @param node server node
128128
*/
129+
@Deprecated
129130
public static Map<String,String> request(InfoPolicy policy, Node node) throws AerospikeException {
130131
int timeout = (policy == null) ? DEFAULT_TIMEOUT : policy.timeout;
131132
Connection conn = node.getConnection(timeout);

client/src/com/aerospike/client/admin/AdminCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public void createUser(Cluster cluster, AdminPolicy policy, String user, String
232232

233233
public void createPkiUser(Cluster cluster, AdminPolicy policy, String user, List<String> roles) {
234234
Node node = cluster.getRandomNode();
235-
Version nodeVer = node.getVersion();
235+
Version nodeVer = node.getServerVersion();
236236
if (nodeVer.compareTo(Version.SERVER_VERSION_8_1) < 0 ) {
237237
throw new AerospikeException("Node version " + nodeVer + " is less than required minimum version " + Version.SERVER_VERSION_8_1);
238238
}

client/src/com/aerospike/client/async/AsyncIndexTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void queryStatus(EventLoop eventLoop, InfoPolicy policy, Node node, TaskS
5656
listener.onFailure(new AerospikeException("Cluster is empty"));
5757
}
5858

59-
String command = buildStatusCommand(namespace, indexName);
59+
String command = buildStatusCommand(namespace, indexName, node.getServerVersion());
6060

6161
client.info(eventLoop, new InfoListener() {
6262
@Override

client/src/com/aerospike/client/cluster/Node.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public class Node implements Closeable {
9696
protected boolean rebalanceChanged;
9797
protected volatile boolean performLogin;
9898
protected volatile boolean active;
99-
private final Version version;
99+
private final Version serverVersion;
100100

101101
/**
102102
* Initialize server node with connection parameters.
@@ -113,7 +113,7 @@ public Node(Cluster cluster, NodeValidator nv) {
113113
this.sessionToken = nv.sessionToken;
114114
this.sessionExpiration = nv.sessionExpiration;
115115
this.features = nv.features;
116-
this.version = nv.version;
116+
this.serverVersion = nv.serverVersion;
117117
this.connsOpened = new AtomicInteger(1);
118118
this.connsClosed = new AtomicInteger(0);
119119
this.errorRateCount = new AtomicInteger(0);
@@ -1300,8 +1300,8 @@ public final int getRebalanceGeneration() {
13001300
/**
13011301
* Return this node's build version
13021302
*/
1303-
public Version getVersion() {
1304-
return version;
1303+
public Version getServerVersion() {
1304+
return serverVersion;
13051305
}
13061306

13071307
/**

client/src/com/aerospike/client/cluster/NodeValidator.java

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public final class NodeValidator {
4444
byte[] sessionToken;
4545
long sessionExpiration;
4646
int features;
47-
Version version;
47+
Version serverVersion;
4848

4949
/**
5050
* Return first valid node referenced by seed host aliases. In most cases, aliases
@@ -226,7 +226,6 @@ private void validateAddress(Cluster cluster, InetAddress address, String tlsNam
226226
commands.add("node");
227227
commands.add("partition-generation");
228228
commands.add("build");
229-
commands.add("features");
230229

231230
boolean validateCluster = cluster.validateClusterName();
232231
if (validateCluster) {
@@ -262,11 +261,11 @@ private void validateAddress(Cluster cluster, InetAddress address, String tlsNam
262261
validatePartitionGeneration(map);
263262
validateServerBuildVersion(map);
264263

265-
boolean sendUserAgent = version.isGreaterOrEqual(Version.SERVER_VERSION_8_1);
264+
boolean sendUserAgent = serverVersion.isGreaterOrEqual(Version.SERVER_VERSION_8_1);
266265
if (sendUserAgent) {
267266
Info.request(conn, "user-agent-set:value=" + getB64userAgent(cluster));
268267
}
269-
setFeatures(map);
268+
setFeatures(serverVersion);
270269

271270
if (validateCluster) {
272271
validateClusterName(cluster, map);
@@ -308,49 +307,29 @@ private void validatePartitionGeneration(HashMap<String,String> map) {
308307

309308
private void validateServerBuildVersion(HashMap<String,String> map) {
310309
String build = map.get("build");
311-
version = Version.convertStringToVersion(build, name, primaryAddress);
310+
serverVersion = Version.convertStringToVersion(build, name, primaryAddress);
312311
}
313312

314-
private void setFeatures(HashMap<String,String> map) {
315-
try {
316-
String featuresString = map.get("features");
317-
int begin = 0;
318-
int end = 0;
319-
320-
while (end < featuresString.length()) {
321-
end = featuresString.indexOf(';', begin);
322-
323-
if (end < 0) {
324-
end = featuresString.length();
325-
}
326-
327-
int len = end - begin;
328-
329-
if (featuresString.regionMatches(begin, "pscans", 0, len)) {
330-
this.features |= Node.HAS_PARTITION_SCAN;
331-
}
332-
else if (featuresString.regionMatches(begin, "query-show", 0, len)) {
333-
this.features |= Node.HAS_QUERY_SHOW;
334-
}
335-
else if (featuresString.regionMatches(begin, "batch-any", 0, len)) {
336-
this.features |= Node.HAS_BATCH_ANY;
337-
}
338-
else if (featuresString.regionMatches(begin, "pquery", 0, len)) {
339-
this.features |= Node.HAS_PARTITION_QUERY;
340-
}
341-
begin = end + 1;
313+
private void setFeatures(Version serverVersion) {
314+
if (serverVersion.isGreaterOrEqual(Version.SERVER_VERSION_PSCAN)) {
315+
this.features |= Node.HAS_PARTITION_SCAN;
316+
} else {
317+
// This client requires partition scan support. Partition scans were first
318+
// supported in server version 4.9. Do not allow any server node into the
319+
// cluster that is running server version < 4.9.
320+
if ((this.features & Node.HAS_PARTITION_SCAN) == 0) {
321+
throw new AerospikeException("Node " + this.name + ' ' + this.primaryHost +
322+
" version < 4.9. This client requires server version >= 4.9");
342323
}
343324
}
344-
catch (Throwable e) {
345-
// Unexpected exception. Use defaults.
325+
326+
if (serverVersion.isGreaterOrEqual(Version.SERVER_VERSION_QUERY_SHOW)) {
327+
features |= Node.HAS_QUERY_SHOW;
346328
}
347329

348-
// This client requires partition scan support. Partition scans were first
349-
// supported in server version 4.9. Do not allow any server node into the
350-
// cluster that is running server version < 4.9.
351-
if ((this.features & Node.HAS_PARTITION_SCAN) == 0) {
352-
throw new AerospikeException("Node " + this.name + ' ' + this.primaryHost +
353-
" version < 4.9. This client requires server version >= 4.9");
330+
if (serverVersion.isGreaterOrEqual(Version.SERVER_VERSION_PQUERY_BATCH_ANY)) {
331+
features |= Node.HAS_BATCH_ANY;
332+
features |= Node.HAS_PARTITION_QUERY;
354333
}
355334
}
356335

client/src/com/aerospike/client/policy/ClientPolicy.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ public class ClientPolicy {
113113
* Server proto-fd-idle-ms and client {@link ClientPolicy#maxSocketIdle} should be set to zero
114114
* (no reap) if minConnsPerNode is greater than zero. Reaping connections can defeat the purpose
115115
* of keeping connections in reserve for a future burst of activity.
116+
* <p>
117+
* <p>
118+
* Servers 8.1+ have deprecated proto-fd-idle-ms. When proto-fd-idle-ms is ultimately removed,
119+
* the server will stop automatically reaping based on socket idle timeouts.
116120
* <p>
117121
* Default: 0
118122
*/
@@ -187,6 +191,10 @@ public class ClientPolicy {
187191
* when maxSocketIdle is zero. Idle connections will still be trimmed down from peak
188192
* connections to min connections (minConnsPerNode and asyncMinConnsPerNode) using a
189193
* hard-coded 55 second limit in the cluster tend thread.
194+
* <p>
195+
* <p>
196+
* Servers 8.1+ have deprecated proto-fd-idle-ms. When proto-fd-idle-ms is ultimately removed,
197+
* the server will stop automatically reaping based on socket idle timeouts.
190198
* <p>
191199
* Default: 0
192200
*/

client/src/com/aerospike/client/task/ExecuteTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public int queryStatus() throws AerospikeException {
7474
String module = (scan) ? "scan" : "query";
7575

7676
for (Node node : nodes) {
77-
Version serverVersion = node.getVersion();
77+
Version serverVersion = node.getServerVersion();
7878
String cmd1 = serverVersion.isGreaterOrEqual(Version.SERVER_VERSION_8_1) ? "query-show:id=" + tid : "query-show:trid=" + tid;
7979
String cmd2 = serverVersion.isGreaterOrEqual(Version.SERVER_VERSION_8_1) ? module + "-show:id=" + tid : module + "-show:trid=" + tid;
8080
String cmd3 = serverVersion.isGreaterOrEqual(Version.SERVER_VERSION_8_1) ? "jobs:module=" + module + ";cmd=get-job;id=" + tid : "jobs:module=" + module + ";cmd=get-job;trid=" + tid;

client/src/com/aerospike/client/task/IndexTask.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public int queryStatus() {
5353
Node[] nodes = cluster.validateNodes();
5454

5555
for (Node node : nodes) {
56-
Version currentServerVersion = node.getVersion();
56+
Version currentServerVersion = node.getServerVersion();
5757
if (isCreate) {
5858
// Check index status.
5959
if (statusCommand == null) {
60-
statusCommand = IndexTask.buildStatusCommand(namespace, indexName);
60+
statusCommand = IndexTask.buildStatusCommand(namespace, indexName, node.getServerVersion());
6161
}
6262

6363
String response = Info.request(policy, node, statusCommand);
@@ -84,8 +84,10 @@ public int queryStatus() {
8484
return Task.COMPLETE;
8585
}
8686

87-
public static String buildStatusCommand(String namespace, String indexName) {
88-
return "sindex/" + namespace + '/' + indexName;
87+
public static String buildStatusCommand(String namespace, String indexName, Version serverVersion) {
88+
return serverVersion.isGreaterOrEqual(Version.SERVER_VERSION_8_1) ?
89+
"sindex-stat:namespace=" + namespace + ";indexname=" + indexName :
90+
"sindex/" + namespace + "/" + indexName;
8991
}
9092

9193
public static String buildExistsCommand(String namespace, String indexName, Version currentServerVersion) {

client/src/com/aerospike/client/util/Version.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
public final class Version implements Comparable<Version> {
2828
public static final Version SERVER_VERSION_8_1 = new Version(8, 1, 0, 0);
29+
public static final Version SERVER_VERSION_PSCAN = new Version(4, 9, 0, 3);
30+
public static final Version SERVER_VERSION_QUERY_SHOW = new Version(5, 7, 0, 0);
31+
public static final Version SERVER_VERSION_PQUERY_BATCH_ANY = new Version(6, 0, 0, 0);
2932

3033
public static Version getServerVersion(IAerospikeClient client, InfoPolicy policy) {
3134
Node node = client.getCluster().getRandomNode();

0 commit comments

Comments
 (0)