public void RefreshReplicationInformation(ServerClient commands) { var serverHash = GetServerHash(commands); JsonDocument document; try { document = commands.DirectGet(commands.Url, RavenReplicationDestinations); failureCounts[commands.Url] = new FailureCounter(); // we just hit the master, so we can reset its failure count } catch (Exception e) { log.ErrorException("Could not contact master for new replication information", e); document = TryLoadReplicationInformationFromLocalCache(serverHash); } if (document == null) { lastReplicationUpdate = SystemTime.UtcNow; // checked and not found return; } TrySavingReplicationInformationToLocalCache(serverHash, document); UpdateReplicationInformationFromDocument(document); lastReplicationUpdate = SystemTime.UtcNow; }
public void RefreshReplicationInformation(ServerClient commands) { lock (this) { var serverHash = ServerHash.GetServerHash(commands.Url); JsonDocument document; var fromFailoverUrls = false; try { document = commands.DirectGet(new OperationMetadata(commands.Url, commands.PrimaryCredentials), RavenReplicationDestinations); failureCounts[commands.Url] = new FailureCounter(); // we just hit the master, so we can reset its failure count } catch (Exception e) { log.ErrorException("Could not contact master for new replication information", e); document = ReplicationInformerLocalCache.TryLoadReplicationInformationFromLocalCache(serverHash); if (document == null) { if (FailoverServers != null && FailoverServers.Length > 0) // try to use configured failover servers { var failoverServers = new ReplicationDocument { Destinations = new List <ReplicationDestination>() }; foreach (var failover in FailoverServers) { failoverServers.Destinations.Add(failover); } document = new JsonDocument(); document.DataAsJson = RavenJObject.FromObject(failoverServers); fromFailoverUrls = true; } } } if (document == null) { lastReplicationUpdate = SystemTime.UtcNow; // checked and not found return; } if (!fromFailoverUrls) { ReplicationInformerLocalCache.TrySavingReplicationInformationToLocalCache(serverHash, document); } UpdateReplicationInformationFromDocument(document); lastReplicationUpdate = SystemTime.UtcNow; } }
public void RefreshReplicationInformation(ServerClient commands) { var serverHash = GetServerHash(commands); JsonDocument document; try { document = commands.DirectGet(commands.Url, RavenReplicationDestinations); failureCounts[commands.Url] = new IntHolder(); // we just hit the master, so we can reset its failure count } catch (Exception e) { log.ErrorException("Could not contact master for new replication information", e); document = TryLoadReplicationInformationFromLocalCache(serverHash); } if (document == null) { lastReplicationUpdate = SystemTime.UtcNow; // checked and not found return; } TrySavingReplicationInformationToLocalCache(serverHash, document); var replicationDocument = document.DataAsJson.JsonDeserialization <ReplicationDocument>(); replicationDestinations = replicationDocument.Destinations.Select(x => x.Url) // filter out replication destination that don't have the url setup, we don't know how to reach them // so we might as well ignore them. Probably private replication destination (using connection string names only) .Where(x => x != null) .ToList(); foreach (var replicationDestination in replicationDestinations) { IntHolder value; if (failureCounts.TryGetValue(replicationDestination, out value)) { continue; } failureCounts[replicationDestination] = new IntHolder(); } lastReplicationUpdate = SystemTime.UtcNow; }
/// <summary> /// Refreshes the replication information. /// </summary> /// <param name="commands">The commands.</param> public void RefreshReplicationInformation(ServerClient commands) { lock (replicationLock) { lastReplicationUpdate = DateTime.UtcNow; var document = commands.DirectGet(commands.Url, RavenReplicationDestinations); failureCounts[commands.Url] = new IntHolder(); // we just hit the master, so we can reset its failure count if (document == null) { return; } var replicationDocument = document.DataAsJson.JsonDeserialization <ReplicationDocument>(); replicationDestinations = replicationDocument.Destinations.Select(x => x.Url).ToList(); foreach (var replicationDestination in replicationDestinations) { IntHolder value; if (failureCounts.TryGetValue(replicationDestination, out value)) { continue; } failureCounts[replicationDestination] = new IntHolder(); } } }