Ejemplo n.º 1
0
        /// <summary>
        /// Refreshes the replication information.
        /// Expert use only.
        /// </summary>
        public async Task RefreshReplicationInformationAsync(RavenFileSystemClient serverClient)
        {
            var serverHash = ServerHash.GetServerHash(serverClient.ServerUrl);

            try
            {
                var result = await serverClient.Config.GetConfig(SynchronizationConstants.RavenSynchronizationDestinations);

                if (result == null)
                {
                    LastReplicationUpdate = SystemTime.UtcNow;                     // checked and not found
                }
                else
                {
                    var urls = result.GetValues("url");
                    replicationDestinations = urls == null ? new List <string>() : urls.ToList();
                }
            }
            catch (Exception e)
            {
                log.ErrorException("Could not contact master for new replication information", e);
                replicationDestinations = ReplicationInformerLocalCache.TryLoadReplicationInformationFromLocalCache(serverHash).ToList();
                LastReplicationUpdate   = SystemTime.UtcNow;
                return;
            }

            failureCounts[serverClient.ServerUrl] = new FailureCounter();             // we just hit the master, so we can reset its failure count
            ReplicationInformerLocalCache.TrySavingReplicationInformationToLocalCache(serverHash, replicationDestinations);
            UpdateReplicationInformationFromDocument(replicationDestinations);
            LastReplicationUpdate = SystemTime.UtcNow;
        }
Ejemplo n.º 2
0
        public Task UpdateReplicationInformationIfNeeded(RavenFileSystemClient serverClient)
#endif
        {
            if (Conventions.FailoverBehavior == FailoverBehavior.FailImmediately)
            {
                return(new CompletedTask());
            }

            if (LastReplicationUpdate.AddMinutes(5) > SystemTime.UtcNow)
            {
                return(new CompletedTask());
            }

            lock (replicationLock)
            {
                if (firstTime)
                {
                    var serverHash = ServerHash.GetServerHash(serverClient.ServerUrl);

                    var destinations = ReplicationInformerLocalCache.TryLoadReplicationInformationFromLocalCache(serverHash);
                    if (destinations != null)
                    {
                        UpdateReplicationInformationFromDocument(destinations);
                    }
                }

                firstTime = false;

                if (LastReplicationUpdate.AddMinutes(5) > SystemTime.UtcNow)
                {
                    return(new CompletedTask());
                }

                var taskCopy = refreshReplicationInformationTask;
                if (taskCopy != null)
                {
                    return(taskCopy);
                }

                return(refreshReplicationInformationTask = RefreshReplicationInformationAsync(serverClient)
                                                           .ContinueWith(task =>
                {
                    if (task.Exception != null)
                    {
                        log.ErrorException("Failed to refresh replication information", task.Exception);
                    }
                    refreshReplicationInformationTask = null;
                }));
            }
        }
        /// <summary>
        /// Refreshes the replication information.
        /// Expert use only.
        /// </summary>
        public override void RefreshReplicationInformation(RavenFileSystemClient serverClient)
        {
            lock (this)
            {
                var serverHash = ServerHash.GetServerHash(serverClient.FileSystemUrl);

                JsonDocument document = null;

                try
                {
                    var config = serverClient.Config.GetConfig <RavenJObject>(SynchronizationConstants.RavenSynchronizationDestinations).Result;
                    failureCounts[serverClient.FileSystemUrl] = new FailureCounter(); // we just hit the master, so we can reset its failure count

                    if (config != null)
                    {
                        var destinationsArray = config.Value <RavenJArray>("Destinations");
                        if (destinationsArray != null)
                        {
                            document            = new JsonDocument();
                            document.DataAsJson = new RavenJObject()
                            {
                                { "Destinations", destinationsArray }
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    log.ErrorException("Could not contact master for new replication information", e);
                    document = ReplicationInformerLocalCache.TryLoadReplicationInformationFromLocalCache(serverHash);
                }


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

                ReplicationInformerLocalCache.TrySavingReplicationInformationToLocalCache(serverHash, document);

                UpdateReplicationInformationFromDocument(document);

                lastReplicationUpdate = SystemTime.UtcNow;
            }
        }