Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CosmosQueryExecutionContextFactory Refactory #988

Merged
merged 37 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c5bbc0e
drafted out refactor
bchong95 Nov 12, 2019
9cc75f9
removed null check
bchong95 Nov 12, 2019
b14bc0f
resolved some iteration comments
bchong95 Nov 12, 2019
e2d3563
reproduced failure
bchong95 Nov 13, 2019
39b50af
got exceptionless to work for non order by queries
bchong95 Nov 13, 2019
72b1198
got exceptionless working for order by
bchong95 Nov 13, 2019
69e0df2
got parallel basic working
bchong95 Nov 14, 2019
f5b8ab5
got non failure case working again
bchong95 Nov 14, 2019
bdbf605
got continuation token story working
bchong95 Nov 14, 2019
c1c5b2a
fixed miscellaneous tests
bchong95 Nov 15, 2019
dac7d8d
got all the combinations working for exceptionless
bchong95 Nov 15, 2019
f9d1715
added test for empty pages
bchong95 Nov 15, 2019
78130a2
uncommented
bchong95 Nov 15, 2019
ae8523f
wip
bchong95 Nov 15, 2019
25eefc4
resolved iteration comments
bchong95 Nov 15, 2019
58d4540
Merge branch 'master' into users/brchon/ImmutableQueryFactory
bchong95 Nov 15, 2019
17aed1e
fixed changelog
bchong95 Nov 15, 2019
fe870db
build
bchong95 Nov 15, 2019
4cc5159
build
bchong95 Nov 15, 2019
8e4dcf2
resolved iteration comments
bchong95 Nov 16, 2019
f422555
update test
bchong95 Nov 16, 2019
1fa6ae1
automatically advancing page
bchong95 Nov 16, 2019
2ec83e2
fixed some split failures
bchong95 Nov 16, 2019
ede9232
merged
bchong95 Nov 16, 2019
f346aaa
merged
bchong95 Nov 16, 2019
f3fce62
fixed split bugs
bchong95 Nov 17, 2019
816d3de
fixed continuation token exception
bchong95 Nov 17, 2019
d3e9280
merged
bchong95 Nov 17, 2019
3aace4a
added a catch all query excetuion context
bchong95 Nov 17, 2019
e2ebfc9
ammend
bchong95 Nov 17, 2019
65130fd
removed is done check for try get continuation token
bchong95 Nov 17, 2019
3f293e1
updated baseline
bchong95 Nov 17, 2019
511b991
fixed test since code doesn't just throw exceptions anymore
bchong95 Nov 17, 2019
d3771ec
removed stack trace from exception
bchong95 Nov 18, 2019
d07126b
updated error message one more time?
bchong95 Nov 18, 2019
4c73633
updated baselines
bchong95 Nov 18, 2019
be49066
merged
bchong95 Nov 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Microsoft.Azure.Cosmos/src/Query/Core/AsyncLazy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------

bchong95 marked this conversation as resolved.
Show resolved Hide resolved
namespace Microsoft.Azure.Cosmos.Query.Core
{
using System;
using System.Threading;
using System.Threading.Tasks;

internal sealed class AsyncLazy<T>
bchong95 marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly Func<CancellationToken, Task<T>> valueFactory;
private T value;

public AsyncLazy(Func<CancellationToken, Task<T>> valueFactory)
bchong95 marked this conversation as resolved.
Show resolved Hide resolved
{
if (valueFactory == null)
{
throw new ArgumentNullException(nameof(valueFactory));
}

this.valueFactory = valueFactory;
}

public bool ValueInitialized { get; private set; }

public async Task<T> GetValueAsync(CancellationToken cancellationToken)
bchong95 marked this conversation as resolved.
Show resolved Hide resolved
{
// Note that this class is not thread safe.
// if the valueFactory has side effects than this will have issues.
cancellationToken.ThrowIfCancellationRequested();
if (!this.ValueInitialized)
{
this.value = await this.valueFactory(cancellationToken);
this.ValueInitialized = true;
}

return this.value;
}

public T Result
{
get
{
if (!this.ValueInitialized)
{
throw new InvalidOperationException("Can not retrieve value before initialization.");
}

return this.value;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.ExecutionContext
{
using System;
using System.Threading;
using System.Threading.Tasks;

internal sealed class CatchAllCosmosQueryExecutionContext : CosmosQueryExecutionContext
{
private readonly CosmosQueryExecutionContext cosmosQueryExecutionContext;
private bool hitException;

public CatchAllCosmosQueryExecutionContext(
CosmosQueryExecutionContext cosmosQueryExecutionContext)
{
if (cosmosQueryExecutionContext == null)
{
throw new ArgumentNullException(nameof(cosmosQueryExecutionContext));
}

this.cosmosQueryExecutionContext = cosmosQueryExecutionContext;
}

public override bool IsDone => this.hitException || this.cosmosQueryExecutionContext.IsDone;

public override void Dispose()
{
this.cosmosQueryExecutionContext.Dispose();
}

public override async Task<QueryResponseCore> ExecuteNextAsync(CancellationToken cancellationToken)
{
if (this.IsDone)
{
throw new InvalidOperationException(
$"Can not {nameof(ExecuteNextAsync)} from a {nameof(CosmosQueryExecutionContext)} where {nameof(this.IsDone)}.");
}

cancellationToken.ThrowIfCancellationRequested();

QueryResponseCore queryResponseCore;
try
{
queryResponseCore = await this.cosmosQueryExecutionContext.ExecuteNextAsync(cancellationToken);
}
catch (Exception ex)
{
queryResponseCore = QueryResponseFactory.CreateFromException(ex);
}

if (!queryResponseCore.IsSuccess)
{
this.hitException = true;
}

return queryResponseCore;
}

public override bool TryGetContinuationToken(out string continuationToken)
{
return this.cosmosQueryExecutionContext.TryGetContinuationToken(out continuationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public abstract bool IsDone
/// <summary>
/// Executes the context to feed the next page of results.
/// </summary>
/// <param name="token">The cancellation token.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task to await on, which in return provides a DoucmentFeedResponse of documents.</returns>
public abstract Task<QueryResponseCore> ExecuteNextAsync(CancellationToken token);
public abstract Task<QueryResponseCore> ExecuteNextAsync(CancellationToken cancellationToken);

public abstract bool TryGetContinuationToken(out string state);
public abstract bool TryGetContinuationToken(out string continuationToken);
}
}
Loading