private void OutgoingHandlerRemoved(OutgoingReplicationHandler handler)
 {
     if (_outgoing.TryRemove(handler, out var stats))
     {
         stats.Handler.DocumentsSend -= OutgoingDocumentsSend;
     }
 }
Esempio n. 2
0
        private void OnOutgoingSendingFailed(OutgoingReplicationHandler instance, Exception e)
        {
            using (instance)
            {
                instance.Failed -= OnOutgoingSendingFailed;
                instance.SuccessfulTwoWaysCommunication -= OnOutgoingSendingSucceeded;

                _outgoing.TryRemove(instance);
                OutgoingReplicationRemoved?.Invoke(instance);

                if (_outgoingFailureInfo.TryGetValue(instance.Node, out ConnectionShutdownInfo failureInfo) == false)
                {
                    return;
                }

                UpdateLastEtag(instance);

                failureInfo.OnError(e);
                failureInfo.DestinationDbId    = instance.DestinationDbId;
                failureInfo.LastHeartbeatTicks = instance.LastHeartbeatTicks;

                _reconnectQueue.Add(failureInfo);

                if (_log.IsInfoEnabled)
                {
                    _log.Info($"Document replication connection ({instance.Node}) failed, and the connection will be retried later.", e);
                }
            }
        }
 public ReplicationIndexTransformerSender(Stream stream, OutgoingReplicationHandler parent, Logger log)
 {
     _log = log;
     _orderedReplicaItems = new SortedList <long, ReplicationBatchIndexItem>();
     _stream = stream;
     _parent = parent;
 }
Esempio n. 4
0
 public ReplicationDocumentSender(Stream stream, OutgoingReplicationHandler parent, Logger log)
 {
     _log = log;
     _orderedReplicaItems = new SortedList <long, ReplicationBatchDocumentItem>();
     _stream = stream;
     _parent = parent;
 }
        private void OutgoingHandlerAdded(OutgoingReplicationHandler handler)
        {
            _outgoing.GetOrAdd(handler, key =>
            {
                handler.DocumentsSend += OutgoingDocumentsSend;

                return(new ReplicationHandlerAndPerformanceStatsList <OutgoingReplicationHandler, OutgoingReplicationStatsAggregator>(handler));
            });
        }
Esempio n. 6
0
        private void UpdateLastEtag(OutgoingReplicationHandler instance)
        {
            var etagPerDestination = _lastSendEtagPerDestination.GetOrAdd(
                instance.Node,
                _ => new LastEtagPerDestination());

            if (etagPerDestination.LastEtag == instance._lastSentDocumentEtag)
            {
                return;
            }

            Interlocked.Exchange(ref etagPerDestination.LastEtag, instance._lastSentDocumentEtag);
        }
Esempio n. 7
0
        private void OnOutgoingSendingSucceeded(OutgoingReplicationHandler instance)
        {
            UpdateLastEtag(instance);

            if (_outgoingFailureInfo.TryGetValue(instance.Node, out ConnectionShutdownInfo failureInfo))
            {
                failureInfo.Reset();
            }
            while (_waitForReplicationTasks.TryDequeue(out TaskCompletionSource <object> result))
            {
                TaskExecutor.Complete(result);
            }
        }
Esempio n. 8
0
        private void AddAndStartOutgoingReplication(ReplicationDestination destination)
        {
            var outgoingReplication = new OutgoingReplicationHandler(_database, destination);

            outgoingReplication.Failed += OnOutgoingSendingFailed;
            outgoingReplication.SuccessfulTwoWaysCommunication += OnOutgoingSendingSucceeded;
            _outgoing.TryAdd(outgoingReplication); // can't fail, this is a brand new instance
            _outgoingFailureInfo.TryAdd(destination, new ConnectionFailureInfo
            {
                Destination = destination
            });
            outgoingReplication.Start();
        }
Esempio n. 9
0
 public ReplicationDocumentSender(Stream stream, OutgoingReplicationHandler parent, Logger log, string[] pathsToSend, string[] destinationAcceptablePaths)
 {
     _log = log;
     if (pathsToSend != null && pathsToSend.Length > 0)
     {
         _pathsToSend = new AllowedPathsValidator(pathsToSend);
     }
     if (destinationAcceptablePaths != null && destinationAcceptablePaths.Length > 0)
     {
         _destinationAcceptablePaths = new AllowedPathsValidator(destinationAcceptablePaths);
     }
     _stream = stream;
     _parent = parent;
 }
