public override async Task AddOrUpdateLeaseAsync(DocumentServiceLease lease)
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();

            if (!this.currentlyOwnedPartitions.TryAdd(lease.CurrentLeaseToken, tcs))
            {
                await this.leaseManager.UpdatePropertiesAsync(lease).ConfigureAwait(false);

                DefaultTrace.TraceVerbose("Lease with token {0}: updated", lease.CurrentLeaseToken);
                return;
            }

            try
            {
                DocumentServiceLease updatedLease = await this.leaseManager.AcquireAsync(lease).ConfigureAwait(false);

                if (updatedLease != null)
                {
                    lease = updatedLease;
                }

                DefaultTrace.TraceInformation("Lease with token {0}: acquired", lease.CurrentLeaseToken);
            }
            catch (Exception)
            {
                await this.RemoveLeaseAsync(lease).ConfigureAwait(false);

                throw;
            }

            PartitionSupervisor supervisor = this.partitionSupervisorFactory.Create(lease);

            this.ProcessPartitionAsync(supervisor, lease).LogException();
        }
        private async Task ProcessPartition(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)
            {
                Logger.DebugFormat("Lease with token {0}: processing canceled", lease.CurrentLeaseToken);
            }
            catch (Exception e)
            {
                Logger.WarnException("Lease with token {0}: processing failed", e, lease.CurrentLeaseToken);
            }

            await this.RemoveLeaseAsync(lease).ConfigureAwait(false);
        }
        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);
        }
예제 #4
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).ConfigureAwait(false);
        }