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

Allow op_type to be set on save methods in (Reactive)ElasticsearchOperations. #2283

Open
frnandu opened this issue Aug 30, 2022 · 4 comments
Labels
type: enhancement A general enhancement

Comments

@frnandu
Copy link
Contributor

frnandu commented Aug 30, 2022

Currently when using repository save operation it will always use op_type index, which doesn't allow to detect concurrent creation of same entity with same generated id (so that if first operation succeed and it creates, the second will fail since it already exists a document with same id).
If I understand correctly usage of seq_no + primary_term is still not possible in the creation phase of the document, only after it is created for subsequent update operations.
Since in ReactiveCrudRepository there isn't a create method which elasticsearch implementation can implement, there should be some way of telling to force creation of entity when using the save method or failing if it already exists.
Without this it seems to me one cannot implement a fully optimistic locking lifecycle for entities/documents which need to have a generated id and concurrency control which avoids creating documents with same id being overwritten. Checking before saving for existence of entity doesn't resolve every scenario when concurrent requests are made.
Do you have any ideas how to resolve this?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 30, 2022
@sothawo
Copy link
Collaborator

sothawo commented Aug 31, 2022

what do you mean with "same generated id"? Who creates this id?****

If I understand correctly usage of seq_no + primary_term is still not possible in the creation phase of the document, only after it is created for subsequent update operations.

Right. Elasticsearch only returns seq_no and primary_term after having indexed a document.

Currently there is no possibility in the save operations of the ReactiveElasticsearchOperations to pass in the op_type.

@sothawo sothawo added the status: waiting-for-feedback We need additional information before we can continue label Aug 31, 2022
@frnandu
Copy link
Contributor Author

frnandu commented Aug 31, 2022

what do you mean with "same generated id"? Who creates this id?****

I mean composite id using few fields from an entity (ex: Vote which is identified by concatenating entity_name + user_id + entity_id).
If concurrently requests are made to create such a Vote with same field values (which result in same generated id), there is no way of optimistic locking versioning to detect if a vote already was created and written on ES successfully or not, and subsequently be able to accordingly publish a messaging queue event of CREATE or UPDATE.

Currently there is no possibility in the save operations of the ReactiveElasticsearchOperations to pass in the op_type.

Could it be added such possibility easily?

Thanks

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 31, 2022
@sothawo sothawo changed the title Support optimistic locking for creating new document with existing id using op_type create Allow op_type to be set on save methods in (Reactive)ElasticsearchOperations. Sep 2, 2022
@sothawo sothawo added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 2, 2022
@sothawo
Copy link
Collaborator

sothawo commented Sep 2, 2022

That won't be too hard, it means to add new overloaded versions of save to the (Reactive)DocumentOperations interface and to implement these.

@sothawo
Copy link
Collaborator

sothawo commented Sep 4, 2022

see #2089 as well

@sothawo sothawo removed the status: feedback-provided Feedback has been provided label Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants