コード例 #1
0
        private void HandleFailedRequest(
            HttpStatusCode statusCode,
            int subStatusCode,
            string lastContinuation)
        {
            DocDbError docDbError = ExceptionClassifier.ClassifyStatusCodes(statusCode, subStatusCode);

            switch (docDbError)
            {
            case DocDbError.PartitionSplit:
                throw new FeedRangeGoneException("Partition split.", lastContinuation);

            case DocDbError.PartitionNotFound:
                throw new FeedNotFoundException("Partition not found.", lastContinuation);

            case DocDbError.ReadSessionNotAvailable:
                throw new FeedReadSessionNotAvailableException("Read session not availalbe.", lastContinuation);

            case DocDbError.Undefined:
                throw new InvalidOperationException($"Undefined DocDbError for status code {statusCode} and substatus code {subStatusCode}");

            default:
                DefaultTrace.TraceCritical($"Unrecognized DocDbError enum value {docDbError}");
                Debug.Fail($"Unrecognized DocDbError enum value {docDbError}");
                throw new InvalidOperationException($"Unrecognized DocDbError enum value {docDbError} for status code {statusCode} and substatus code {subStatusCode}");
            }
        }
コード例 #2
0
        public override async Task RunAsync(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                TimeSpan delay = this.monitoringDelay;

                try
                {
                    long estimation = await this.remainingWorkEstimator.GetEstimatedRemainingWorkAsync(cancellationToken).ConfigureAwait(false);

                    await this.dispatcher.DispatchEstimation(estimation, cancellationToken);
                }
                catch (DocumentClientException clientException)
                {
                    this.logger.WarnException("exception within estimator", clientException);
                    DocDbError docDbError = ExceptionClassifier.ClassifyClientException(clientException);
                    switch (docDbError)
                    {
                    case DocDbError.Undefined:
                        throw;

                    case DocDbError.PartitionNotFound:
                    case DocDbError.PartitionSplit:
                    case DocDbError.TransientError:
                        // Retry on transient (429) errors
                        break;

                    default:
                        this.logger.Fatal($"Unrecognized DocDbError enum value {docDbError}");
                        Debug.Fail($"Unrecognized DocDbError enum value {docDbError}");
                        throw;
                    }

                    if (clientException.RetryAfter != TimeSpan.Zero)
                    {
                        delay = clientException.RetryAfter;
                    }
                }
                catch (TaskCanceledException canceledException)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        throw;
                    }

                    this.logger.WarnException("exception within estimator", canceledException);

                    // ignore as it is caused by DocumentDB client
                }

                await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
            }
        }
