Пример #1
0
        public override async Task <IEnumerable <DocumentServiceLease> > SplitPartitionAsync(DocumentServiceLease lease)
        {
            if (lease == null)
            {
                throw new ArgumentNullException(nameof(lease));
            }

            string partitionId           = lease.CurrentLeaseToken;
            string lastContinuationToken = lease.ContinuationToken;

            Logger.InfoFormat("Partition {0} is gone due to split", partitionId);

            // After split the childs are either all or none available
            List <PartitionKeyRange> ranges = await this.EnumPartitionKeyRangesAsync().ConfigureAwait(false);

            List <string> addedPartitionIds = ranges.Where(range => range.Parents.Contains(partitionId)).Select(range => range.Id).ToList();

            if (addedPartitionIds.Count == 0)
            {
                Logger.ErrorFormat("Partition {0} had split but we failed to find at least one child partition", partitionId);
                throw new InvalidOperationException();
            }

            var newLeases = new ConcurrentQueue <DocumentServiceLease>();
            await addedPartitionIds.ForEachAsync(
                async addedRangeId =>
            {
                DocumentServiceLease newLease = await this.leaseManager.CreateLeaseIfNotExistAsync(addedRangeId, lastContinuationToken).ConfigureAwait(false);
                if (newLease != null)
                {
                    newLeases.Enqueue(newLease);
                }
            },
                this.degreeOfParallelism).ConfigureAwait(false);

            if (Logger.IsInfoEnabled())
            {
                Logger.InfoFormat("partition {0} split into {1}", partitionId, string.Join(", ", newLeases.Select(l => l.CurrentLeaseToken)));
            }

            return(newLeases);
        }
