Skip to content

Commit

Permalink
Merge pull request #322 from sUpniverse/supniverse/cancel_message
Browse files Browse the repository at this point in the history
ENHANCE: add node information to the cancellation message
  • Loading branch information
jhpark816 authored Jan 29, 2021
2 parents ded452c + 247f141 commit 1c77f7d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/main/java/net/spy/memcached/MemcachedConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ private void updateConnections(List<InetSocketAddress> addrs) throws IOException
List<MemcachedNode> removeNodes = new ArrayList<MemcachedNode>();

for (MemcachedNode node : locator.getAll()) {
if (addrs.contains((InetSocketAddress) node.getSocketAddress())) {
addrs.remove((InetSocketAddress) node.getSocketAddress());
if (addrs.contains(node.getSocketAddress())) {
addrs.remove(node.getSocketAddress());
} else {
removeNodes.add(node);
}
Expand Down Expand Up @@ -749,7 +749,7 @@ private void handleIO(SelectionKey sk) {

qa.setupForAuth("due to exception"); // noop if !shouldAuth
getLogger().warn("Reconnecting due to exception on %s", qa, e);
lostConnection(qa, ReconnDelay.DEFAULT, "exception" + e);
lostConnection(qa, ReconnDelay.DEFAULT, e.getMessage());
}
qa.fixupOps();
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/spy/memcached/MemcachedNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ public interface MemcachedNode {
*/
int getSelectionOps();

/**
* Get the node name used for reading ip, port and hostname from this node
*/
String getNodeName();

/**
* Get the buffer used for reading data from this node.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/spy/memcached/MemcachedNodeROImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public String toString() {
return root.toString();
}

@Override
public String getNodeName() {
return root.getNodeName();
}

public MemcachedNode getMemcachedNode() {
return root;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ public final OperationException getException() {

public final void cancel(String cause) {
cancelled = true;
cancelCause = "Cancelled (" + cause + ")";
if (handlingNode != null) {
cancelCause = "Cancelled (" + cause + " : (" + handlingNode.getNodeName() + ")" + ")";
} else {
cancelCause = "Cancelled (" + cause + ")";
}
wasCancelled();
callback.complete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ public final int getSelectionOps() {
return rv;
}

public final String getNodeName() {
return nodeName;
}

public final ByteBuffer getRbuf() {
return rbuf;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void testReadOnliness() throws Exception {

Set<String> acceptable = new HashSet<String>(Arrays.asList(
"toString", "getSocketAddress", "getBytesRemainingToWrite",
"getReconnectCount", "getSelectionOps", "hasReadOp",
"getReconnectCount", "getSelectionOps", "getNodeName", "hasReadOp",
"hasWriteOp", "isActive", "isFirstConnecting"));

for (Method meth : MemcachedNode.class.getMethods()) {
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/net/spy/memcached/MockMemcachedNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public int getSelectionOps() {
return 0;
}

@Override
public String getNodeName() {
return null;
}

public ByteBuffer getRbuf() {
return null;
}
Expand Down

0 comments on commit 1c77f7d

Please sign in to comment.