Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 5ca6904eb7357dee35ba53444f3cd542a1ed6f75 1 parent 821844d
Michael Nitschinger authored January 24, 2013 daschl committed January 29, 2013
3  src/main/java/net/spy/memcached/KetamaNodeLocator.java
@@ -48,7 +48,7 @@
48 48
 public final class KetamaNodeLocator extends SpyObject implements NodeLocator {
49 49
 
50 50
   private volatile TreeMap<Long, MemcachedNode> ketamaNodes;
51  
-  private final Collection<MemcachedNode> allNodes;
  51
+  private volatile Collection<MemcachedNode> allNodes;
52 52
 
53 53
   private final HashAlgorithm hashAlg;
54 54
   private final KetamaNodeLocatorConfiguration config;
@@ -152,6 +152,7 @@ public NodeLocator getReadonlyCopy() {
152 152
 
153 153
   @Override
154 154
   public void updateLocator(List<MemcachedNode> nodes) {
  155
+    allNodes = nodes;
155 156
     setKetamaNodes(nodes);
156 157
   }
157 158
 
27  src/test/java/net/spy/memcached/KetamaNodeLocatorTest.java
@@ -24,9 +24,11 @@
24 24
 package net.spy.memcached;
25 25
 
26 26
 import java.net.InetSocketAddress;
  27
+import java.util.ArrayList;
27 28
 import java.util.Arrays;
28 29
 import java.util.Collection;
29 30
 import java.util.List;
  31
+import org.jmock.Mock;
30 32
 
31 33
 /**
32 34
  * Test ketama node location.
@@ -59,6 +61,31 @@ public void testAll() throws Exception {
59 61
     }
60 62
   }
61 63
 
  64
+  public void testAllAfterUpdate() throws Exception {
  65
+     setupNodes(4);
  66
+
  67
+    Collection<MemcachedNode> all = locator.getAll();
  68
+    assertEquals(4, all.size());
  69
+    for (int i = 0; i < 4; i++) {
  70
+      assertTrue(all.contains(nodes[i]));
  71
+    }
  72
+
  73
+    ArrayList<MemcachedNode> toUpdate = new ArrayList<MemcachedNode>();
  74
+    Mock mock = mock(MemcachedNode.class);
  75
+    mock.expects(atLeastOnce()).method("getSocketAddress")
  76
+          .will(returnValue(InetSocketAddress.createUnresolved("127.0.0.1",
  77
+          10000)));
  78
+    toUpdate.add((MemcachedNode) mock.proxy());
  79
+    locator.updateLocator(toUpdate);
  80
+
  81
+    Collection<MemcachedNode> afterUpdate = locator.getAll();
  82
+    assertEquals(1, afterUpdate.size());
  83
+    for (int i = 0; i < 4; i++) {
  84
+      assertFalse(afterUpdate.contains(nodes[i]));
  85
+    }
  86
+    assertTrue(afterUpdate.contains((MemcachedNode) mock.proxy()));
  87
+  }
  88
+
62 89
   public void testAllClone() throws Exception {
63 90
     setupNodes(4);
64 91
 

0 notes on commit 5ca6904

Please sign in to comment.
Something went wrong with that request. Please try again.