private void OnSentinelError(Exception ex) { if (this.worker != null) { Log.Error("Error on existing SentinelWorker, reconnecting..."); if (OnWorkerError != null) { OnWorkerError(ex); } this.worker = GetNextSentinel(); this.worker.BeginListeningForConfigurationChanges(); } }
public List <string> GetActiveSentinelHosts(IEnumerable <string> sentinelHosts) { var activeSentinelHosts = new List <string>(); foreach (var sentinelHost in sentinelHosts.ToArray()) { try { if (Log.IsDebugEnabled) { Log.Debug("Connecting to all available Sentinels to discover Active Sentinel Hosts..."); } var endpoint = sentinelHost.ToRedisEndpoint(defaultPort: RedisConfig.DefaultPortSentinel); using (var sentinelWorker = new RedisSentinelWorker(this, endpoint)) { var activeHosts = sentinelWorker.GetSentinelHosts(MasterName); if (!activeSentinelHosts.Contains(sentinelHost)) { activeSentinelHosts.Add(sentinelHost); } foreach (var activeHost in activeHosts) { if (!activeSentinelHosts.Contains(activeHost)) { activeSentinelHosts.Add(activeHost); } } } if (Log.IsDebugEnabled) { Log.Debug("All active Sentinels Found: " + string.Join(", ", activeSentinelHosts)); } } catch (Exception ex) { Log.Error("Could not get active Sentinels from: {0}".Fmt(sentinelHost), ex); } } return(activeSentinelHosts); }
private RedisSentinelWorker GetValidSentinelWorker() { if (isDisposed) { throw new ObjectDisposedException(GetType().Name); } if (this.worker != null) { return(this.worker); } RedisException lastEx = null; while (this.worker == null && ShouldRetry()) { try { this.worker = GetNextSentinel(); GetRedisManager(); this.worker.BeginListeningForConfigurationChanges(); this.failures = 0; //reset return(this.worker); } catch (RedisException ex) { if (OnWorkerError != null) { OnWorkerError(ex); } lastEx = ex; this.failures++; Interlocked.Increment(ref RedisState.TotalFailedSentinelWorkers); } } this.failures = 0; //reset Thread.Sleep(WaitBetweenFailedHosts); throw new RedisException("No Redis Sentinels were available", lastEx); }
private RedisSentinelWorker GetNextSentinel() { lock (oLock) { if (this.worker != null) { this.worker.Dispose(); this.worker = null; } if (++sentinelIndex >= SentinelEndpoints.Length) { sentinelIndex = 0; } var sentinelWorker = new RedisSentinelWorker(this, SentinelEndpoints[sentinelIndex]) { OnSentinelError = OnSentinelError }; return(sentinelWorker); } }