ptupitsyn commented on code in PR #7261:
URL: https://github.com/apache/ignite-3/pull/7261#discussion_r2629765953
##########
modules/platforms/dotnet/Apache.Ignite/Internal/ClientFailoverSocket.cs:
##########
@@ -385,6 +408,74 @@ internal IEnumerable<ClientSocket> GetSockets()
return res;
}
+ private async Task InitEndpointsAsync(int lockWaitTimeoutMs =
Timeout.Infinite)
+ {
+ bool lockAcquired = await
_socketLock.WaitAsync(lockWaitTimeoutMs).ConfigureAwait(false);
+ if (!lockAcquired)
+ {
+ return;
+ }
+
+ try
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ HashSet<SocketEndpoint> newEndpoints = await
GetIpEndPointsAsync(Configuration.Configuration).ConfigureAwait(false);
+ IReadOnlyList<SocketEndpoint> oldEndpoints = _endpoints;
+
+ var resList = new List<SocketEndpoint>(newEndpoints.Count);
+ List<SocketEndpoint>? toRemove = null;
+
+ // Retain existing sockets for endpoints that are still
present.
+ foreach (var oldEndpoint in oldEndpoints)
+ {
+ if (newEndpoints.Remove(oldEndpoint))
+ {
+ resList.Add(oldEndpoint);
+ }
+ else
+ {
+ toRemove ??= new List<SocketEndpoint>();
+ toRemove.Add(oldEndpoint);
+ }
+ }
+
+ if (_logger.IsEnabled(LogLevel.Trace) && (newEndpoints.Count >
0 || toRemove != null))
+ {
+ var addedStr = newEndpoints.Select(e =>
e.EndPointString).StringJoin();
+ var removedStr = toRemove?.Select(e =>
e.EndPointString).StringJoin();
+
+ _logger.LogEndpointListUpdatedTrace(addedStr, removedStr
?? string.Empty);
+ }
+
+ // Add remaining endpoints that were not known before.
+ resList.AddRange(newEndpoints);
+
+ // Apply the new endpoint list.
+ _endpoints = resList;
+
+ // Dispose removed sockets after updating the endpoint list.
Review Comment:
Good catch. Fixed. Now we retain old connections, mark them as "abandoned",
and remove them only when they get disconnected naturally.
--
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]