Esempio n. 10
0
        private void OnOutgoingSendingSucceeded(OutgoingReplicationHandler instance)
        {
            ConnectionFailureInfo failureInfo;

            if (_outgoingFailureInfo.TryGetValue(instance.Destination, out failureInfo))
            {
                failureInfo.Reset();
            }
            TaskCompletionSource <object> result;

            while (_waitForReplicationTasks.TryDequeue(out result))
            {
                ThreadPool.QueueUserWorkItem(task => ((TaskCompletionSource <object>)task).TrySetResult(null), result);
            }
        }
        private void OutgoingDocumentsSend(OutgoingReplicationHandler handler)
        {
            if (_outgoing.TryGetValue(handler, out var stats) == false)
            {
                // possible?
                return;
            }

            var latestStat = stats.Handler.GetLatestReplicationPerformance();

            if (latestStat != null)
            {
                stats.Performance.Add(latestStat, _cts.Token);
            }
        }
Esempio n. 12
0
        public ReplicationDocumentSender(Stream stream, OutgoingReplicationHandler parent, Logger log, string[] pathsToSend, string[] destinationAcceptablePaths)
        {
            _log = log;
            if (pathsToSend != null && pathsToSend.Length > 0)
            {
                _pathsToSend = new AllowedPathsValidator(pathsToSend);
            }
            if (destinationAcceptablePaths != null && destinationAcceptablePaths.Length > 0)
            {
                _destinationAcceptablePaths = new AllowedPathsValidator(destinationAcceptablePaths);
            }
            _stream = stream;
            _parent = parent;

            _shouldSkipSendingTombstones = _parent.Destination is PullReplicationAsSink sink && sink.Mode == PullReplicationMode.SinkToHub &&
                                           parent._outgoingPullReplicationParams?.PreventDeletionsMode?.HasFlag(PreventDeletionsMode.PreventSinkToHubDeletions) == true &&
                                           _parent._database.ForTestingPurposes?.ForceSendTombstones == false;
        }
Esempio n. 13
0
        private void AddAndStartOutgoingReplication(ReplicationNode node, bool external)
        {
            var outgoingReplication = new OutgoingReplicationHandler(this, Database, node, external);

            outgoingReplication.Failed += OnOutgoingSendingFailed;
            outgoingReplication.SuccessfulTwoWaysCommunication += OnOutgoingSendingSucceeded;
            _outgoing.TryAdd(outgoingReplication); // can't fail, this is a brand new instance

            node.Url = node.Url.Trim();

            _outgoingFailureInfo.TryAdd(node, new ConnectionShutdownInfo
            {
                Node     = node,
                External = external
            });
            outgoingReplication.Start();

            OutgoingReplicationAdded?.Invoke(outgoingReplication);
        }
Esempio n. 14
0
        private void AddAndStartOutgoingReplication(ReplicationNode node, bool external)
        {
            var info = GetConnectionInfo(node, external);

            if (info == null)
            {
                // this means that we were unable to retrive the tcp connection info and will try it again later
                return;
            }
            var outgoingReplication = new OutgoingReplicationHandler(this, Database, node, external, info);

            outgoingReplication.Failed += OnOutgoingSendingFailed;
            outgoingReplication.SuccessfulTwoWaysCommunication += OnOutgoingSendingSucceeded;
            _outgoing.TryAdd(outgoingReplication); // can't fail, this is a brand new instance

            outgoingReplication.Start();

            OutgoingReplicationAdded?.Invoke(outgoingReplication);
        }
Esempio n. 15
0
        private void OnOutgoingSendingFailed(OutgoingReplicationHandler instance, Exception e)
        {
            using (instance)
            {
                _outgoing.TryRemove(instance);

                ConnectionFailureInfo failureInfo;
                if (_outgoingFailureInfo.TryGetValue(instance.Destination, out failureInfo) == false)
                {
                    return;
                }

                _reconnectQueue.Add(failureInfo);

                if (_log.IsInfoEnabled)
                {
                    _log.Info($"Document replication connection ({instance.Destination}) failed, and the connection will be retried later.",
                              e);
                }
            }
        }
 private void OutgoingHandlerAdded(OutgoingReplicationHandler handler)
 {
     handler.HandleReplicationPulse += HandleReplicationPulse;
 }
 private void OutgoingHandlerRemoved(OutgoingReplicationHandler handler)
 {
     handler.HandleReplicationPulse -= HandleReplicationPulse;
 }
Esempio n. 18
0
 public ReplicationDocumentSender(Stream stream, OutgoingReplicationHandler parent, Logger log)
 {
     _log    = log;
     _stream = stream;
     _parent = parent;
 }