Skip to content

Commit

Permalink
ENHANCE: Moved cache list change logic from IO thread to CacheManger …
Browse files Browse the repository at this point in the history
…thread.
  • Loading branch information
brido4125 committed Apr 1, 2024
1 parent af91703 commit 34b215f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/main/java/net/spy/memcached/CacheManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,17 @@ public void run() {
waitBeforeRetryMonitorCheck(1000L - elapsed);
}
}

// Handling cacheList changes to a MemcachedConnection resulting
// from the processing of a CacheMonitor's Watch event.
for (ArcusClient ac : getAC()) {
try {
ac.getMemcachedConnection().handleCacheNodesChange();
} catch (IOException e) {
getLogger().error("Cache List update error in ArcusClient {}, exception = {}",
ac.getName(), e.getCause());
}
}
}
}
getLogger().info("Close cache manager.");
Expand Down Expand Up @@ -482,6 +493,7 @@ public void commandCacheListChange(List<String> children) {
MemcachedConnection conn = ac.getMemcachedConnection();
conn.setCacheNodesChange(addrs);
}
notifyAll(); // awake CacheManager Thread.
}

/* ENABLE_MIGRATION if */
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/net/spy/memcached/MemcachedConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

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

// Deal with the memcached server group that's been added by CacheManager.
handleCacheNodesChange();

if (!reconnectQueue.isEmpty()) {
attemptReconnects();
}
Expand Down Expand Up @@ -735,7 +733,7 @@ public void setCacheNodesChange(String addrs) {
alterNodesChange.set(old);
}
/* ENABLE_MIGRATION end */
selector.wakeup();
wakeUpSelector();
}

/* ENABLE_MIGRATION if */
Expand Down

0 comments on commit 34b215f

Please sign in to comment.