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

Introduce the ability to kill competing transactions that hold exclusive lock during swap #23

Merged
merged 1 commit into from
Feb 6, 2022

Conversation

shayonj
Copy link
Owner

@shayonj shayonj commented Feb 6, 2022

This introduces wait_time_for_lock and kill_backends as new flags.
By default pgosc won't kill any backends if it cannot acquire an
AccessExclusiveLock to perform the swap. It will retry upto 3 times
and for the duration specified in wait_time_for_lock (default: 10s).
So, in total 30s. Configurable. If kill_backends/kill-backend
is set to true (supplied), then it will kill the backend on each try
it couldn't acquire the lock, upto 3 times before exiting. Though,
after killing the backends after 1st attempt should work.

Specs added. A bit messy for now. Refactor in the end

closes #16

def lock_exclusive(client, table)
attempts ||= 1

client.connection.async_exec("SET lock_timeout = '#{client.wait_time_for_lock}s'; BEGIN;")
Copy link
Owner Author

Choose a reason for hiding this comment

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

it sets a lock_timeout which matches client.wait_time_for_lock. we use this ability for retries since on failure to acquire the lock PG::LockNotAvailable/PG::InFailedSqlTransaction is raised

…ive lock during swap

This introduces wait_time_for_lock and kill_backends as new flags.
By default pgosc won't kill any backends if it cannot acquire an
exclusive lock to perform the swap. It will retry upto 3 times
and for the duration specified in wait_time_for_lock (default: 10s).
So, in total 30s. Configurable. If kill_backends/kill-backend
is set to true (supplied), then it will kill the backend on each try
it couldn't acquire the lock, upto 3 times before exiting. Though,
after killing the backends after 1st attempt should work.

Specs added. A bit messy for now. Refactor in the end
@shayonj shayonj merged commit fbd479f into main Feb 6, 2022
@shayonj shayonj deleted the s/locks-backend branch February 6, 2022 21:52
@shayonj shayonj mentioned this pull request Feb 7, 2022
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.

Look into lock_timeout
1 participant