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

Spring Cosmos - Support patch/partial update #21433

Closed
Tracked by #21491
z1069867141 opened this issue May 14, 2021 · 21 comments · Fixed by #32630
Closed
Tracked by #21491

Spring Cosmos - Support patch/partial update #21433

z1069867141 opened this issue May 14, 2021 · 21 comments · Fixed by #32630
Assignees
Labels
azure-spring All azure-spring related issues azure-spring-cosmos Spring cosmos related issues. Client This issue points to a problem in the data-plane of the library. feature-request This issue requires a new behavior in the product in order be resolved.
Milestone

Comments

@z1069867141
Copy link

cosmos is a document DB, and one record could be large. Sometimes it's desired to only update part of the document instead of the whole document.

This story is to support the partial patch update to one cosmos document.

@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels May 14, 2021
@z1069867141 z1069867141 changed the title [FEATURE REQ]Support patch/partial update [Enhance Spring integration for cosmos DB]Support patch/partial update May 14, 2021
@z1069867141 z1069867141 changed the title [Enhance Spring integration for cosmos DB]Support patch/partial update Support patch/partial update May 14, 2021
@saragluna saragluna added azure-spring All azure-spring related issues azure-spring-cosmos Spring cosmos related issues. Client This issue points to a problem in the data-plane of the library. feature-request This issue requires a new behavior in the product in order be resolved. labels May 14, 2021
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label May 14, 2021
@saragluna saragluna removed the question The issue doesn't require a change to the product in order to be resolved. Most issues start as that label May 14, 2021
@saragluna saragluna changed the title Support patch/partial update Spring Cosmos - Support patch/partial update May 14, 2021
@backwind1233 backwind1233 removed the customer-reported Issues that are reported by GitHub users external to the Azure organization. label May 14, 2021
@stliu stliu added this to the Backlog milestone Aug 11, 2021
@kushagraThapar
Copy link
Member

Cosmos is waiting for Bulk / Batch / Patch GA, once that is done, this can be implemented in spring.

@Manuel-Moya
Copy link

Patch is GA :)

@kushagraThapar
Copy link
Member

@Manuel-Moya - yes, it is GA now, will be released in Java SDK v4.21.0 sometime next week. Once that is out, we will start building support for it in spring-data-cosmos SDK.

@sachinadiga
Copy link

@kushagraThapar any progress on this? what is the timeline we have by which this can be implemented.

@MihaiTudorP
Copy link

MihaiTudorP commented Nov 11, 2022

Hello, is there any update on this? It's been some time since the 3rd of November, 2021, with nothing here. Any roadmap milestones or estimated release in which this will come out for Spring? The Cosmos feature has been available for quite some time now.

@backwind1233
Copy link
Contributor

backwind1233 commented Nov 14, 2022

Hi @kushagraThapar, is there any updates you can share with MihaiTudorP?

@kushagraThapar kushagraThapar modified the milestones: Backlog, 2023-03 Nov 14, 2022
@kushagraThapar
Copy link
Member

@MihaiTudorP - apologies for the missed update. We do plan to pick up Patch API work in this semester and plan to deliver it early next year after the holidays.
Since we are still looking into the design phase, I am wondering if we can collect some design input from you. And the most important question being how do you plan to use Patch API in spring data cosmos SDK? Since spring-data abstracts out most of the database components, exposing Patch API is going to be interesting from design point of view.
cc @TheovanKraay
@trande4884, can you please take this discussion forward?

@MihaiTudorP
Copy link

MihaiTudorP commented Nov 15, 2022

@MihaiTudorP - apologies for the missed update. We do plan to pick up Patch API work in this semester and plan to deliver it early next year after the holidays. Since we are still looking into the design phase, I am wondering if we can collect some design input from you. And the most important question being how do you plan to use Patch API in spring data cosmos SDK? Since spring-data abstracts out most of the database components, exposing Patch API is going to be interesting from design point of view. cc @TheovanKraay @trande4884, can you please take this discussion forward?

Hi, @kushagraThapar , thank you very much for the swift update. Do you have also an estimated date of delivery for this, so that I can plan the version upgrade on my project? Also, if you need input, I will provide the needed information, just say what design-related info you need for this in order to develop the patch.

@trande4884
Copy link
Member

@MihaiTudorP we do not yet have an estimated date of delivery, I will update here once we do

@TheovanKraay
Copy link
Member

@MihaiTudorP as Kushagra mention, we would also really like to collect some design input from you.

The most important question being: what is your motivation for wanting to use patch api in Spring?

