public void CheckConfigUpdate(string bucketName, IPEndPoint excludeEndPoint) { var lockAcquired = false; try { Monitor.TryEnter(_syncObject, ref lockAcquired); var now = DateTime.Now; var lastCheckedPlus = LastConfigCheckedTime.AddMilliseconds(Configuration.HeartbeatConfigCheckFloor); if (!lockAcquired || lastCheckedPlus > now) { Log.Info("Not checking config because {0} > {1} or a lock ({2}) could not be acquired.", lastCheckedPlus, now, lockAcquired); return; } Log.Info("Checking config because {0} < {1}", lastCheckedPlus, now); var provider = _configProviders.FirstOrDefault(x => x is CarrierPublicationProvider); if (provider != null) { var configInfo = provider.GetCached(bucketName); var servers = configInfo.Servers. Where(x => x.IsDataNode && !x.IsDown && !x.EndPoint.Equals(excludeEndPoint)). ToList(). Shuffle(); if (servers.Any()) { var server = servers.First(); Log.Info("Checking for new config {0}", server.EndPoint); var config = server.Send( new Config(Transcoder, _clientConfig.DefaultOperationLifespan, server.EndPoint)); if (config.Success) { EnqueueConfigForProcessing(config.Value); } } } } catch (Exception e) { Log.Info(e); } finally { LastConfigCheckedTime = DateTime.Now; } if (lockAcquired) { Monitor.Exit(_syncObject); } }
public void CheckConfigUpdate(string bucketName, IPEndPoint excludeEndPoint) { _semaphoreSlim.Wait(); try { var now = DateTime.Now; var lastCheckedPlus = LastConfigCheckedTime.AddMilliseconds(Configuration.ConfigPollCheckFloor); if (lastCheckedPlus > now) { Log.Info("Not checking config because {0} > {1}.", lastCheckedPlus, now); return; } Log.Info("Checking config because {0} < {1}", lastCheckedPlus, now); var provider = _configProviders.FirstOrDefault(x => x is CarrierPublicationProvider); if (provider != null) { var configInfo = provider.GetCached(bucketName); var servers = configInfo.Servers. Where(x => x.IsDataNode && !x.IsDown && !x.EndPoint.Equals(excludeEndPoint)). ToList(). Shuffle(); if (servers.Any()) { var server = servers.First(); Log.Info("Checking for new config {0}", server.EndPoint); var operation = new Config(Transcoder, _clientConfig.DefaultOperationLifespan, server.EndPoint); IOperationResult <BucketConfig> result; using (configInfo.ClientConfig.Tracer.StartParentSpan(operation, addIgnoreTag: true)) { result = server.Send(operation); } if (result.Success) { EnqueueConfigForProcessing(result.Value); } } } } catch (Exception e) { Log.Info(e); } finally { LastConfigCheckedTime = DateTime.Now; _semaphoreSlim.Release(); } }