public List <string> GetActiveSentinelHosts(IEnumerable <string> sentinelHosts) { var activeSentinelHosts = new List <string>(); foreach (var sentinelHost in sentinelHosts.ToArray()) { try { 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); } } } } catch (Exception ex) { Log.Error("Could not get active Sentinels from: {0}".Fmt(sentinelHost), ex); } } return(activeSentinelHosts); }
private RedisSentinelWorker GetNextSentinel() { RedisSentinelWorker disposeWorker = null; try { lock (oLock) { if (this.worker != null) { disposeWorker = this.worker; this.worker = null; } if (++sentinelIndex >= SentinelEndpoints.Length) { sentinelIndex = 0; } var sentinelWorker = new RedisSentinelWorker(this, SentinelEndpoints[sentinelIndex]) { OnSentinelError = OnSentinelError }; return(sentinelWorker); } } finally { disposeWorker?.Dispose(); } }
public void Dispose() { if (worker != null) { worker.Dispose(); worker = null; } }
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()) { var step = 0; try { this.worker = GetNextSentinel(); step = 1; GetRedisManager(); step = 2; this.worker.BeginListeningForConfigurationChanges(); this.failures = 0; //reset return(this.worker); } catch (RedisException ex) { if (Log.IsDebugEnabled) { var name = step switch { 0 => "GetNextSentinel()", 1 => "GetRedisManager()", 2 => "BeginListeningForConfigurationChanges()", _ => $"Step {step}", }; Log.Debug($"Failed to {name}: {ex.Message}"); } if (OnWorkerError != null) { OnWorkerError(ex); } lastEx = ex; this.worker = null; this.failures++; Interlocked.Increment(ref RedisState.TotalFailedSentinelWorkers); } } this.failures = 0; //reset TaskUtils.Sleep(WaitBetweenFailedHosts); throw new RedisException("No Redis Sentinels were available", lastEx); }
public void Dispose() { if (worker != null) { worker.SentinelError -= Worker_SentinelError; worker.Dispose(); worker = null; } }
private void Worker_SentinelError(object sender, EventArgs e) { var worker = sender as RedisSentinelWorker; if (worker != null) { worker.SentinelError -= Worker_SentinelError; worker.Dispose(); this.worker = GetNextSentinel(); this.worker.BeginListeningForConfigurationChanges(); } }
private RedisSentinelWorker GetNextSentinel() { sentinelIndex++; if (sentinelIndex >= sentinels.Count) { sentinelIndex = 0; } var sentinelWorker = new RedisSentinelWorker(sentinels[sentinelIndex], this.sentinelName, this.clientManager); sentinelWorker.SentinelError += Worker_SentinelError; return(sentinelWorker); }
private RedisSentinelWorker GetNextSentinel() { sentinelIndex++; if (sentinelIndex >= sentinels.Count) { sentinelIndex = 0; } var sentinelWorker = new RedisSentinelWorker(sentinels[sentinelIndex], this.sentinelName, this.clientManager); sentinelWorker.SentinelError += Worker_SentinelError; return sentinelWorker; }
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(); } }
/// <summary> /// Raised if there is an error from a sentinel worker /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Worker_SentinelError(object sender, EventArgs e) { var worker = sender as RedisSentinelWorker; if (worker != null) { // dispose the worker worker.SentinelError -= Worker_SentinelError; worker.Dispose(); // get a new worker and start looking for more changes this.worker = GetNextSentinel(); this.worker.BeginListeningForConfigurationChanges(); } }
private RedisSentinelWorker GetNextSentinel() { sentinelIndex++; if (sentinelIndex >= sentinels.Count) { sentinelIndex = 0; } var sentinelWorker = new RedisSentinelWorker(this, sentinels[sentinelIndex], this.sentinelName) { OnSentinelError = OnSentinelError }; return(sentinelWorker); }
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)) { if (!activeSentinelHosts.Contains(sentinelHost)) { activeSentinelHosts.Add(sentinelHost); } var activeHosts = sentinelWorker.GetSentinelHosts(MasterName); foreach (var activeHost in activeHosts) { if (!activeSentinelHosts.Contains(activeHost)) { activeSentinelHosts.Add(SentinelHostFilter != null ? SentinelHostFilter(activeHost) : 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.worker = null; this.failures++; Interlocked.Increment(ref RedisState.TotalFailedSentinelWorkers); } } this.failures = 0; //reset Thread.Sleep(WaitBetweenFailedHosts); throw new RedisException("No Redis Sentinels were available", lastEx); }
/// <summary> /// Raised if there is an error from a sentinel worker /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnSentinelError(Exception ex) { if (this.worker != null) { Log.Error("Error on existing SentinelWorker, reconnecting..."); if (OnWorkerError != null) { OnWorkerError(ex); } // dispose the worker this.worker.Dispose(); // get a new worker and start looking for more changes this.worker = GetNextSentinel(); this.worker.BeginListeningForConfigurationChanges(); } }
private void GetValidSentinel() { while (this.clientManager == null && ShouldRetry()) { try { this.worker = GetNextSentinel(); this.clientManager = worker.GetClientManager(); this.worker.BeginListeningForConfigurationChanges(); } catch (RedisException) { if (this.worker != null) { this.worker.SentinelError -= Worker_SentinelError; this.worker.Dispose(); } this.failures++; } } }
private void GetValidSentinel() { while (this.clientManager == null && ShouldRetry()) { try { this.worker = GetNextSentinel(); this.clientManager = worker.GetClientManager(); this.worker.BeginListeningForConfigurationChanges(); } catch (RedisException) { if (this.worker != null) { this.worker.SentinelError -= Worker_SentinelError; this.worker.Dispose(); } this.failures++; } } }
private void GetValidSentinel() { while (this.clientManager == null && failures < RedisSentinel.MaxFailures) { try { worker = GetNextSentinel(); clientManager = worker.GetClientManager(); worker.BeginListeningForConfigurationChanges(); } catch (RedisException) { if (worker != null) { worker.SentinelError -= Worker_SentinelError; worker.Dispose(); } failures++; } } }
private void GetValidSentinel() { while (this.clientManager == null && failures < RedisSentinel.MaxFailures) { try { worker = GetNextSentinel(); clientManager = worker.GetClientManager(); worker.BeginListeningForConfigurationChanges(); } catch (RedisException) { if (worker != null) { worker.SentinelError -= Worker_SentinelError; worker.Dispose(); } failures++; } } }
private RedisSentinelWorker GetValidSentinel() { if (this.worker != null) { return(this.worker); } RedisException lastEx = null; while (this.RedisManager == null && ShouldRetry()) { try { this.worker = GetNextSentinel(); this.RedisManager = worker.GetClientManager(); this.worker.BeginListeningForConfigurationChanges(); return(this.worker); } catch (RedisException ex) { if (OnWorkerError != null) { OnWorkerError(ex); } lastEx = ex; if (this.worker != null) { this.worker.Dispose(); } this.failures++; } } throw new RedisException("RedisSentinel is not accessible", lastEx); }
private RedisSentinelWorker GetNextSentinel() { RedisSentinelWorker disposeWorker = null; try { lock (oLock) { if (this.worker != null) { disposeWorker = this.worker; this.worker = null; } if (++sentinelIndex >= SentinelEndpoints.Length) { sentinelIndex = 0; } if (Log.IsDebugEnabled) { Log.Debug($"Attempt to connect to next sentinel '{SentinelEndpoints[sentinelIndex]}'..."); } var sentinelWorker = new RedisSentinelWorker(this, SentinelEndpoints[sentinelIndex]) { OnSentinelError = OnSentinelError }; return(sentinelWorker); } } finally { disposeWorker?.Dispose(); } }
public void Dispose() { if (worker != null) { worker.SentinelError -= Worker_SentinelError; worker.Dispose(); worker = null; } }
public void Dispose() { if (worker == null) return; worker.Dispose(); worker = null; }
public List<string> GetActiveSentinelHosts(IEnumerable<string> sentinelHosts) { var activeSentinelHosts = new List<string>(); foreach (var sentinelHost in sentinelHosts.ToArray()) { try { 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); } } } catch (Exception ex) { Log.Error("Could not get active Sentinels from: {0}".Fmt(sentinelHost), ex); } } return activeSentinelHosts; }
private RedisSentinelWorker GetValidSentinel() { if (this.worker != null) return this.worker; RedisException lastEx = null; while (this.RedisManager == null && ShouldRetry()) { try { this.worker = GetNextSentinel(); this.RedisManager = worker.GetClientManager(); this.worker.BeginListeningForConfigurationChanges(); return this.worker; } catch (RedisException ex) { if (OnWorkerError != null) OnWorkerError(ex); lastEx = ex; if (this.worker != null) this.worker.Dispose(); this.failures++; } } throw new RedisException("RedisSentinel is not accessible", lastEx); }
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 void Dispose() { if (worker != null) { worker.Dispose(); worker = null; } }
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; } }
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 GetValidSentinel() { if (this.worker != null) return this.worker; RedisException lastEx = null; while (this.worker == null && ShouldRetry()) { try { this.worker = GetNextSentinel(); GetRedisManager(); this.worker.BeginListeningForConfigurationChanges(); return this.worker; } catch (RedisException ex) { if (OnWorkerError != null) OnWorkerError(ex); lastEx = ex; this.failures++; this.totalFailures++; } } this.failures = 0; //reset Thread.Sleep(WaitBetweenSentinelLookups); throw new RedisException("No Redis Sentinels were available", lastEx); }
/// <summary> /// Raised if there is an error from a sentinel worker /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Worker_SentinelError(object sender, EventArgs e) { var worker = sender as RedisSentinelWorker; if (worker != null) { // dispose the worker worker.SentinelError -= Worker_SentinelError; worker.Dispose(); // get a new worker and start looking for more changes this.worker = GetNextSentinel(); this.worker.BeginListeningForConfigurationChanges(); } }
private void Worker_SentinelError(object sender, EventArgs e) { var worker = sender as RedisSentinelWorker; if (worker != null) { worker.SentinelError -= Worker_SentinelError; worker.Dispose(); this.worker = GetNextSentinel(); this.worker.BeginListeningForConfigurationChanges(); } }
private RedisSentinelWorker GetNextSentinel() { sentinelIndex++; if (sentinelIndex >= sentinels.Count) sentinelIndex = 0; var sentinelWorker = new RedisSentinelWorker(this, sentinels[sentinelIndex], this.masterName) { OnSentinelError = OnSentinelError }; return sentinelWorker; }
/// <summary> /// Raised if there is an error from a sentinel worker /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnSentinelError(Exception ex) { if (this.worker != null) { Log.Error("Error on existing SentinelWorker, reconnecting..."); if (OnWorkerError != null) OnWorkerError(ex); // dispose the worker this.worker.Dispose(); // get a new worker and start looking for more changes this.worker = GetNextSentinel(); this.worker.BeginListeningForConfigurationChanges(); } }
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.worker = null; this.failures++; Interlocked.Increment(ref RedisState.TotalFailedSentinelWorkers); } } this.failures = 0; //reset Thread.Sleep(WaitBetweenFailedHosts); throw new RedisException("No Redis Sentinels were available", lastEx); }