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

Replace Cosmos Db metadata query with container query #2215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LeeAtCfc
Copy link

@LeeAtCfc LeeAtCfc commented May 15, 2024

What this PR does / why we need it:
Run a container query rather than a metadata query if containers are specified

Which issue(s) this PR fixes:
Execution of Cosmos Db account metadata queries that can result in throttling errors

Please reference the issue this PR will close: #[462]

Special notes for your reviewer:

Does this PR introduce a user-facing change?:
Implementation change of existing functionality

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Unit tests passing
  • End-to-end tests passing
  • Extended the documentation
  • Provided sample for the feature

Run a container query rather than a metadata query if containers are  specified
@LeeAtCfc
Copy link
Author

@dotnet-policy-service agree company="CFC Underwriting"

@LeeAtCfc LeeAtCfc changed the title Don't run metadata query Replace Cosmos Db metadata query with container query May 15, 2024
@AButcherCFC
Copy link

@adamsitnik

{
var container = _cosmosClient.GetContainer(_options.DatabaseId, containerId);
var query = new QueryDefinition($"SELECT 1 FROM {containerId}");
using var queryStream = container.GetItemQueryStreamIterator(query);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need to call .ReadNextAsync() to execute the operation against the container?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@idkburkes is correct: This is correct. The query is not executed until you call await ReadNextAsync()

Copy link
Collaborator

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The best I can do right now is ask the owners of the CosmosDB SDK to review the change.

{
foreach (var containerId in _options.ContainerIds)
{
var container = _cosmosClient.GetContainer(_options.DatabaseId, containerId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leminh98 @Maya-Painter @sboshra @adityasa could someone from the CosmosDB Team please review this change?

Context: this code is executed quite frequently, from an ASP.NET health check which has almost 6m downloads on nuget.org: https://www.nuget.org/packages/AspNetCore.HealthChecks.CosmosDb

BTW we are soon going to implement #2325 and hopefully reduce the number of users of Microsoft.Azure.DocumentDB.Core package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants