Ejemplo n.º 1
0
        public Task RefreshReplicationInformation(AsyncServerClient commands)
        {
            var serverHash = GetServerHash(commands);

            return(commands.DirectGetAsync(commands.Url, RavenReplicationDestinations).ContinueWith((Task <JsonDocument> getTask) =>
            {
                JsonDocument document;
                if (getTask.Status == TaskStatus.RanToCompletion)
                {
                    document = getTask.Result;
                    failureCounts[commands.Url] = new FailureCounter();                     // we just hit the master, so we can reset its failure count
                }
                else
                {
                    log.ErrorException("Could not contact master for new replication information", getTask.Exception);
                    document = TryLoadReplicationInformationFromLocalCache(serverHash);
                }


                if (IsInvalidDestinationsDocument(document))
                {
                    lastReplicationUpdate = SystemTime.UtcNow;                     // checked and not found
                    return;
                }

                TrySavingReplicationInformationToLocalCache(serverHash, document);

                UpdateReplicationInformationFromDocument(document);

                lastReplicationUpdate = SystemTime.UtcNow;
            }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Refreshes the replication information.
        /// Expert use only.
        /// </summary>
#if SILVERLIGHT || NETFX_CORE
        public Task RefreshReplicationInformation(AsyncServerClient commands)
        {
            lock (this)
            {
                var serverHash = ServerHash.GetServerHash(commands.Url);
                return(commands.DirectGetAsync(new OperationMetadata(commands.Url), RavenReplicationDestinations).ContinueWith((Task <JsonDocument> getTask) =>
                {
                    JsonDocument document;

                    var fromFailoverUrls = false;

                    if (getTask.Status == TaskStatus.RanToCompletion)
                    {
                        document = getTask.Result;
                        failureCounts[commands.Url] = new FailureCounter();                         // we just hit the master, so we can reset its failure count
                    }
                    else
                    {
                        log.ErrorException("Could not contact master for new replication information", getTask.Exception);
                        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 (IsInvalidDestinationsDocument(document))
                    {
                        lastReplicationUpdate = SystemTime.UtcNow;                         // checked and not found
                        return;
                    }

                    if (!fromFailoverUrls)
                    {
                        ReplicationInformerLocalCache.TrySavingReplicationInformationToLocalCache(serverHash, document);
                    }

                    UpdateReplicationInformationFromDocument(document);

                    lastReplicationUpdate = SystemTime.UtcNow;
                }));
            }
        }
Ejemplo n.º 3
0
 public Task UpdateReplicationInformationIfNeeded(AsyncServerClient serverClient)
 {
     return(UpdateReplicationInformationIfNeededInternal(serverClient.Url, key => serverClient.DirectGetAsync(new OperationMetadata(serverClient.Url, serverClient.PrimaryCredentials), key).ResultUnwrap()));
 }
Ejemplo n.º 4
0
 public void RefreshReplicationInformation(AsyncServerClient serverClient)
 {
     RefreshReplicationInformationInternal(serverClient.Url, key => serverClient.DirectGetAsync(new OperationMetadata(serverClient.Url, serverClient.PrimaryCredentials), key).ResultUnwrap());
 }