internal async Task <IRoutingTable> UpdateRoutingTableAsync(IRoutingTable routingTable, AccessMode mode, string database, Bookmark bookmark, ISet <Uri> triedUris = null) { if (database == null) { throw new ArgumentNullException(nameof(database)); } var knownRouters = routingTable?.Routers ?? throw new ArgumentNullException(nameof(routingTable)); foreach (var router in knownRouters) { triedUris?.Add(router); try { var conn = await _poolManager.CreateClusterConnectionAsync(router).ConfigureAwait(false); if (conn == null) { routingTable.Remove(router); } else { var newRoutingTable = await _discovery.DiscoverAsync(conn, database, bookmark).ConfigureAwait(false); if (!newRoutingTable.IsStale(mode)) { return(newRoutingTable); } _logger?.Debug("Skipping stale routing table received from server '{0}' for database '{1}'", router, database); } } catch (SecurityException e) { _logger?.Error(e, "Failed to update routing table from server '{0}' for database '{1}' because of a security exception.", router, database); throw; } catch (FatalDiscoveryException e) { _logger?.Error(e, "Failed to update routing table from server '{0}' for database '{1}' because of a fatal discovery exception.", router, database); throw; } catch (Exception e) { _logger?.Warn(e, "Failed to update routing table from server '{0}' for database '{1}'.", router, database); } } return(null); }
public async Task <IRoutingTable> UpdateRoutingTableAsync(ISet <Uri> triedUris = null, Func <IConnection, Task <IRoutingTable> > rediscoveryFunc = null) { rediscoveryFunc = rediscoveryFunc ?? RediscoveryAsync; var knownRouters = _routingTable.Routers; foreach (var router in knownRouters) { triedUris?.Add(router); IConnection conn = await _poolManager.CreateClusterConnectionAsync(router).ConfigureAwait(false); if (conn == null) { _routingTable.Remove(router); } else { try { var roundRobinRoutingTable = await rediscoveryFunc(conn).ConfigureAwait(false); if (!IsRoutingTableStale(roundRobinRoutingTable)) { return(roundRobinRoutingTable); } } catch (Exception e) { _logger?.Warn(e, "Failed to update routing table with server uri={0}.", router); if (e is SessionExpiredException) { // ignored // Already handled by clusterConn.OnConnectionError to remove from load balancer } else { throw; } } } } return(null); }
public async Task <IRoutingTable> UpdateRoutingTableAsync(ISet <Uri> triedUris = null, Func <IConnection, Task <IRoutingTable> > rediscoveryFunc = null) { var knownRouters = _routingTable.Routers; foreach (var router in knownRouters) { triedUris?.Add(router); try { var conn = await _poolManager.CreateClusterConnectionAsync(router).ConfigureAwait(false); if (conn == null) { _routingTable.Remove(router); } else { var newRoutingTable = await _discovery.DiscoverAsync(conn).ConfigureAwait(false); if (!IsRoutingTableStale(newRoutingTable)) { return(newRoutingTable); } } } catch (SecurityException e) { _logger?.Error(e, "Failed to update routing table from server '{0}' because of a security exception.", router); throw; } catch (Exception e) { _logger?.Warn(e, "Failed to update routing table from server '{0}'.", router); } } return(null); }