Permalink
Browse files

SPY-110: Update KetamaNodeLocator allNodes on reconfigure.

This changeset updates the KetamaNodeLocator to also change the
allNodes on reconfigure, not only the ketamaNodes. This fixes
an issue where broadcast operations (which rely on the allNodes
collection) were sent to the wrong targets.

Change-Id: I1184ab8f3c564d181d832cad37e63ede2dabc631
Reviewed-on: http://review.couchbase.org/24180
Reviewed-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
  • Loading branch information...
1 parent 821844d commit 5ca6904eb7357dee35ba53444f3cd542a1ed6f75 @daschl daschl committed with daschl Jan 24, 2013
@@ -48,7 +48,7 @@
public final class KetamaNodeLocator extends SpyObject implements NodeLocator {
private volatile TreeMap<Long, MemcachedNode> ketamaNodes;
- private final Collection<MemcachedNode> allNodes;
+ private volatile Collection<MemcachedNode> allNodes;
private final HashAlgorithm hashAlg;
private final KetamaNodeLocatorConfiguration config;
@@ -152,6 +152,7 @@ public NodeLocator getReadonlyCopy() {
@Override
public void updateLocator(List<MemcachedNode> nodes) {
+ allNodes = nodes;
setKetamaNodes(nodes);
}
@@ -24,9 +24,11 @@
package net.spy.memcached;
import java.net.InetSocketAddress;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
+import org.jmock.Mock;
/**
* Test ketama node location.
@@ -59,6 +61,31 @@ public void testAll() throws Exception {
}
}
+ public void testAllAfterUpdate() throws Exception {
+ setupNodes(4);
+
+ Collection<MemcachedNode> all = locator.getAll();
+ assertEquals(4, all.size());
+ for (int i = 0; i < 4; i++) {
+ assertTrue(all.contains(nodes[i]));
+ }
+
+ ArrayList<MemcachedNode> toUpdate = new ArrayList<MemcachedNode>();
+ Mock mock = mock(MemcachedNode.class);
+ mock.expects(atLeastOnce()).method("getSocketAddress")
+ .will(returnValue(InetSocketAddress.createUnresolved("127.0.0.1",
+ 10000)));
+ toUpdate.add((MemcachedNode) mock.proxy());
+ locator.updateLocator(toUpdate);
+
+ Collection<MemcachedNode> afterUpdate = locator.getAll();
+ assertEquals(1, afterUpdate.size());
+ for (int i = 0; i < 4; i++) {
+ assertFalse(afterUpdate.contains(nodes[i]));
+ }
+ assertTrue(afterUpdate.contains((MemcachedNode) mock.proxy()));
+ }
+
public void testAllClone() throws Exception {
setupNodes(4);

0 comments on commit 5ca6904

Please sign in to comment.