public override async Task <QueryResponseCore> ExecuteNextAsync(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // If the cache is stale the entire execute context has incorrect values and should be recreated.
            // This should only be done for the first execution.
            // If results have already been pulled,
            // then an error should be returned to the user,
            // since it's not possible to combine query results from multiple containers.
            QueryResponseCore queryResponse = await this.currentCosmosQueryExecutionContext.ExecuteNextAsync(cancellationToken);

            if (
                (queryResponse.StatusCode == System.Net.HttpStatusCode.Gone) &&
                (queryResponse.SubStatusCode == Documents.SubStatusCodes.NameCacheIsStale) &&
                !this.alreadyRetried)
            {
                await this.cosmosQueryContext.QueryClient.ForceRefreshCollectionCacheAsync(
                    this.cosmosQueryContext.ResourceLink.OriginalString,
                    cancellationToken);

                this.alreadyRetried = true;
                this.currentCosmosQueryExecutionContext.Dispose();
                this.currentCosmosQueryExecutionContext = this.cosmosQueryExecutionContextFactory();
                return(await this.ExecuteNextAsync(cancellationToken));
            }

            return(queryResponse);
        }
 public CosmosQueryExecutionContextWithNameCacheStaleRetry(
     CosmosQueryContext cosmosQueryContext,
     Func <CosmosQueryExecutionContext> cosmosQueryExecutionContextFactory)
 {
     this.cosmosQueryContext = cosmosQueryContext ?? throw new ArgumentNullException(nameof(cosmosQueryContext));
     this.cosmosQueryExecutionContextFactory = cosmosQueryExecutionContextFactory ?? throw new ArgumentNullException(nameof(cosmosQueryExecutionContextFactory));
     this.currentCosmosQueryExecutionContext = cosmosQueryExecutionContextFactory();
 }
Beispiel #3
0
        public CatchAllCosmosQueryExecutionContext(
            CosmosQueryExecutionContext cosmosQueryExecutionContext)
        {
            if (cosmosQueryExecutionContext == null)
            {
                throw new ArgumentNullException(nameof(cosmosQueryExecutionContext));
            }

            this.cosmosQueryExecutionContext = cosmosQueryExecutionContext;
        }
Beispiel #4
0
        public override async Task <QueryResponseCore> ExecuteNextAsync(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            TryCatch <CosmosQueryExecutionContext> tryCreateCosmosQueryExecutionContext = await this.lazyTryCreateCosmosQueryExecutionContext.GetValueAsync(cancellationToken);

            if (!tryCreateCosmosQueryExecutionContext.Succeeded)
            {
                return(QueryResponseFactory.CreateFromException(tryCreateCosmosQueryExecutionContext.Exception));
            }

            CosmosQueryExecutionContext cosmosQueryExecutionContext = tryCreateCosmosQueryExecutionContext.Result;
            QueryResponseCore           queryResponseCore           = await cosmosQueryExecutionContext.ExecuteNextAsync(cancellationToken);

            return(queryResponseCore);
        }