Skip to content

Commit e677483

Browse files
authored
CLIENT-3624 Fix the client info calls that are causing deprecation warning messages on server 8.1+
1 parent 647bb2e commit e677483

File tree

18 files changed

+113
-257
lines changed

18 files changed

+113
-257
lines changed

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

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

53385338
sb.append(createIndexCommand);
@@ -5346,40 +5346,53 @@ private String buildCreateIndexInfoCommand(
53465346
sb.append(";indexname=");
53475347
sb.append(indexName);
53485348

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

53605352
sb.append(";exp=");
53615353
sb.append(base64);
5362-
}
53635354

5364-
if (indexCollectionType != IndexCollectionType.DEFAULT) {
5365-
sb.append(";indextype=");
5366-
sb.append(indexCollectionType);
5367-
}
5355+
if (indexCollectionType != IndexCollectionType.DEFAULT) {
5356+
sb.append(";indextype=");
5357+
sb.append(indexCollectionType);
5358+
}
53685359

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

53805393
private String buildDropIndexInfoCommand(Node node, String namespace, String setName, String indexName) {
53815394
StringBuilder sb = new StringBuilder(500);
5382-
Version currentServerVersion = node.getVersion();
5395+
Version currentServerVersion = node.getServerVersion();
53835396
String deleteIndexCommand = currentServerVersion.isGreaterOrEqual(Version.SERVER_VERSION_8_1) ? "sindex-delete:namespace=": "sindex-delete:ns=";
53845397

53855398
sb.append(deleteIndexCommand);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public static Map<String,String> request(InfoPolicy policy, Node node, String...
125125
* @param policy info command configuration parameters, pass in null for defaults
126126
* @param node server node
127127
*/
128+
@Deprecated(since="8.1.0")
128129
public static Map<String,String> request(InfoPolicy policy, Node node) throws AerospikeException {
129130
int timeout = (policy == null) ? DEFAULT_TIMEOUT : policy.timeout;
130131
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
@@ -231,7 +231,7 @@ public void createUser(Cluster cluster, AdminPolicy policy, String user, String
231231

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

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.serverVersion);
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+
public 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: 49 additions & 37 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,62 @@ 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;
313+
/*
314+
private void SetFeatures(Version serverVersion)
315+
{
316+
if (serverVersion >= Node.SERVER_VERSION_PSCAN)
317+
{
318+
features |= Node.HAS_PARTITION_SCAN;
319+
}
320+
else
321+
{
322+
// This client requires partition scan support. Partition scans were first
323+
// supported in server version 4.9. Do not allow any server node into the
324+
// cluster that is running server version < 4.9.
325+
if ((this.features & Node.HAS_PARTITION_SCAN) == 0)
326+
{
327+
throw new AerospikeException("Node " + this.name + ' ' + this.primaryHost +
328+
" version < 4.9. This client requires server version >= 4.9");
329+
}
330+
}
319331
320-
while (end < featuresString.length()) {
321-
end = featuresString.indexOf(';', begin);
332+
if (serverVersion >= Node.SERVER_VERSION_QUERY_SHOW)
333+
{
334+
features |= Node.HAS_QUERY_SHOW;
335+
}
322336
323-
if (end < 0) {
324-
end = featuresString.length();
325-
}
337+
if (serverVersion >= Node.SERVER_VERSION_PQUERY_BATCH_ANY)
338+
{
339+
features |= Node.HAS_BATCH_ANY;
340+
features |= Node.HAS_PARTITION_QUERY;
341+
}
342+
}
343+
*/
326344

327-
int len = end - begin;
328345

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;
346+
private void setFeatures(Version serverVersion) {
347+
if (serverVersion.isGreaterOrEqual(Version.SERVER_VERSION_PSCAN)) {
348+
this.features |= Node.HAS_PARTITION_SCAN;
349+
} else {
350+
// This client requires partition scan support. Partition scans were first
351+
// supported in server version 4.9. Do not allow any server node into the
352+
// cluster that is running server version < 4.9.
353+
if ((this.features & Node.HAS_PARTITION_SCAN) == 0) {
354+
throw new AerospikeException("Node " + this.name + ' ' + this.primaryHost +
355+
" version < 4.9. This client requires server version >= 4.9");
342356
}
343357
}
344-
catch (Throwable e) {
345-
// Unexpected exception. Use defaults.
358+
359+
if (serverVersion.isGreaterOrEqual(Version.SERVER_VERSION_QUERY_SHOW)) {
360+
features |= Node.HAS_QUERY_SHOW;
346361
}
347362

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");
363+
if (serverVersion.isGreaterOrEqual(Version.SERVER_VERSION_PQUERY_BATCH_ANY)) {
364+
features |= Node.HAS_BATCH_ANY;
365+
features |= Node.HAS_PARTITION_QUERY;
354366
}
355367
}
356368

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.serverVersion);
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)