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

Query: Refactors Optimistic Direct Execution to be turned on by default on .NET SDK #4225

Merged
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c5afef5
Turned on ODe by default
akotalwar Dec 21, 2023
1829fac
update subpartitioning tests to include ODE
NaluTripician Jan 2, 2024
1bac380
Updated contracts
akotalwar Jan 3, 2024
caf86c6
Merge branch 'users/akotalwar/TurnOnODEByDefault' of https://github.c…
akotalwar Jan 3, 2024
2fe5471
adds multihash test cases
NaluTripician Jan 3, 2024
f1aae84
Updated client serialization test output
akotalwar Jan 3, 2024
fa4b47f
Merge branch 'users/akotalwar/TurnOnODEByDefault' of https://github.c…
akotalwar Jan 3, 2024
492425c
Updated OffsetLimitPageSize() test
akotalwar Jan 4, 2024
255d13b
Revert changes to Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos…
akotalwar Jan 4, 2024
f4514db
Updated EndToEndTraceWriterBaselineTests.ReadManyAsync baseline test
akotalwar Jan 4, 2024
094e886
Removed account details
akotalwar Jan 5, 2024
cc1db80
Updated performance benchmark results
akotalwar Jan 5, 2024
ab69838
Merge branch 'master' into users/akotalwar/TurnOnODEByDefault
akotalwar Jan 6, 2024
4fb4163
Set enableODE to true for some of the tests
akotalwar Jan 10, 2024
badcfd0
Merge branch 'users/akotalwar/TurnOnODEByDefault' of https://github.c…
akotalwar Jan 10, 2024
eb85e34
Updated Feed token tests to test ODE and non ODE cases
akotalwar Jan 10, 2024
426f6b0
Added ODE testing for Session token regression test
akotalwar Jan 12, 2024
8f0ce41
Updated AggregateQueryTests() and CosmosMultiHashTest()
akotalwar Jan 12, 2024
e30479f
Reverted changes to OffsetLimitPageSize()
akotalwar Jan 13, 2024
a8e01e8
Added ODE testing to AggregateFunctionAsync()
akotalwar Jan 15, 2024
53ed6dc
Removed account details from baseline tests
akotalwar Jan 15, 2024
0110e90
Added assert to confirm that the right document is being returned eve…
akotalwar Jan 16, 2024
07e1a9e
Merge branch 'master' into users/akotalwar/TurnOnODEByDefault
akotalwar Jan 16, 2024
ac55208
Updated location of foreach loop for ODE
akotalwar Jan 16, 2024
2e2e35a
Merge branch 'users/akotalwar/TurnOnODEByDefault' of https://github.c…
akotalwar Jan 16, 2024
ddea7d0
Updated baselines
akotalwar Jan 17, 2024
5af47e4
Merge branch 'master' into users/akotalwar/TurnOnODEByDefault
akotalwar Jan 17, 2024
0918378
Fixed comments
akotalwar Jan 19, 2024
021cad9
Merge branch 'users/akotalwar/TurnOnODEByDefault' of https://github.c…
akotalwar Jan 19, 2024
2b068e0
Cleaned up code
akotalwar Jan 19, 2024
78ea0e4
Merge branch 'master' into users/akotalwar/TurnOnODEByDefault
akotalwar Jan 19, 2024
131112c
Fixed baselines
akotalwar Jan 19, 2024
f84c9d9
Merge branch 'users/akotalwar/TurnOnODEByDefault' of https://github.c…
akotalwar Jan 19, 2024
4ebd3a8
Updated more baselines
akotalwar Jan 19, 2024
3d3c7f7
Merge branch 'master' into users/akotalwar/TurnOnODEByDefault
akotalwar Jan 19, 2024
cd871ad
Setting QueryRequestRateTest() to not use ODE
akotalwar Jan 22, 2024
ede9b21
Merge branch 'users/akotalwar/TurnOnODEByDefault' of https://github.c…
akotalwar Jan 22, 2024
d4df81c
Merge branch 'master' into users/akotalwar/TurnOnODEByDefault
akotalwar Jan 23, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ private static Documents.PartitionKeyDefinition GetPartitionKeyDefinition(InputP
Debug.Assert(containerQueryProperties.ResourceId != null, "CosmosQueryExecutionContextFactory Assert!", "Container ResourceId cannot be null!");

List<Documents.PartitionKeyRange> targetRanges;
if (partitionedQueryExecutionInfo != null)
if (partitionedQueryExecutionInfo != null || inputParameters.InitialFeedRange != null)
akotalwar marked this conversation as resolved.
Show resolved Hide resolved
{
targetRanges = await CosmosQueryExecutionContextFactory.GetTargetPartitionKeyRangesAsync(
cosmosQueryContext.QueryClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,7 @@ public class QueryRequestOptions : RequestOptions
/// <value>
/// Direct (optimistic) execution offers improved performance for several kinds of queries such as a single partition streaming query.
/// </value>
#if PREVIEW
public
#else
internal
#endif
bool EnableOptimisticDirectExecution { get; set; }
#if PREVIEW
= true;
#endif
public bool EnableOptimisticDirectExecution { get; set; } = true;
akotalwar marked this conversation as resolved.
Show resolved Hide resolved
akotalwar marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets or sets the maximum number of items that can be buffered client side during
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ public async Task QueryRequestRateTest(bool directMode)
{
MaxItemCount = 1,
MaxConcurrency = 1,
#if PREVIEW
EnableOptimisticDirectExecution = false
#endif
EnableOptimisticDirectExecution = true
akotalwar marked this conversation as resolved.
Show resolved Hide resolved
}))
{
while (feedIterator.HasMoreResults)
Expand Down Expand Up @@ -271,9 +269,7 @@ public async Task QueryRequestRateTest(bool directMode)
{
MaxItemCount = 1,
MaxConcurrency = 1,
#if PREVIEW
EnableOptimisticDirectExecution = false
#endif
EnableOptimisticDirectExecution = true
akotalwar marked this conversation as resolved.
Show resolved Hide resolved
});

// First request should be a success
Expand Down Expand Up @@ -818,7 +814,7 @@ public async Task TesOdeTokenCompatibilityWithNonOdePipeline()
QueryRequestOptions newQueryRequestOptions = new QueryRequestOptions
{
MaxItemCount = 50,
EnableOptimisticDirectExecution = false
EnableOptimisticDirectExecution = true
akotalwar marked this conversation as resolved.
Show resolved Hide resolved
};

// use Continuation Token to create new iterator and use same trace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ public async Task QueryPlanRetryTimeoutTestAsync()

QueryRequestOptions requestOptions = new QueryRequestOptions()
{
#if PREVIEW
EnableOptimisticDirectExecution = false
akotalwar marked this conversation as resolved.
Show resolved Hide resolved
#endif
};

using FeedIterator<JObject> iterator = gatewayQueryPlanContainer.GetItemQueryIterator<JObject>("select * From T order by T.status", requestOptions: requestOptions);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -94,48 +94,64 @@ public async Task TestQueryWithCustomJsonSerializer()
Assert.AreEqual(1, toStreamCount, "parameter should use custom serializer");
Assert.AreEqual(0, fromStreamCount);

toStreamCount = 0;
fromStreamCount = 0;

FeedIterator<ToDoActivity> itemIterator = container.GetItemQueryIterator<ToDoActivity>(
query
#if PREVIEW
, requestOptions: new QueryRequestOptions() { EnableOptimisticDirectExecution = false }
#endif
);
List<ToDoActivity> items = new List<ToDoActivity>();
while (itemIterator.HasMoreResults)
foreach (bool enableODE in new bool[] { false, true })
{
items.AddRange(await itemIterator.ReadNextAsync());
}

Assert.AreEqual(2, toStreamCount);
Assert.AreEqual(1, fromStreamCount);

toStreamCount = 0;
fromStreamCount = 0;
toStreamCount = 0;
fromStreamCount = 0;

FeedIterator<ToDoActivity> itemIterator = container.GetItemQueryIterator<ToDoActivity>(
query,
requestOptions: new QueryRequestOptions() { EnableOptimisticDirectExecution = enableODE }
);
List<ToDoActivity> items = new List<ToDoActivity>();
while (itemIterator.HasMoreResults)
{
items.AddRange(await itemIterator.ReadNextAsync());
}

// Verify that the custom serializer is actually being used via stream
FeedIterator itemStreamIterator = container.GetItemQueryStreamIterator(
query
#if PREVIEW
, requestOptions: new QueryRequestOptions() { EnableOptimisticDirectExecution = false }
#endif
);
while (itemStreamIterator.HasMoreResults)
{
ResponseMessage response = await itemStreamIterator.ReadNextAsync();
using (StreamReader reader = new StreamReader(response.Content))
// The toStreamCount variable will differ between ODE and non-ODE pipelines due to the non-ODE pipelines needing to get the query plan which makes an additional serialization call during its initialization.
if (enableODE)
{
string content = await reader.ReadToEndAsync();
Assert.IsTrue(content.Contains("9001.42"));
Assert.IsFalse(content.Contains("description"), "Description should be ignored and not in the JSON");
Assert.AreEqual(1, toStreamCount);
}
else
{
Assert.AreEqual(2, toStreamCount);
}

Assert.AreEqual(1, fromStreamCount);

toStreamCount = 0;
fromStreamCount = 0;

// Verify that the custom serializer is actually being used via stream
FeedIterator itemStreamIterator = container.GetItemQueryStreamIterator(
query,
requestOptions: new QueryRequestOptions() { EnableOptimisticDirectExecution = enableODE }
);
while (itemStreamIterator.HasMoreResults)
{
ResponseMessage response = await itemStreamIterator.ReadNextAsync();
using (StreamReader reader = new StreamReader(response.Content))
{
string content = await reader.ReadToEndAsync();
Assert.IsTrue(content.Contains("9001.42"));
Assert.IsFalse(content.Contains("description"), "Description should be ignored and not in the JSON");
}
}
}

Assert.AreEqual(2, toStreamCount);
Assert.AreEqual(0, fromStreamCount);
// The toStreamCount variable will differ between ODE and non-ODE pipelines due to the non-ODE pipelines needing to get the query plan which makes an additional serialization call during its initialization.
if (enableODE)
{
Assert.AreEqual(1, toStreamCount);
}
else
{
Assert.AreEqual(2, toStreamCount);
}

Assert.AreEqual(0, fromStreamCount);
}
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,64 +447,68 @@ public async Task MultiHashQueryItemTest()
doc.SetValue("Type", "Goverment");
documents[2] = await this.container.CreateItemAsync<Document>(doc);

