private bool IsServerValidForCluster(ClusterType clusterType, ClusterConnectionMode connectionMode, ServerType serverType) { switch (clusterType) { case ClusterType.Standalone: return(serverType == ServerType.Standalone); case ClusterType.ReplicaSet: return(serverType.IsReplicaSetMember()); case ClusterType.Sharded: return(serverType == ServerType.ShardRouter); case ClusterType.Unknown: switch (connectionMode) { case ClusterConnectionMode.Automatic: if (serverType == ServerType.Standalone) { return(Settings.Scheme == ConnectionStringScheme.MongoDBPlusSrv); // Standalone is only valid in MultiServerCluster when using MongoDBPlusSrv scheme } return(serverType.IsReplicaSetMember() || serverType == ServerType.ShardRouter); default: throw new MongoInternalException("Unexpected connection mode."); } default: throw new MongoInternalException("Unexpected cluster type."); } }
private bool IsServerValidForCluster(ClusterType clusterType, ClusterConnectionMode connectionMode, ServerType serverType) { switch (clusterType) { case ClusterType.ReplicaSet: return(serverType.IsReplicaSetMember()); case ClusterType.Sharded: return(serverType == ServerType.ShardRouter); case ClusterType.Standalone: return(serverType == ServerType.Standalone); case ClusterType.Unknown: switch (connectionMode) { case ClusterConnectionMode.Automatic: case ClusterConnectionMode.Direct: return(true); default: throw new MongoInternalException("Unexpected connection mode."); } default: throw new MongoInternalException("Unexpected cluster type."); } }
private void PublishDescription(ICluster cluster, EndPoint endPoint, ServerType serverType, IEnumerable <EndPoint> hosts = null, string setName = null, EndPoint primary = null, ElectionId electionId = null, EndPoint canonicalEndPoint = null, int?setVersion = null) { var current = _serverFactory.GetServerDescription(endPoint); var config = new ReplicaSetConfig( hosts ?? new[] { _firstEndPoint, _secondEndPoint, _thirdEndPoint }, setName ?? "test", primary, setVersion); var serverDescription = current.With( averageRoundTripTime: TimeSpan.FromMilliseconds(10), replicaSetConfig: serverType.IsReplicaSetMember() ? config : null, canonicalEndPoint: canonicalEndPoint, electionId: electionId, state: ServerState.Connected, tags: null, type: serverType, version: new SemanticVersion(2, 6, 3), wireVersionRange: new Range <int>(0, int.MaxValue)); var currentClusterDescription = cluster.Description; _serverFactory.PublishDescription(serverDescription); SpinWait.SpinUntil(() => !object.ReferenceEquals(cluster.Description, currentClusterDescription), 100); // sometimes returns false and that's OK }
private bool IsServerValidForCluster(ClusterType clusterType, ClusterSettings clusterSettings, ServerType serverType) { switch (clusterType) { case ClusterType.Standalone: return(serverType == ServerType.Standalone); case ClusterType.ReplicaSet: return(serverType.IsReplicaSetMember()); case ClusterType.Sharded: return(serverType == ServerType.ShardRouter); case ClusterType.Unknown: #pragma warning disable CS0618 // Type or member is obsolete if (clusterSettings.ConnectionModeSwitch == ConnectionModeSwitch.UseDirectConnection) { return(true); } else { switch (clusterSettings.ConnectionMode) { case ClusterConnectionMode.Automatic: if (serverType == ServerType.Standalone) { return(_servers.Count == 1 || Settings.Scheme == ConnectionStringScheme.MongoDBPlusSrv); // Standalone is only valid in MultiServerCluster when using MongoDBPlusSrv scheme } return(serverType.IsReplicaSetMember() || serverType == ServerType.ShardRouter); default: throw new MongoInternalException("Unexpected connection mode."); } } #pragma warning restore CS0618 // Type or member is obsolete default: throw new MongoInternalException("Unexpected cluster type."); } }
private bool IsServerValidForCluster(ClusterType clusterType, ClusterSettings clusterSettings, ServerType serverType) { switch (clusterType) { case ClusterType.ReplicaSet: return(serverType.IsReplicaSetMember()); case ClusterType.Sharded: return(serverType == ServerType.ShardRouter); case ClusterType.Standalone: return(IsStandaloneServerValidForCluster()); case ClusterType.Unknown: return(IsUnknownServerValidForCluster()); default: throw new MongoInternalException("Unexpected cluster type."); } bool IsStandaloneServerValidForCluster() { #pragma warning disable CS0618 // Type or member is obsolete if (clusterSettings.ConnectionModeSwitch == ConnectionModeSwitch.UseDirectConnection) #pragma warning restore CS0618 // Type or member is obsolete { return(clusterSettings.DirectConnection.GetValueOrDefault()); } else { return(serverType == ServerType.Standalone); } } bool IsUnknownServerValidForCluster() { #pragma warning disable CS0618 // Type or member is obsolete if (clusterSettings.ConnectionModeSwitch == ConnectionModeSwitch.UseDirectConnection) { return(clusterSettings.DirectConnection.GetValueOrDefault()); } else { var connectionMode = clusterSettings.ConnectionMode; return (connectionMode == ClusterConnectionMode.Automatic || connectionMode == ClusterConnectionMode.Direct); } #pragma warning restore CS0618 // Type or member is obsolete } }
private void PublishDescription(EndPoint endPoint, ServerType serverType, IEnumerable <EndPoint> hosts = null, string setName = null, EndPoint primary = null) { var current = _serverFactory.GetServerDescription(endPoint); var config = new ReplicaSetConfig( hosts ?? new[] { _firstEndPoint, _secondEndPoint, _thirdEndPoint }, setName ?? "test", primary, null); var description = current.WithHeartbeatInfo( TimeSpan.FromMilliseconds(10), serverType.IsReplicaSetMember() ? config : null, null, serverType, new SemanticVersion(2, 6, 3), new Range <int>(0, int.MaxValue)); _serverFactory.PublishDescription(description); }
private void PublishDescription(EndPoint endPoint, ServerType serverType, IEnumerable <EndPoint> hosts = null, string setName = null, EndPoint primary = null) { var current = _serverFactory.GetServerDescription(endPoint); var config = new ReplicaSetConfig( hosts ?? new[] { _firstEndPoint, _secondEndPoint, _thirdEndPoint }, setName ?? "test", primary, null); var description = current.With( averageRoundTripTime: TimeSpan.FromMilliseconds(10), replicaSetConfig: serverType.IsReplicaSetMember() ? config : null, state: ServerState.Connected, tags: null, type: serverType, version: new SemanticVersion(2, 6, 3), wireVersionRange: new Range <int>(0, int.MaxValue)); _serverFactory.PublishDescription(description); }
private bool IsServerValidForCluster(ClusterType clusterType, ClusterConnectionMode connectionMode, ServerType serverType) { switch (clusterType) { case ClusterType.ReplicaSet: return serverType.IsReplicaSetMember(); case ClusterType.Sharded: return serverType == ServerType.ShardRouter; case ClusterType.Standalone: return serverType == ServerType.Standalone; case ClusterType.Unknown: switch (connectionMode) { case ClusterConnectionMode.Automatic: case ClusterConnectionMode.Direct: return true; default: throw new MongoInternalException("Unexpected connection mode."); } default: throw new MongoInternalException("Unexpected cluster type."); } }
private void PublishDescription(ICluster cluster, EndPoint endPoint, ServerType serverType, IEnumerable<EndPoint> hosts = null, string setName = null, EndPoint primary = null, ElectionId electionId = null, EndPoint canonicalEndPoint = null, int? setVersion = null) { var current = _serverFactory.GetServerDescription(endPoint); var config = new ReplicaSetConfig( hosts ?? new[] { _firstEndPoint, _secondEndPoint, _thirdEndPoint }, setName ?? "test", primary, setVersion); var serverDescription = current.With( averageRoundTripTime: TimeSpan.FromMilliseconds(10), replicaSetConfig: serverType.IsReplicaSetMember() ? config : null, canonicalEndPoint: canonicalEndPoint, electionId: electionId, state: ServerState.Connected, tags: null, type: serverType, version: new SemanticVersion(2, 6, 3), wireVersionRange: new Range<int>(0, int.MaxValue)); var currentClusterDescription = cluster.Description; _serverFactory.PublishDescription(serverDescription); SpinWait.SpinUntil(() => !object.ReferenceEquals(cluster.Description, currentClusterDescription), 100); // sometimes returns false and that's OK }
private void PublishDescription(EndPoint endPoint, ServerType serverType, IEnumerable<EndPoint> hosts = null, string setName = null, EndPoint primary = null, ElectionId electionId = null, EndPoint canonicalEndPoint = null) { var current = _serverFactory.GetServerDescription(endPoint); var config = new ReplicaSetConfig( hosts ?? new[] { _firstEndPoint, _secondEndPoint, _thirdEndPoint }, setName ?? "test", primary, null); var description = current.With( averageRoundTripTime: TimeSpan.FromMilliseconds(10), replicaSetConfig: serverType.IsReplicaSetMember() ? config : null, canonicalEndPoint: canonicalEndPoint, electionId: electionId, state: ServerState.Connected, tags: null, type: serverType, version: new SemanticVersion(2, 6, 3), wireVersionRange: new Range<int>(0, int.MaxValue)); _serverFactory.PublishDescription(description); }
private void PublishDescription(EndPoint endPoint, ServerType serverType, IEnumerable<EndPoint> hosts = null, string setName = null, EndPoint primary = null) { var current = _serverFactory.GetServerDescription(endPoint); var config = new ReplicaSetConfig( hosts ?? new[] { _firstEndPoint, _secondEndPoint, _thirdEndPoint }, setName ?? "test", primary, null); var description = current.WithHeartbeatInfo( TimeSpan.FromMilliseconds(10), serverType.IsReplicaSetMember() ? config : null, null, serverType, new SemanticVersion(2, 6, 3), new Range<int>(0, int.MaxValue)); _serverFactory.PublishDescription(description); }