Пример #2
0
 public override Task AddOrUpdateLeaseAsync(DocumentServiceLease lease)
 {
     this.HitCount++;
     throw new ArgumentException();
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HealthMonitoringRecord"/> class.
 /// </summary>
 /// <param name="severity">The health severity level.</param>
 /// <param name="operation">The operation.</param>
 /// <param name="lease">The lease.</param>
 /// <param name="exception">The exception.</param>
 public HealthMonitoringRecord(HealthSeverity severity, MonitoredOperation operation, DocumentServiceLease lease, Exception exception)
 {
     if (lease == null)
     {
         throw new ArgumentNullException(nameof(lease));
     }
     this.Severity  = severity;
     this.Operation = operation;
     this.Lease     = lease;
     this.Exception = exception;
 }
Пример #4
0
 public abstract Task <(IEnumerable <DocumentServiceLease>, bool)> HandlePartitionGoneAsync(DocumentServiceLease lease);
Пример #5
0
 public abstract PartitionSupervisor Create(DocumentServiceLease lease);
Пример #6
0
 private bool IsExpired(DocumentServiceLease lease)
 {
     return(lease.Timestamp.ToUniversalTime() + this.leaseExpirationInterval < DateTime.UtcNow);
 }
Пример #7
0
            public WorkerData(Task task, IChangeFeedObserver observer, ChangeFeedObserverContext context, CancellationTokenSource cancellation, DocumentServiceLease lease)
            {
                Debug.Assert(task != null);
                Debug.Assert(observer != null);
                Debug.Assert(context != null);
                Debug.Assert(cancellation != null);

                this.Task         = task;
                this.Observer     = observer;
                this.Context      = context;
                this.Cancellation = cancellation;
                this.Lease        = lease;
            }
 public PartitionCheckpointerCore(DocumentServiceLeaseCheckpointer leaseCheckpointer, DocumentServiceLease lease)
 {
     this.leaseCheckpointer = leaseCheckpointer;
     this.lease             = lease;
 }
        public override async Task CheckpointPartitionAsync(string сontinuationToken)
        {
            this.lease = await this.leaseCheckpointer.CheckpointAsync(this.lease, сontinuationToken).ConfigureAwait(false);

            Logger.InfoFormat("Checkpoint: lease token {0}, new continuation {1}", this.lease.CurrentLeaseToken, this.lease.ContinuationToken);
        }
 /// <summary>
 /// Creates an instance of a <see cref="FeedProcessor"/>.
 /// </summary>
 /// <param name="lease">Lease to be used for feed processing</param>
 /// <param name="observer">Observer to be used</param>
 /// <returns>An instance of a <see cref="FeedProcessor"/>.</returns>
 public abstract FeedProcessor Create(DocumentServiceLease lease, ChangeFeedObserver <T> observer);
 public abstract Task <IEnumerable <DocumentServiceLease> > SplitPartitionAsync(DocumentServiceLease lease);
Пример #12
0
        /// <summary>
        /// Handle a Partition Gone response and decide what to do based on the type of lease.
        /// </summary>
        /// <returns>Returns the list of leases to create and a boolean that indicates whether or not to remove the current lease.</returns>
        public override async Task <(IEnumerable <DocumentServiceLease>, bool)> HandlePartitionGoneAsync(DocumentServiceLease lease)
        {
            if (lease == null)
            {
                throw new ArgumentNullException(nameof(lease));
            }

            string leaseToken            = lease.CurrentLeaseToken;
            string lastContinuationToken = lease.ContinuationToken;

            DefaultTrace.TraceInformation("Lease {0} is gone due to split or merge", leaseToken);

            IReadOnlyList <PartitionKeyRange> overlappingRanges = await this.partitionKeyRangeCache.TryGetOverlappingRangesAsync(
                this.containerRid,
                ((FeedRangeEpk)lease.FeedRange).Range,
                NoOpTrace.Singleton,
                forceRefresh : true);

            if (overlappingRanges.Count == 0)
            {
                DefaultTrace.TraceError("Lease {0} is gone but we failed to find at least one child range", leaseToken);
                throw new InvalidOperationException();
            }

            return(lease switch
            {
                DocumentServiceLeaseCoreEpk feedRangeBaseLease => await this.HandlePartitionGoneAsync(leaseToken, lastContinuationToken, feedRangeBaseLease, overlappingRanges),
                _ => await this.HandlePartitionGoneAsync(leaseToken, lastContinuationToken, (DocumentServiceLeaseCore)lease, overlappingRanges)
            });
Пример #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LeaseLostException" /> class using the specified lease, inner exception, and a flag indicating whether lease is gone.
 /// </summary>
 /// <param name="lease">Instance of a lost lease.</param>
 /// <param name="innerException">The inner exception.</param>
 /// <param name="isGone">Whether lease doesn't exist.</param>
 public LeaseLostException(DocumentServiceLease lease, Exception innerException, bool isGone)
     : base(DefaultMessage, innerException)
 {
     this.Lease  = lease;
     this.IsGone = isGone;
 }
Пример #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LeaseLostException" /> class using the specified lease.
 /// </summary>
 /// <param name="lease">Instance of a lost lease.</param>
 public LeaseLostException(DocumentServiceLease lease)
     : base(DefaultMessage)
 {
     this.Lease = lease;
 }
Пример #15
0
 public abstract Task AddOrUpdateLeaseAsync(DocumentServiceLease lease);
Пример #16
0
 public LeaseRenewerCore(DocumentServiceLease lease, DocumentServiceLeaseManager leaseManager, TimeSpan leaseRenewInterval)
 {
     this.lease              = lease;
     this.leaseManager       = leaseManager;
     this.leaseRenewInterval = leaseRenewInterval;
 }
        private async Task ProcessPartitionAsync(PartitionSupervisor partitionSupervisor, DocumentServiceLease lease)
        {
            try
            {
                await partitionSupervisor.RunAsync(this.shutdownCts.Token).ConfigureAwait(false);
            }
            catch (FeedSplitException ex)
            {
                await this.HandleSplitAsync(lease, ex.LastContinuation).ConfigureAwait(false);
            }
            catch (TaskCanceledException)
            {
                DefaultTrace.TraceVerbose("Lease with token {0}: processing canceled", lease.CurrentLeaseToken);
            }
            catch (Exception e)
            {
                Extensions.TraceException(e);
                DefaultTrace.TraceWarning("Lease with token {0}: processing failed", lease.CurrentLeaseToken);
            }

            await this.RemoveLeaseAsync(lease).ConfigureAwait(false);
        }
Пример #18
0
        private async Task ProcessPartitionAsync(PartitionSupervisor partitionSupervisor, DocumentServiceLease lease)
        {
            try
            {
                await partitionSupervisor.RunAsync(this.shutdownCts.Token).ConfigureAwait(false);
            }
            catch (FeedRangeGoneException ex)
            {
                await this.HandlePartitionGoneAsync(lease, ex.LastContinuation).ConfigureAwait(false);
            }
            catch (OperationCanceledException) when(this.shutdownCts.IsCancellationRequested)
            {
                DefaultTrace.TraceVerbose("Lease with token {0}: processing canceled", lease.CurrentLeaseToken);
            }
            catch (Exception ex)
            {
                await this.monitor.NotifyErrorAsync(lease.CurrentLeaseToken, ex);

                DefaultTrace.TraceWarning("Lease with token {0}: processing failed", lease.CurrentLeaseToken);
            }

            await this.RemoveLeaseAsync(lease : lease, wasAcquired : true).ConfigureAwait(false);
        }