Skip to content

Commit f20a8e5

Browse files
committed
ENHANCE: Moved cache list change logic from IO thread to CacheManger thread.
1 parent 07918e6 commit f20a8e5

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,17 @@ public void run() {
398398
waitBeforeRetryMonitorCheck(1000L - elapsed);
399399
}
400400
}
401+
402+
// Handling cacheList changes to a MemcachedConnection resulting
403+
// from the processing of a CacheMonitor's Watch event.
404+
for (ArcusClient ac : getAC()) {
405+
try {
406+
ac.getMemcachedConnection().handleCacheNodesChange();
407+
} catch (IOException e) {
408+
getLogger().error("Cache List update error in ArcusClient {}, exception = {}",
409+
ac.getName(), e.getCause());
410+
}
411+
}
401412
}
402413
}
403414
getLogger().info("Close cache manager.");
@@ -482,6 +493,10 @@ public void commandCacheListChange(List<String> children) {
482493
MemcachedConnection conn = ac.getMemcachedConnection();
483494
conn.setCacheNodesChange(addrs);
484495
}
496+
497+
synchronized (this) {
498+
notifyAll(); // awake CacheManager Thread.
499+
}
485500
}
486501

487502
/* ENABLE_MIGRATION if */

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.SortedMap;
4545
import java.util.TreeMap;
4646
import java.util.concurrent.ConcurrentLinkedQueue;
47+
import java.util.concurrent.CopyOnWriteArrayList;
4748
import java.util.concurrent.TimeUnit;
4849
import java.util.concurrent.atomic.AtomicReference;
4950

@@ -142,7 +143,7 @@ public MemcachedConnection(String name, ConnectionFactory f,
142143
timeoutRatioThreshold = f.getTimeoutRatioThreshold();
143144
timeoutDurationThreshold = f.getTimeoutDurationThreshold();
144145
selector = Selector.open();
145-
List<MemcachedNode> connections = new ArrayList<MemcachedNode>(a.size());
146+
List<MemcachedNode> connections = new CopyOnWriteArrayList<MemcachedNode>();
146147
for (SocketAddress sa : a) {
147148
connections.add(makeMemcachedNode(connName, sa));
148149
}
@@ -304,9 +305,6 @@ public void handleIO() throws IOException {
304305
}
305306
/* ENABLE_REPLICATION end */
306307

307-
// Deal with the memcached server group that's been added by CacheManager.
308-
handleCacheNodesChange();
309-
310308
if (!reconnectQueue.isEmpty()) {
311309
attemptReconnects();
312310
}

0 commit comments

Comments
 (0)