funky-eyes commented on code in PR #8020:
URL: https://github.com/apache/incubator-seata/pull/8020#discussion_r3009214223
##########
core/src/main/java/org/apache/seata/core/rpc/netty/NettyClientChannelManager.java:
##########
@@ -297,6 +301,49 @@ void registerChannel(final String serverAddress, final
Channel channel, String v
Version.putChannelVersion(channel, version);
}
+ void putServerVersion(String serverAddress, String version) {
+ serverVersionMap.put(serverAddress, version);
+ }
+
+ String getServerVersion(String serverAddress) {
+ return serverVersionMap.get(serverAddress);
+ }
+
+ void clearServerVersions() {
+ serverVersionMap.clear();
+ }
+
+ /**
+ * Remove entries from internal maps for addresses that are no longer
+ * in the available server list and have no active channel.
+ * This prevents unbounded map growth in environments like Kubernetes
+ * where server IPs change frequently.
+ */
+ private void cleanupStaleAddresses(List<String> availList) {
+ Set<String> availSet = new HashSet<>(availList);
+ Set<String> staleAddresses = serverVersionMap.keySet().stream()
+ .filter(address -> !availSet.contains(address) &&
!channels.containsKey(address))
+ .collect(Collectors.toSet());
+
+ poolKeyMap.keySet().stream()
+ .filter(address -> !availSet.contains(address) &&
!channels.containsKey(address))
+ .forEachOrdered(staleAddresses::add);
+
+ channelLocks.keySet().stream()
+ .filter(address -> !availSet.contains(address) &&
!channels.containsKey(address))
+ .forEachOrdered(staleAddresses::add);
+
+ staleAddresses.forEach(address -> {
Review Comment:
I think it is more appropriate to use Netty's `channelInactive` or similar
disconnection events to clear the cache.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]