Skip to content

Commit

Permalink
Query: Fixes logic to determine whether to use distributed query by a…
Browse files Browse the repository at this point in the history
…dding a check for gateway connection mode (#5024)

## Description

This changes the logic for determining whether to use the distributed
query dedicated gateway.

With this PR, we check both the
**AZURE_COSMOS_DISTRIBUTED_QUERY_GATEWAY_ENABLED** environment variable
**and** the connection mode to determine whether to use the distributed
query dedicated gateway. If the environment variable is set to **True**
**and** the connection mode is **gateway**, then we **will** use the
dedicated gateway. If the connection mode is **direct**, we should not
use the distributed query dedicated gateway.


## Type of change

Please delete options that are not relevant.

- [X] Bug fix (non-breaking change which fixes an issue)
- [] New feature (non-breaking change which adds functionality)
- [] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [] This change requires a documentation update

---------

Co-authored-by: neildsh <[email protected]>
  • Loading branch information
sc978345 and neildsh authored Feb 21, 2025
1 parent 557ec7a commit 11e2c34
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/Query/v3Query/QueryIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static QueryIterator Create(
returnResultsInDeterministicOrder: queryRequestOptions.ReturnResultsInDeterministicOrder,
enableOptimisticDirectExecution: queryRequestOptions.EnableOptimisticDirectExecution,
isNonStreamingOrderByQueryFeatureDisabled: queryRequestOptions.IsNonStreamingOrderByQueryFeatureDisabled,
enableDistributedQueryGatewayMode: queryRequestOptions.EnableDistributedQueryGatewayMode,
enableDistributedQueryGatewayMode: queryRequestOptions.EnableDistributedQueryGatewayMode && (clientContext.ClientOptions.ConnectionMode == ConnectionMode.Gateway),
testInjections: queryRequestOptions.TestSettings);

return new QueryIterator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,33 @@ await this.CreateIngestQueryDeleteAsync(
ImplementationAsync);
}

[TestMethod]
public async Task DirectModeTestsAsync()
{
using EnvironmentVariableOverride enableDistributedQueryOverride = new EnvironmentVariableOverride(
ConfigurationManager.DistributedQueryGatewayModeEnabled,
bool.TrueString);

static Task ImplementationAsync(Container container, IReadOnlyList<CosmosObject> _)
{
TestCase[] testCases = new[]
{
MakeTest(
"SELECT VALUE COUNT(1) FROM c",
PageSizes,
Expectations.OneValueWithDocumentCountIsPresent),
};

return RunStreamIteratorTestsAsync(container, testCases);
}

await this.CreateIngestQueryDeleteAsync(
ConnectionModes.Direct,
CollectionTypes.MultiPartition,
CreateDocuments(DocumentCount),
ImplementationAsync);
}

private static async Task RunPartitionedParityTestsAsync(Container container, IEnumerable<string> testCases)
{
IReadOnlyList<FeedRange> feedRanges = await container.GetFeedRangesAsync();
Expand Down Expand Up @@ -393,6 +420,11 @@ public static bool AllDocumentsGreaterThan200ArePresent(List<int> actual)
.ToHashSet()
.SetEquals(actual);
}

public static bool OneValueWithDocumentCountIsPresent(List<int> actual)
{
return (actual.Count == 1) && (actual[0] == DocumentCount);
}
}

private sealed class EnvironmentVariableOverride : IDisposable
Expand Down

0 comments on commit 11e2c34

Please sign in to comment.