Skip to content

Commit c9bd722

Browse files
committed
ENHANCE: Moved cache list change logic from IO thread to CacheManger thread.
1 parent d388cee commit c9bd722

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,20 @@ public void run() {
398398
waitBeforeRetryMonitorCheck(1000L - elapsed);
399399
}
400400
}
401+
402+
// Only perform cache node list updates when connectivity with ZK is normal.
403+
if (!isDead) {
404+
// Handling cacheList changes to a MemcachedConnection resulting
405+
// from the processing of a CacheMonitor's Watch event.
406+
for (ArcusClient ac : getAC()) {
407+
try {
408+
ac.getMemcachedConnection().handleCacheNodesChange();
409+
} catch (IOException e) {
410+
getLogger().error("Cache List update error in ArcusClient {}, exception = {}",
411+
ac.getName(), e.getCause());
412+
}
413+
}
414+
}
401415
}
402416
}
403417
getLogger().info("Close cache manager.");

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

+3-5
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
}
@@ -735,7 +733,7 @@ public void setCacheNodesChange(String addrs) {
735733
alterNodesChange.set(old);
736734
}
737735
/* ENABLE_MIGRATION end */
738-
selector.wakeup();
736+
wakeUpSelector();
739737
}
740738

741739
/* ENABLE_MIGRATION if */

0 commit comments

Comments
 (0)