Skip to content

Container properties cache consolidation#35731

Merged
bambriz merged 42 commits intoAzure:mainfrom
bambriz:container-cache
May 23, 2024
Merged

Container properties cache consolidation#35731
bambriz merged 42 commits intoAzure:mainfrom
bambriz:container-cache

Conversation

@bambriz
Copy link
Copy Markdown
Member

@bambriz bambriz commented May 21, 2024

Description

This PR makes the cache for Container Properties (namely Partition Key Definition and RID) for a container to be cached in the client instance instead of the container instance.
Because at the moment the Python SDK does not handle caches the same as other SDKs which include refreshing the cache
(See Issue 35294) it is not a regression since it is just consolidating the cache of the properties to a single cache in the client instance and the python sdk has not yet implemented caching the container properties as the other SDKs do.

This PR will avoid a situation where: if you call single instances of a container multiple times from a client, it will perform a container read for every operation that does Create, Replace, Upsert, and ReadOffers. It will now instead use the cached container properties after the first container read has already been performed for that specific container.

The Client keeps a cache of properties of each container that is used in the lifetime of the client instance.

The current properties that are cached are "_self" which is the container link "dbsname/coll/containername" , the RID of the container, and the partition key definition of the container.

container_properties = { "_self": "dbsname/colls/containername", "_rid": "########", "partitionKey": {...} }

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

bambriz added 30 commits April 19, 2024 17:43
This adds a client level cache for container properties.
updated tests that were compensating for extra container reads, the extra reads no longer happen with adding the container cache properties in the client.
Fixed some reccomnded changes, and added optimizations for the cache. Only including needed properties info that will be unlikely to change.
Added a method in base.py to set the properties cache so we only have to change one location in case in the future we want to cache additional properties
bambriz and others added 11 commits May 2, 2024 14:01
Changed container cache to be a private attribute.
Also added tests to verify the contents of the cache to be correct ones.
Co-authored-by: Kushagra Thapar <kushuthapar@gmail.com>
Fixed broken tests that used old properties cache. Added samples to show how new properties cache works and best way to get the container properties
@bambriz
Copy link
Copy Markdown
Member Author

bambriz commented May 21, 2024

/azp run python - cosmos - tests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@azure-sdk
Copy link
Copy Markdown
Collaborator

API change check

API changes are not detected in this pull request.

@bambriz bambriz marked this pull request as ready for review May 22, 2024 20:07
Copy link
Copy Markdown
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @bambriz

Comment thread sdk/cosmos/azure-cosmos/test/test_container_properties_cache.py
Copy link
Copy Markdown
Member

@simorenoh simorenoh left a comment

Choose a reason for hiding this comment

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

small comment on the test setup but not a blocker since we can update it with the re-create scenario - thanks Bryan!

@bambriz
Copy link
Copy Markdown
Member Author

bambriz commented May 23, 2024

/azp run python - cosmos - tests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants