Skip to content

Commit

Permalink
Merge pull request #339 from aerospike/stage-jdk8
Browse files Browse the repository at this point in the history
Java Client 8.1.4 for JDK8
  • Loading branch information
BrianNichols authored Sep 17, 2024
2 parents 0fcc584 + 95a64d9 commit b2d87cb
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 38 deletions.
2 changes: 1 addition & 1 deletion benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-parent</artifactId>
<version>8.1.3</version>
<version>8.1.4</version>
</parent>
<artifactId>aerospike-benchmarks</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-parent</artifactId>
<version>8.1.3</version>
<version>8.1.4</version>
</parent>
<artifactId>aerospike-client-jdk8</artifactId>
<packaging>jar</packaging>
Expand Down
10 changes: 9 additions & 1 deletion client/src/com/aerospike/client/ResultCode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 Aerospike, Inc.
* Copyright 2012-2024 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements WHICH ARE COMPATIBLE WITH THE APACHE LICENSE, VERSION 2.0.
Expand Down Expand Up @@ -233,6 +233,11 @@ public final class ResultCode {
*/
public static final int LOST_CONFLICT = 28;

/**
* Write can't complete until XDR finishes shipping.
*/
public static final int XDR_KEY_BUSY = 32;

/**
* There are no more records left for query.
*/
Expand Down Expand Up @@ -582,6 +587,9 @@ public static String getResultString(int resultCode) {
case LOST_CONFLICT:
return "Transaction failed due to conflict with XDR";

case XDR_KEY_BUSY:
return "Write can't complete until XDR finishes shipping";

case QUERY_END:
return "Query end";

Expand Down
12 changes: 6 additions & 6 deletions client/src/com/aerospike/client/cluster/Cluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,11 @@ private final void tend(boolean failIfNotConnected, boolean isInit) {
}

// Handle nodes changes determined from refreshes.
ArrayList<Node> removeList = findNodesToRemove(peers.refreshCount);
findNodesToRemove(peers);

// Remove nodes in a batch.
if (removeList.size() > 0) {
removeNodes(removeList);
if (peers.removeList.size() > 0) {
removeNodes(peers.removeList);
}
}

Expand Down Expand Up @@ -762,8 +762,9 @@ protected Node createNode(NodeValidator nv) {
return node;
}

private final ArrayList<Node> findNodesToRemove(int refreshCount) {
ArrayList<Node> removeList = new ArrayList<Node>();
private final void findNodesToRemove(Peers peers) {
int refreshCount = peers.refreshCount;
ArrayList<Node> removeList = peers.removeList;

for (Node node : nodes) {
if (! node.isActive()) {
Expand Down Expand Up @@ -797,7 +798,6 @@ private final ArrayList<Node> findNodesToRemove(int refreshCount) {
}
}
}
return removeList;
}

private final boolean findNodeInPartitionMap(Node filter) {
Expand Down
44 changes: 29 additions & 15 deletions client/src/com/aerospike/client/cluster/Node.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 Aerospike, Inc.
* Copyright 2012-2024 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements WHICH ARE COMPATIBLE WITH THE APACHE LICENSE, VERSION 2.0.
Expand Down Expand Up @@ -426,7 +426,7 @@ protected final void refreshPeers(Peers peers) {
boolean peersValidated = true;

for (Peer peer : peers.peers) {
if (findPeerNode(cluster, peers, peer.nodeName)) {
if (findPeerNode(cluster, peers, peer)) {
// Node already exists. Do not even try to connect to hosts.
continue;
}
Expand All @@ -450,19 +450,16 @@ protected final void refreshPeers(Peers peers) {
if (Log.warnEnabled()) {
Log.warn("Peer node " + peer.nodeName + " is different than actual node " + nv.name + " for host " + host);
}

if (findPeerNode(cluster, peers, nv.name)) {
// Node already exists. Do not even try to connect to hosts.
nv.primaryConn.close();
nodeValidated = true;
break;
}
}

// Create new node.
Node node = cluster.createNode(nv);
peers.nodes.put(nv.name, node);
nodeValidated = true;
nodeValidated = true;

if (peer.replaceNode != null) {
peers.removeList.add(peer.replaceNode);
}
break;
}
catch (Throwable e) {
Expand Down Expand Up @@ -490,20 +487,37 @@ protected final void refreshPeers(Peers peers) {
}
}

private static boolean findPeerNode(Cluster cluster, Peers peers, String nodeName) {
private static boolean findPeerNode(Cluster cluster, Peers peers, Peer peer) {
// Check global node map for existing cluster.
Node node = cluster.nodesMap.get(nodeName);
Node node = cluster.nodesMap.get(peer.nodeName);

if (node != null) {
node.referenceCount++;
return true;
// Node name found.
if (node.failures <= 0 || node.address.getAddress().isLoopbackAddress()) {
// If the node does not have cluster tend errors or is localhost,
// reject new peer as the IP address does not need to change.
node.referenceCount++;
return true;
}

// Match peer hosts with the node host.
for (Host h : peer.hosts) {
if (h.equals(node.host)) {
// Main node host is also the same as one of the peer hosts.
// Peer should not be added.
node.referenceCount++;
return true;
}
}
peer.replaceNode = node;
}

// Check local node map for this tend iteration.
node = peers.nodes.get(nodeName);
node = peers.nodes.get(peer.nodeName);

if (node != null) {
node.referenceCount++;
peer.replaceNode = null;
return true;
}
return false;
Expand Down
3 changes: 2 additions & 1 deletion client/src/com/aerospike/client/cluster/Peer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 Aerospike, Inc.
* Copyright 2012-2024 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements WHICH ARE COMPATIBLE WITH THE APACHE LICENSE, VERSION 2.0.
Expand All @@ -24,4 +24,5 @@ public final class Peer {
String nodeName;
String tlsName;
List<Host> hosts;
Node replaceNode;
}
4 changes: 3 additions & 1 deletion client/src/com/aerospike/client/cluster/Peers.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 Aerospike, Inc.
* Copyright 2012-2024 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements WHICH ARE COMPATIBLE WITH THE APACHE LICENSE, VERSION 2.0.
Expand All @@ -26,13 +26,15 @@
public final class Peers {
public final ArrayList<Peer> peers;
public final HashMap<String,Node> nodes;
public final ArrayList<Node> removeList;
private final HashSet<Host> invalidHosts;
public int refreshCount;
public boolean genChanged;

public Peers(int peerCapacity) {
peers = new ArrayList<Peer>(peerCapacity);
nodes = new HashMap<String,Node>(16);
removeList = new ArrayList<Node>();
invalidHosts = new HashSet<Host>(8);
}

Expand Down
29 changes: 24 additions & 5 deletions client/src/com/aerospike/client/command/RegisterCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 Aerospike, Inc.
* Copyright 2012-2024 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements WHICH ARE COMPATIBLE WITH THE APACHE LICENSE, VERSION 2.0.
Expand Down Expand Up @@ -55,11 +55,23 @@ public static RegisterTask register(Cluster cluster, Policy policy, byte[] bytes
String file = null;
String line = null;
String message = null;
String messageNew = null;
int errorCode = 0;

while (parser.next()) {
String name = parser.getName();

if (name.equals("error")) {

if (name.startsWith("ERROR")) {
// New error format: ERROR:<code>:<msg1>;file=<filename>;line=<line>;message=<base64 encoded msg2>
int idx = name.indexOf(';');
String s = (idx > 0)? name.substring(0, idx) : name;
Info.Error ie = new Info.Error(s);
messageNew = ie.message;
errorCode = ie.code;
file = parser.getValue();
}
else if (name.equals("error")) {
// Old error format: error=<code>;file=<filename>;line=<line>;message=<base64 encoded msg>
error = parser.getValue();
}
else if (name.equals("file")) {
Expand All @@ -72,8 +84,15 @@ else if (name.equals("message")) {
message = parser.getStringBase64();
}
}

if (error != null) {

if (errorCode != 0) {
throw new AerospikeException(errorCode, "Registration failed: " + System.lineSeparator() +
"File: " + file + System.lineSeparator() +
"Line: " + line + System.lineSeparator() +
"Message: " + messageNew + ". " + message
);
}
else if (error != null) {
throw new AerospikeException("Registration failed: " + error + System.lineSeparator() +
"File: " + file + System.lineSeparator() +
"Line: " + line + System.lineSeparator() +
Expand Down
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-parent</artifactId>
<version>8.1.3</version>
<version>8.1.4</version>
</parent>
<artifactId>aerospike-examples</artifactId>
<packaging>jar</packaging>
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.aerospike</groupId>
<artifactId>aerospike-parent</artifactId>
<name>aerospike-parent</name>
<version>8.1.3</version>
<version>8.1.4</version>
<packaging>pom</packaging>
<url>https://github.com/aerospike/aerospike-client-java</url>

Expand Down Expand Up @@ -39,12 +39,12 @@
<maven-surefire-plugin.version>2.18.1</maven-surefire-plugin.version>
<maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>

<netty.version>4.1.111.Final</netty.version>
<netty.version>4.1.112.Final</netty.version>
<netty.tcnative.version>2.0.62.Final</netty.tcnative.version>
<grpc.version>1.59.0</grpc.version>
<grpc.version>1.65.1</grpc.version>
<luaj-jse.version>3.0.1</luaj-jse.version>
<jbcrypt.version>0.4</jbcrypt.version>
<commons-cli.version>1.8.0</commons-cli.version>
<commons-cli.version>1.9.0</commons-cli.version>
<junit.version>4.13.1</junit.version>
</properties>

Expand Down
2 changes: 1 addition & 1 deletion proxy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-parent</artifactId>
<version>8.1.3</version>
<version>8.1.4</version>
</parent>
<artifactId>aerospike-proxy-client</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-parent</artifactId>
<version>8.1.3</version>
<version>8.1.4</version>
</parent>
<artifactId>aerospike-client-test</artifactId>
<packaging>jar</packaging>
Expand Down

0 comments on commit b2d87cb

Please sign in to comment.