Example #1
0
 /// <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();
         }
     }
 }
Example #2
0
        /// <summary>
        /// Updates the replication information if needed.
        /// </summary>
        /// <param name="serverClient">The server client.</param>
        public Task UpdateReplicationInformationIfNeeded(ServerClient serverClient)
        {
            if (conventions.FailoverBehavior == FailoverBehavior.FailImmediately)
            {
                return(new CompletedTask());
            }

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

            lock (replicationLock)
            {
                if (lastReplicationUpdate.AddMinutes(5) > SystemTime.UtcNow)
                {
                    return(new CompletedTask());
                }

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

                return(refreshReplicationInformationTask = Task.Factory.StartNew(() => RefreshReplicationInformation(serverClient))
                                                           .ContinueWith(task =>
                {
                    if (task.Exception != null)
                    {
                        log.ErrorException("Failed to refresh replication information", task.Exception);
                    }
                    refreshReplicationInformationTask = null;
                }));
            }
        }
Example #3
0
 public Operation(ServerClient serverClient, long id)
 {
     client  = serverClient;
     this.id = id;
 }