0

I'm looking for the way to enable Optimistic locking for Firestore DB document, but seems @Version annotation doesn't work.

Currently I'm using spring-cloud-gcp-starter-data-firestore lib for extending FirestoreReactiveRepository interface repository. I've looked through the spring cloud gcp documentation and found nothing about optimistic locking and data versioning(using for example document's modificatioNumber field).

My be someone knows are there any way to enable, declaratively (using some annotations) or programmatically, optimistic locking for Firestore DB documents using spring libs or some other libs? Thanks.

Dustin Ingram
  • 20,502
  • 7
  • 59
  • 82
  • The best place to ask this question is on Spring Cloud GCP GitHub repo issue tracker: https://github.com/spring-cloud/spring-cloud-gcp/issues – Mike E. Aug 21 '20 at 18:27
  • Added a FR issue: https://github.com/spring-cloud/spring-cloud-gcp/issues/2498 PTAL. – saturnism Aug 24 '20 at 18:38

1 Answers1

0

I believe its built in and there is no need to enable it. (unless I am missing something) Firestore in Datastore mode transactions have a built-in optimistic locking, You can configure the transaction in order that, if the transaction fails (the data was already modified, for example) you can rollback the changes. You can read more about the transactions and how to use it in here

You can refer to the confirmation that Datastore’s transactions use “optimistic locking” on this StackOverflow post

Andres S
  • 1,168
  • 7
  • 11