If, for example, the motivation is to save on RU costs from doing replace(), keep in mind that the RU cost for patch() is equivalent to the RU for replace() because the physics in terms of physical resources (cpu, memory, etc.) are roughly the same. The cost savings for patch() compared to replace() will come from avoiding the RU cost for a read() and cpu/memory burned on the application that comes before replace(). For example, if I want to update a property – I can either:

  1. Send a patch()

Or

  1. read() the document + patch within the application tier + replace() the document

Typically Spring users are not needing to do #2 and so there is no benefit in this space. However, another major benefit for patch is avoiding etag contention from highly concurrent updates.

hence, any feedback on your motivation and use case for using patch, and how you expect it to benefit you, will be greatly appreciated! Thank you.

@MihaiTudorP
Copy link

@TheovanKraay my motivation is to improve overall application performance (sending less data should improve processing speeds) and avoid etag contention from concurrent updates. Also, less time on the network for sensitive data.

@TheovanKraay TheovanKraay self-assigned this Nov 22, 2022
@arunim29
Copy link

arunim29 commented Dec 1, 2022

@TheovanKraay @kushagraThapar is there a way to use vanilla cosmos client provided by cosmos sdk along with spring data cosmos. Basically, share the same cosmosClient instance. With this, we can use the best of both worlds.

I could not find a way because spring data cosmos expects a bean of cosmosClientBuilder instead of cosmosClient. If it would have been cosmosClient, I could have shared the instance. Any idea on how to achieve this?

@TheovanKraay
Copy link
Member

@TheovanKraay my motivation is to improve overall application performance (sending less data should improve processing speeds) and avoid etag contention from concurrent updates. Also, less time on the network for sensitive data.

Hello @MihaiTudorP, in order to help with design of this, we have a few follow up questions:

  1. Is your expectation to use patch via CosmosTemplate or the Repositories?
  2. Are you planning to use Reactive Spring or Spring?

@TheovanKraay
Copy link
Member

TheovanKraay commented Dec 1, 2022

@TheovanKraay @kushagraThapar is there a way to use vanilla cosmos client provided by cosmos sdk along with spring data cosmos. Basically, share the same cosmosClient instance. With this, we can use the best of both worlds.

I could not find a way because spring data cosmos expects a bean of cosmosClientBuilder instead of cosmosClient. If it would have been cosmosClient, I could have shared the instance. Any idea on how to achieve this?

You can access Cosmos client directly. To do this, autowire ApplicationContext bean and then use it to get any bean that is created by cosmos client or by spring:

@Autowired
private ApplicationContext applicationContext;

Then in your application, you can do this ->

final CosmosAsyncClient cosmosAsyncClient = applicationContext.getBean(CosmosAsyncClient.class);

One of our unit tests show how to do this: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageableAddressRepositoryIT.java#L153

@arunim29
Copy link

arunim29 commented Dec 1, 2022

@TheovanKraay thanks for a quick reply. I have some follow-up questions :

Any reason why cosmosclient is made private? I am asking because the builder is provided anyways by the application. So, you get all the config from the application. Correct me if I am wrong -> in spring data for relation dbs, spring data takes datasource bean from application and that bean can be used in parallel by the application code as well.

@TheovanKraay
Copy link
Member

@TheovanKraay thanks for a quick reply. I have some follow-up questions :

Any reason why cosmosclient is made private? I am asking because the builder is provided anyways by the application. So, you get all the config from the application. Correct me if I am wrong -> in spring data for relation dbs, spring data takes datasource bean from application and that bean can be used in parallel by the application code as well.

Corrected myself. You can access the client directly. See above.

@TheovanKraay
Copy link
Member

Note: this is only possible for CosmosAsyncClient, because we don't create a bean of CosmosClient.

@arunim29
Copy link

arunim29 commented Dec 1, 2022

@TheovanKraay if u do not create bean of CosmosClient, which cosmos client do you use to support normal crud repositories which are not reactive.

@TheovanKraay
Copy link
Member

@arunim29 non-reactive Repository still uses CosmosAsyncClient behind the scenes, but with blocking calls. CosmosClient is not used by Spring Data Cosmos library.

@arunim29
Copy link

arunim29 commented Dec 2, 2022

@TheovanKraay got it. Thanks for the help.

@TheovanKraay
Copy link
Member

TheovanKraay commented Dec 16, 2022

@arunim29 - as posted in separate issue #32390 - we plan to expose patch something like the below. Let us know if this is not what you expect. Feel free to make suggestions or ask questions here.

CosmosPatchOperations patchOperations = CosmosPatchOperations
    .create()
    .replace("/size", 5)
    .add("/color", "blue");

User patchedUser = userRepository.save(user,patchOperations,null);

