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

Safely acquire lock on multiple tables #100

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

rkrage
Copy link
Contributor

@rkrage rkrage commented Jun 5, 2024

This functionality will allow us to improve the safety of operations that take out locks on multiple tables (e.g. adding / removing foreign keys).

I also discovered a bug in the nested lock acquisition logic, so this PR fixes that and adds more tests.

I feel like it's tradition at this point for me to include too many changes in a PR and for @jcoleman to ask me to break it up into smaller commits 😆 (I will try to do that tomorrow done).

@rkrage rkrage force-pushed the multi-table-locks branch 3 times, most recently from 9541a0a to c9fdfaa Compare June 7, 2024 14:33
@rkrage rkrage force-pushed the multi-table-locks branch 8 times, most recently from 4142ddb to 2cfa43d Compare June 20, 2024 12:33
@rkrage rkrage force-pushed the multi-table-locks branch 2 times, most recently from d159713 to 0660b33 Compare July 10, 2024 15:34
@rkrage rkrage force-pushed the multi-table-locks branch from 0660b33 to b956bc5 Compare March 5, 2025 18:04
@rkrage rkrage changed the base branch from master to add-safe-make-column-not-nullable March 5, 2025 18:05
@rkrage rkrage force-pushed the multi-table-locks branch 3 times, most recently from 953b0a5 to ef38a88 Compare March 5, 2025 23:05
Base automatically changed from add-safe-make-column-not-nullable to master March 6, 2025 19:06
@rkrage rkrage force-pushed the multi-table-locks branch from ef38a88 to c2e3775 Compare March 6, 2025 19:09
@rkrage rkrage force-pushed the multi-table-locks branch from c2e3775 to da6cced Compare March 6, 2025 19:19

until successfully_acquired_lock
while (
loop do
# If in a nested context and all of the above checks have passed,
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this effectively mean that if parent_lock_tables is present we could set successfully_acquired_lock to true earlier and not need this break?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems related to your previous comment:

Do we simply skip lock acquisition (as a query, I mean) in that case since we track what we've locked?

Are you suggesting we could short-circuit in a nested lock scenario and just execute the block that was passed in?

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems related to your previous comment:

I should have clarified what I was continuing the conversation on; it was this one: #100 (comment)

attr_reader :raw_set

delegate :each, to: :raw_set
delegate :mode, to: :first, allow_nil: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Can there never be different modes on the different tables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the ways we are currently interacting with this collection, no. I can probably enforce that in the initializer if you'd like to be a bit more defensive. The only downside is more work for me 😆 . Adding a guard like that would require dedicated unit tests (we exercise these classes currently via functional tests of the methods that use them).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's probably worth being defensive if it's not that difficult.

Copy link
Contributor

@jcoleman jcoleman left a comment

Choose a reason for hiding this comment

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

There's one outstanding comment thread, but I trust you to finish that, so approving now.

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.

3 participants