예제 #1
0
        public void RefreshReplicationInformation(ServerClient commands)
        {
            lock (this)
            {
                var serverHash = ServerHash.GetServerHash(commands.Url);

                JsonDocument document;
                try
                {
                    document = commands.DirectGet(new OperationMetadata(commands.Url, commands.Credentials), 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)
                {
                    lastReplicationUpdate = SystemTime.UtcNow;                     // checked and not found
                    return;
                }

                ReplicationInformerLocalCache.TrySavingReplicationInformationToLocalCache(serverHash, document);

                UpdateReplicationInformationFromDocument(document);

                lastReplicationUpdate = SystemTime.UtcNow;
            }
        }
예제 #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;
                    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 (IsInvalidDestinationsDocument(document))
                    {
                        lastReplicationUpdate = SystemTime.UtcNow;                         // checked and not found
                        return;
                    }

                    ReplicationInformerLocalCache.TrySavingReplicationInformationToLocalCache(serverHash, document);

                    UpdateReplicationInformationFromDocument(document);

                    lastReplicationUpdate = SystemTime.UtcNow;
                }));
            }
        }
예제 #3
0
        private void RefreshReplicationInformationInternal(string url, Func <ReplicationDocument> getReplicationDestinations)
        {
            lock (this)
            {
                var serverHash = ServerHash.GetServerHash(url);

                JsonDocument document;
                var          fromFailoverUrls = false;

                try
                {
                    var replicationDestinations = getReplicationDestinations();
                    document           = replicationDestinations == null ? null : RavenJObject.FromObject(replicationDestinations).ToJsonDocument();
                    failureCounts[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
                            {
                                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;
            }
        }
예제 #4
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;
                }));
            }
        }
예제 #5
0
        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;
            }
        }