@trande4884 trande4884 linked a pull request Dec 16, 2022 that will close this issue
6 tasks
azure-sdk pushed a commit to azure-sdk/azure-sdk-for-java that referenced this issue Jan 4, 2023
Feature/cplat 2022 11 01 (Azure#21571)

* add 2022-11-01 folder

* update readme, update version reference

* Added userData property for PUT Restore Point API

Added user data property for PUT Restore Point API

* Revert "Added userData property for PUT Restore Point API"

This reverts commit 94c96d8ca8586b37a59083efd6357ccf2594dd61.

* Reimage Support for Non-Ephemeral VMs (Azure#21090)

* Reimage support for non-ephemeral VMs

* small changes

* small changes

* resolving issues

* pretty check

* pretty install

* remove package-lock

* remove package-lock

* Added userData property in Restore Point PUT API endpoint (Azure#21262)

* Added userData property in Restore Point PUT Operation

* Update based on review comment

* Updated description

Co-authored-by: Ashwani Tiwari <[email protected]>

* Add OS Image profile to scheduled events profile and maxSurge in rolling upgrade policy in Microsoft.Compute (Azure#21253)

* add reimage notification

* update reimage notification, add max surge

* fix grammar

* Adding requireGuestProvisionSignal and constrainedMaximumCapacity mis… (Azure#21433)

* Adding requireGuestProvisionSignal and constrainedMaximumCapacity missing properties

* Moved the property at the end

Co-authored-by: Avaiyang Garg <[email protected]>

* Add serviceArtifactReference property (Azure#21607)

* Add serviceArtifactReference property

* Moved the property inside the virtualMachineScaleSet file

* Minor change in example

Co-authored-by: Avaiyang Garg <[email protected]>

* add platformFaultDomain in instanceView (Azure#21605)

* add platformFaultDomain in instanceView

* change platformFaultDomain values

* add APIVersionPattern Suppression (Azure#21675)

Co-authored-by: Theodore Chang <[email protected]>

* Adding imageDeprecationStatus properties to VirtualMachineImage response (Azure#21615)

* Changes to virtualMachineImage.json to include ImageDeprecationStatus properties

* Changes to example json

* Fixed LintDiff errors

* Addressed review comment

* Introduce rollbackFailedInstancesOnPolicyBreach in VMSS RollingUpgradePolicy  (Azure#21676)

* add property in compute.json

* add in 2022 file

* add rollbackFailedInstancesOnPolicyBreach in examples

* Revert "add property in compute.json"

This reverts commit 15a1e10503cc4e34b0b69f351cc8f23339002360.

* remove space

Co-authored-by: Sachin Doddaiah Shylaja <[email protected]>
Co-authored-by: Theodore Chang <[email protected]>

* fix spellingCheck error, LintDiff error, model validation, and typo

* fix modelValidation

* model validation

* update headers for examples

* model validation errors

* model validation

* Revert "model validation"

This reverts commit d3810a7866a9093b6ef75a57834e1aaeb4e139f3.

* Revert "model validation errors"

This reverts commit ba34d1b2af2bef58b60c16e9ed1cda00803a2ce0.

* Revert "update headers for examples"

This reverts commit 216b3dc1367655b8c7867a9d7a772fe7e2fa1583.

* Revert "model validation"

This reverts commit 285345656321e984bc99486a575e35a4d3359667.

* Revert "fix modelValidation"

This reverts commit a5fa156d42130566b827df88d6dea4ee591f4a6c.

* Revert "fix spellingCheck error, LintDiff error, model validation, and typo"

This reverts commit 9f60b71000be72bf4511feefcda0820b570345de.

* fix spelling error CI, file name typo, Lint Diff

Co-authored-by: Theodore Chang <[email protected]>
Co-authored-by: Ashwani Tiwari <[email protected]>
Co-authored-by: srcharug <[email protected]>
Co-authored-by: csassasin <[email protected]>
Co-authored-by: John Zhang <[email protected]>
Co-authored-by: avaiyanggarg <[email protected]>
Co-authored-by: Avaiyang Garg <[email protected]>
Co-authored-by: parahluwalia <[email protected]>
Co-authored-by: RajalakshmiSwaminathan <[email protected]>
Co-authored-by: Sachin Doddaiah Shylaja <[email protected]>
Co-authored-by: Sachin Doddaiah Shylaja <[email protected]>
@github-project-automation github-project-automation bot moved this from Todo to Done in Spring Cloud Azure Jan 12, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
azure-spring All azure-spring related issues azure-spring-cosmos Spring cosmos related issues. Client This issue points to a problem in the data-plane of the library. feature-request This issue requires a new behavior in the product in order be resolved.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.