Skip to content

Commit 78ab91e

Browse files
committed
FIX: Concurrency problem in locator allNodes.
1 parent 715f73a commit 78ab91e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/main/java/net/spy/memcached/ArcusKetamaNodeLocator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.SortedSet;
3333
import java.util.TreeMap;
3434
import java.util.TreeSet;
35+
import java.util.concurrent.CopyOnWriteArrayList;
3536
import java.util.concurrent.locks.Lock;
3637
import java.util.concurrent.locks.ReentrantLock;
3738

@@ -66,7 +67,7 @@ public ArcusKetamaNodeLocator(List<MemcachedNode> nodes) {
6667
public ArcusKetamaNodeLocator(List<MemcachedNode> nodes,
6768
ArcusKetamaNodeLocatorConfiguration conf) {
6869
super();
69-
allNodes = nodes;
70+
allNodes = new CopyOnWriteArrayList<>(nodes);
7071
ketamaNodes = new TreeMap<>();
7172
config = conf;
7273

@@ -92,7 +93,7 @@ private ArcusKetamaNodeLocator(TreeMap<Long, SortedSet<MemcachedNode>> smn,
9293
ArcusKetamaNodeLocatorConfiguration conf) {
9394
super();
9495
ketamaNodes = smn;
95-
allNodes = an;
96+
allNodes = new CopyOnWriteArrayList<>(an);
9697
config = conf;
9798

9899
/* ENABLE_MIGRATION if */

src/main/java/net/spy/memcached/ArcusReplKetamaNodeLocator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.SortedSet;
3333
import java.util.TreeMap;
3434
import java.util.TreeSet;
35+
import java.util.concurrent.CopyOnWriteArrayList;
3536
import java.util.concurrent.locks.Lock;
3637
import java.util.concurrent.locks.ReentrantLock;
3738

@@ -65,7 +66,7 @@ public class ArcusReplKetamaNodeLocator extends SpyObject implements NodeLocator
6566

6667
public ArcusReplKetamaNodeLocator(List<MemcachedNode> nodes) {
6768
super();
68-
allNodes = nodes;
69+
allNodes = new CopyOnWriteArrayList<>(nodes);
6970
ketamaGroups = new TreeMap<>();
7071
allGroups = new HashMap<>();
7172

@@ -108,7 +109,7 @@ private ArcusReplKetamaNodeLocator(TreeMap<Long, SortedSet<MemcachedReplicaGroup
108109
super();
109110
ketamaGroups = kg;
110111
allGroups = ag;
111-
allNodes = an;
112+
allNodes = new CopyOnWriteArrayList<>(an);
112113
toDeleteGroups = new HashSet<>();
113114

114115
/* ENABLE_MIGRATION if */

0 commit comments

Comments
 (0)