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

Lock state.block table when performing non-atomic read/write #85

Merged
merged 1 commit into from
Oct 10, 2023

Conversation

jbearer
Copy link
Member

@jbearer jbearer commented Oct 9, 2023

This should prevent the duplicate key errors we have seen in production from the preconfirmations node, which runs two simultaneous tasks that both update the blocks table.

This should prevent the duplicate key errors we have seen in
production from the preconfirmations node, which runs two
simultaneous tasks that both update the blocks table.
// already exists) and modify it. These two actions do not happen atomically; without
// protection, another transaction may complete and modify the state.block table in between.
// Thus, we first need to acquire a lock that prevents concurrent updates to the table.
if _, err := e.Exec(ctx, "LOCK TABLE state.block IN EXCLUSIVE MODE"); err != nil {
Copy link
Contributor

@nomaxg nomaxg Oct 9, 2023

Choose a reason for hiding this comment

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

What is the scope of the client session? Just wondering if we need to unlock explicitly

Copy link
Member Author

Choose a reason for hiding this comment

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

Postgres has no explicit unlock command. All locks are dropped when the transaction is committed or rolled back

Copy link
Member Author

Choose a reason for hiding this comment

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

@nomaxg nomaxg self-requested a review October 9, 2023 15:48
@jbearer jbearer merged commit cc393ab into hotshot-integration Oct 10, 2023
2 checks passed
@jbearer jbearer deleted the fix/lock-blocks branch October 10, 2023 13:06
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

Successfully merging this pull request may close these issues.

2 participants