Skip to content

How do I use retry_on_conflict to resolve error "ConflictError 409" with update()? #1326

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

Closed
erichaus opened this issue Mar 13, 2020 · 7 comments

Comments

@erichaus
Copy link

erichaus commented Mar 13, 2020

I noticed that if I send too many requests in a short period, my elasticsearch update code throws a 409 ConflictError. Reading a bit into it, I noticed there is a param for update() to set the number of retry attempts, however when I tried using it, I get another error:

RequestError(400, 'action_request_validation_exception', 'Validation Failed: 1: compare and write operations can not be retried;')

How can I handle 409 ConflictError during frequent updates and/or use the retry_on_conflict param?

    thing = Thing.get(id=thing_id, ignore=404)

    if thing:
            return post.update(
                script=update_func,
                refresh=True,
                retry_on_conflict=ES_UPDATE_RETRY_COUNT,
                now=arrow.utcnow().float_timestamp,
            )
ConflictError: ConflictError(409, 'version_conflict_engine_exception', '[TtWP-la58FPHbw]: version conflict, required seqNo [8], primary term [1]. current document has seqNo [9] and primary term [1]')
(2 additional frame(s) were not displaye
@erichaus
Copy link
Author

using elasticsearch-py directly seems to work...

            return post._get_connection().update(
                Post.Index().name,
                post_id,
                body,
                refresh=True,
                retry_on_conflict=10,
            )

@549982170
Copy link

I have the same problem.

@smurf-U
Copy link

smurf-U commented Oct 29, 2020

I have the same problem.

Any update?

after adding retry_on_conflict I'm getting below one RequestError(400, 'action_request_validation_exception', 'Validation Failed: 1: compare and write operations can not be retried;')

Any soulution?

@erichaus
Copy link
Author

@smurf-U I ended up using above solution

@smurf-U
Copy link

smurf-U commented Oct 30, 2020

Hi @burritoIand
Thanks for reply.
Then how did you handle this scenario?

@erichaus
Copy link
Author

@smurf-U

post.update(
                script=update_func,
                refresh=True,
                retry_on_conflict=ES_UPDATE_RETRY_COUNT,
                now=arrow.utcnow().float_timestamp,
            )

@ryonakamura
Copy link

This error seems to occur when adding if_seq_no and if_primary_term to the update arguments.

https://github.com/elastic/elasticsearch-dsl-py/blob/7.3.0/elasticsearch_dsl/document.py#L407

Here's a temporary solution:

del post.meta['seq_no']
del post.meta['primary_term']
post.update(
    retry_on_conflict=10,
    date=datetime.utcnow(),
)

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

No branches or pull requests

4 participants