internal IPooledConnection AcquireReadConnection() { while (true) { Uri uri; if (!_clusterView.TryNextReader(out uri)) { // no server known to clusterView break; } try { IPooledConnection conn; if (_clusterConnectionPool.TryAcquire(uri, out conn)) { return(conn); } } catch (SessionExpiredException) { // ignored // Already handled by connectionpool error handler to remove from load balancer } } throw new SessionExpiredException("Failed to connect to any read server."); }
private ClusterConnection CreateClusterConnection(Uri uri, AccessMode mode = AccessMode.Write) { lock (_syncLock) { try { IPooledConnection conn; if (_clusterConnectionPool.TryAcquire(uri, out conn)) { return(new ClusterConnection(conn, uri, mode, this)); } OnConnectionError(uri, new ArgumentException( $"Routing table {_routingTable} contains a server {uri} " + $"that is not known to cluster connection pool {_clusterConnectionPool}.")); } catch (ServiceUnavailableException e) { OnConnectionError(uri, e); } return(null); } }