Ejemplo n.º 1
0
        protected IEnumerable <IReplicationPerformanceStats> PrepareInitialPerformanceStats()
        {
            foreach (var handler in Database.ReplicationLoader.IncomingHandlers)
            {
                var stats = handler.GetReplicationPerformance();

                if (stats.Length == 0)
                {
                    stats = new IncomingReplicationPerformanceStats[] { new IncomingReplicationPerformanceStats() };
                }

                yield return(handler.PullReplication
                    ? IncomingPerformanceStats.ForPullReplication(handler.ConnectionInfo.SourceDatabaseId, handler.SourceFormatted, stats)
                    : IncomingPerformanceStats.ForPushReplication(handler.ConnectionInfo.SourceDatabaseId, handler.GetReplicationPerformanceType(), handler.SourceFormatted, stats));
            }

            foreach (var handler in Database.ReplicationLoader.OutgoingHandlers)
            {
                var stats = handler.GetReplicationPerformance();

                if (stats.Length == 0)
                {
                    stats = new OutgoingReplicationPerformanceStats[] { new OutgoingReplicationPerformanceStats() };
                }

                yield return(handler.IsPullReplicationAsHub
                    ? OutgoingPerformanceStats.ForPullReplication(handler.DestinationDbId, handler.DestinationFormatted, stats)
                    : OutgoingPerformanceStats.ForPushReplication(handler.DestinationDbId, handler.GetReplicationPerformanceType(), handler.DestinationFormatted, stats));
            }
        }
Ejemplo n.º 2
0
        protected override List <IReplicationPerformanceStats> PreparePerformanceStats()
        {
            var results = new List <IReplicationPerformanceStats>(_incoming.Count + _outgoing.Count + _incomingErrors.Count + _outgoingErrors.Count);

            foreach (var incoming in _incoming)
            {
                // This is done this way instead of using
                // _incoming.Values because .Values locks the entire
                // dictionary.

                var handlerAndPerformanceStatsList = incoming.Value;
                var handler     = handlerAndPerformanceStatsList.Handler;
                var performance = handlerAndPerformanceStatsList.Performance;

                var itemsToSend = new List <IncomingReplicationStatsAggregator>(performance.Count);
                while (performance.TryTake(out IncomingReplicationStatsAggregator stat))
                {
                    itemsToSend.Add(stat);
                }

                var latestStats = handler.GetLatestReplicationPerformance();

                if (latestStats != null && latestStats.Completed == false && itemsToSend.Contains(latestStats) == false)
                {
                    itemsToSend.Add(latestStats);
                }

                if (itemsToSend.Count > 0)
                {
                    var stats = itemsToSend.Select(item => item.ToReplicationPerformanceLiveStatsWithDetails()).ToArray();
                    results.Add(handler.PullReplication
                        ? IncomingPerformanceStats.ForPullReplication(handler.ConnectionInfo.SourceDatabaseId, handler.SourceFormatted, stats)
                        : IncomingPerformanceStats.ForPushReplication(handler.ConnectionInfo.SourceDatabaseId, handler.GetReplicationPerformanceType(), handler.SourceFormatted, stats));
                }
            }

            foreach (var outgoing in _outgoing)
            {
                // This is done this way instead of using
                // _outgoing.Values because .Values locks the entire
                // dictionary.

                var handlerAndPerformanceStatsList = outgoing.Value;
                var handler     = handlerAndPerformanceStatsList.Handler;
                var performance = handlerAndPerformanceStatsList.Performance;

                var itemsToSend = new List <OutgoingReplicationStatsAggregator>(performance.Count);
                while (performance.TryTake(out OutgoingReplicationStatsAggregator stat))
                {
                    itemsToSend.Add(stat);
                }

                var latestStats = handler.GetLatestReplicationPerformance();

                if (latestStats != null && latestStats.Completed == false && itemsToSend.Contains(latestStats) == false)
                {
                    itemsToSend.Add(latestStats);
                }

                if (itemsToSend.Count > 0)
                {
                    var stats = itemsToSend.Select(item => item.ToReplicationPerformanceLiveStatsWithDetails()).ToArray();
                    results.Add(handler.IsPullReplicationAsHub
                        ? OutgoingPerformanceStats.ForPullReplication(handler.DestinationDbId, handler.DestinationFormatted, stats)
                        : OutgoingPerformanceStats.ForPushReplication(handler.DestinationDbId, handler.GetReplicationPerformanceType(), handler.DestinationFormatted, stats));
                }
            }

            foreach (var outgoingError in _outgoingErrors)
            {
                var type = outgoingError.Key is InternalReplication
                    ? ReplicationPerformanceType.OutgoingInternal
                    : ReplicationPerformanceType.OutgoingExternal;
                results.Add(OutgoingPerformanceStats.ForPushReplication(outgoingError.Key.Database, type, outgoingError.Value.DestinationFormatted, outgoingError.Value.GetReplicationPerformance()));
                _outgoingErrors.TryRemove(outgoingError.Key, out _);
            }

            foreach (var incomingError in _incomingErrors)
            {
                results.Add(IncomingPerformanceStats.ForPullReplication(incomingError.Key.Database, incomingError.Value.DestinationFormatted, incomingError.Value.GetReplicationPerformance()));
                _incomingErrors.TryRemove(incomingError.Key, out _);
            }

            return(results);
        }