コード例 #3
0
        private void HandleFailedRequest(
            ResponseMessage responseMessage,
            string lastContinuation)
        {
            DocDbError docDbError = ExceptionClassifier.ClassifyStatusCodes(responseMessage.StatusCode, (int)responseMessage.Headers.SubStatusCode);

            switch (docDbError)
            {
            case DocDbError.PartitionSplit:
                throw new FeedRangeGoneException("Partition split.", lastContinuation);

            case DocDbError.Undefined:
                throw CosmosExceptionFactory.Create(responseMessage);

            default:
                DefaultTrace.TraceCritical($"Unrecognized DocDbError enum value {docDbError}");
                Debug.Fail($"Unrecognized DocDbError enum value {docDbError}");
                throw new InvalidOperationException($"Unrecognized DocDbError enum value {docDbError} for status code {responseMessage.StatusCode} and substatus code {responseMessage.Headers.SubStatusCode}");
            }
        }
        public async Task RunAsync(CancellationToken cancellationToken)
        {
            string lastContinuation = this.settings.StartContinuation;

            while (!cancellationToken.IsCancellationRequested)
            {
                TimeSpan delay = this.settings.FeedPollDelay;

                try
                {
                    do
                    {
                        IFeedResponse <Document> response = await this.query.ExecuteNextAsync <Document>(cancellationToken).ConfigureAwait(false);

                        lastContinuation = response.ResponseContinuation;
                        if (response.Count > 0)
                        {
                            await this.DispatchChanges(response, cancellationToken).ConfigureAwait(false);
                        }
                    }while (this.query.HasMoreResults && !cancellationToken.IsCancellationRequested);

                    if (this.options.MaxItemCount != this.settings.MaxItemCount)
                    {
                        this.options.MaxItemCount = this.settings.MaxItemCount;   // Reset after successful execution.
                    }
                }
                catch (DocumentClientException clientException)
                {
                    this.logger.WarnException("exception: partition '{0}'", clientException, this.settings.PartitionKeyRangeId);
                    DocDbError docDbError = ExceptionClassifier.ClassifyClientException(clientException);
                    switch (docDbError)
                    {
                    case DocDbError.PartitionNotFound:
                        throw new PartitionNotFoundException("Partition not found.", lastContinuation);

                    case DocDbError.PartitionSplit:
                        throw new PartitionSplitException("Partition split.", lastContinuation);

                    case DocDbError.Undefined:
                        throw;

                    case DocDbError.TransientError:
                        // Retry on transient (429) errors
                        break;

                    case DocDbError.MaxItemCountTooLarge:
                        if (!this.options.MaxItemCount.HasValue)
                        {
                            this.options.MaxItemCount = DefaultMaxItemCount;
                        }
                        else if (this.options.MaxItemCount <= 1)
                        {
                            this.logger.ErrorFormat("Cannot reduce maxItemCount further as it's already at {0}.", this.options.MaxItemCount);
                            throw;
                        }

                        this.options.MaxItemCount /= 2;
                        this.logger.WarnFormat("Reducing maxItemCount, new value: {0}.", this.options.MaxItemCount);
                        break;

                    default:
                        this.logger.Fatal($"Unrecognized DocDbError enum value {docDbError}");
                        Debug.Fail($"Unrecognized DocDbError enum value {docDbError}");
                        throw;
                    }

                    if (clientException.RetryAfter != TimeSpan.Zero)
                    {
                        delay = clientException.RetryAfter;
                    }
                }
                catch (TaskCanceledException canceledException)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        throw;
                    }

                    this.logger.WarnException("exception: partition '{0}'", canceledException, this.settings.PartitionKeyRangeId);

                    // ignore as it is caused by DocumentDB client
                }

                await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
            }
        }
コード例 #5
0
        public async Task RunAsync(CancellationToken cancellationToken)
        {
            string requestContinuation = this.settings.RequestContinuation;

            while (!cancellationToken.IsCancellationRequested)
            {
                TimeSpan delay = this.settings.FeedPollDelay;

                try
                {
                    requestContinuation = await this.ProcessBatch(cancellationToken).ConfigureAwait(false);

                    if (this.options.MaxItemCount != this.settings.MaxItemCount)
                    {
                        this.options.MaxItemCount = this.settings.MaxItemCount;   // Reset after successful execution.
                    }
                }
                catch (DocumentClientException clientException)
                {
                    this.logger.WarnException("exception: partition '{0}'", clientException, this.settings.PartitionKeyRangeId);
                    DocDbError docDbError = ExceptionClassifier.ClassifyClientException(clientException);
                    switch (docDbError)
                    {
                    case DocDbError.PartitionNotFound:
                        throw new PartitionNotFoundException(requestContinuation);

                    case DocDbError.PartitionSplit:
                        throw new PartitionSplitException(requestContinuation);

                    case DocDbError.Undefined:
                        throw;

                    case DocDbError.MaxItemCountTooLarge:
                        if (!this.options.MaxItemCount.HasValue)
                        {
                            this.options.MaxItemCount = DefaultMaxItemCount;
                        }
                        else if (this.options.MaxItemCount <= 1)
                        {
                            this.logger.ErrorFormat("Cannot reduce maxItemCount further as it's already at {0}.", this.options.MaxItemCount);
                            throw;
                        }

                        this.options.MaxItemCount /= 2;
                        this.logger.WarnFormat("Reducing maxItemCount, new value: {0}.", this.options.MaxItemCount);
                        break;
                    }

                    if (clientException.RetryAfter != TimeSpan.Zero)
                    {
                        delay = clientException.RetryAfter;
                    }
                }
                catch (TaskCanceledException canceledException)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        throw;
                    }

                    this.logger.WarnException("exception: partition '{0}'", canceledException, this.settings.PartitionKeyRangeId);

                    // ignore as it is caused by DocumentDB client
                }

                await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
            }
        }