//Query
foreach (Document document in documents)
foreach (bool odeEnabled in new bool[] { false, true })
{
pKey = new PartitionKeyBuilder()
.Add(document.GetPropertyValue<string>("ZipCode"))
.Add(document.GetPropertyValue<string>("City"))
.Build();

badPKey = new PartitionKeyBuilder()
.Add(document.GetPropertyValue<string>("City"))
.Build();

String query = $"SELECT * from c where c.id = \"{document.GetPropertyValue<string>("id")}\"";

using (FeedIterator<Document> feedIterator = this.container.GetItemQueryIterator<Document>(
query,
null,
new QueryRequestOptions() { PartitionKey = pKey }))
//Query
foreach (Document document in documents)
{
Assert.IsTrue(feedIterator.HasMoreResults);
pKey = new PartitionKeyBuilder()
.Add(document.GetPropertyValue<string>("ZipCode"))
.Add(document.GetPropertyValue<string>("City"))
.Build();

FeedResponse<Document> queryDoc = await feedIterator.ReadNextAsync();
queryDoc.First<Document>();
Assert.IsTrue(queryDoc.Count == 1);
feedIterator.Dispose();
}
badPKey = new PartitionKeyBuilder()
.Add(document.GetPropertyValue<string>("City"))
.Build();

//Using an incomplete partition key with prefix of PK path definition
pKey = new PartitionKeyBuilder()
.Add(document.GetPropertyValue<string>("ZipCode"))
.Build();
using (FeedIterator<Document> feedIterator = this.container.GetItemQueryIterator<Document>(
query,
null,
new QueryRequestOptions() { PartitionKey = pKey }))
{
Assert.IsTrue(feedIterator.HasMoreResults);
String query = $"SELECT * from c where c.id = \"{document.GetPropertyValue<string>("id")}\"";

FeedResponse<Document> queryDoc = await feedIterator.ReadNextAsync();
queryDoc.First<Document>();
Assert.IsTrue(queryDoc.Count == 1);
feedIterator.Dispose();
}
using (FeedIterator<Document> feedIterator = this.container.GetItemQueryIterator<Document>(
query,
null,
new QueryRequestOptions() { EnableOptimisticDirectExecution = odeEnabled, PartitionKey = pKey }))
{
Assert.IsTrue(feedIterator.HasMoreResults);

//Negative test - using incomplete partition key
using (FeedIterator<Document> badFeedIterator = this.container.GetItemQueryIterator<Document>(
query,
null,
new QueryRequestOptions() { PartitionKey = badPKey}))
{
FeedResponse<Document> queryDocBad = await badFeedIterator.ReadNextAsync();
Assert.ThrowsException<InvalidOperationException>(() =>
queryDocBad.First<Document>()
);
badFeedIterator.Dispose();
FeedResponse<Document> queryDoc = await feedIterator.ReadNextAsync();
Document retrievedDocument = queryDoc.First<Document>();
Assert.IsTrue(queryDoc.Count == 1);
Assert.AreEqual(document.Id, retrievedDocument.Id);
feedIterator.Dispose();
}

//Using an incomplete partition key with prefix of PK path definition
pKey = new PartitionKeyBuilder()
.Add(document.GetPropertyValue<string>("ZipCode"))
.Build();
using (FeedIterator<Document> feedIterator = this.container.GetItemQueryIterator<Document>(
query,
null,
new QueryRequestOptions() { EnableOptimisticDirectExecution = odeEnabled, PartitionKey = pKey }))
{
Assert.IsTrue(feedIterator.HasMoreResults);

FeedResponse<Document> queryDoc = await feedIterator.ReadNextAsync();
Document retrievedDocument = queryDoc.First<Document>();
Assert.IsTrue(queryDoc.Count == 1);
Assert.AreEqual(document.Id, retrievedDocument.Id);
feedIterator.Dispose();
}

//Negative test - using incomplete partition key
using (FeedIterator<Document> badFeedIterator = this.container.GetItemQueryIterator<Document>(
query,
null,
new QueryRequestOptions() { EnableOptimisticDirectExecution = odeEnabled, PartitionKey = badPKey }))
{
FeedResponse<Document> queryDocBad = await badFeedIterator.ReadNextAsync();
Assert.ThrowsException<InvalidOperationException>(() =>
queryDocBad.First<Document>()
);
badFeedIterator.Dispose();
}
}
}
}

}
}
Loading
Loading