-
Notifications
You must be signed in to change notification settings - Fork 24
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
Support for different lock modes #88
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
73e86eb
Support for different lock modes
rkrage 0e4509a
fixup logging
rkrage 3bf3d16
minor refactor
rkrage 2cdce20
make lock mode tests more explicit
rkrage 16b8054
only block on conflicting lock modes
rkrage 7b2b88d
more tests
rkrage 63e8016
only override ==
rkrage c44fe17
cleanup
rkrage 16d42f4
use gsub instead of split + join for lock mode sql
rkrage 8f105f3
code review comments
rkrage e28ed66
minor cleanup
rkrage 742a4e9
s/targeted_table/target_table
rkrage 97c4488
remove unneeded setter on relation struct
rkrage a7566f3
Update readme with example
rkrage 398c30e
attempt to fix flaky tests
rkrage 3038d44
more re-entrancy tests / expectations
rkrage ccfe1d2
remove inspect delegation in lock mode
rkrage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
module PgHaMigrations | ||
class LockMode | ||
include Comparable | ||
|
||
MODE_CONFLICTS = ActiveSupport::OrderedHash.new | ||
|
||
MODE_CONFLICTS[:access_share] = %i[ | ||
access_exclusive | ||
] | ||
|
||
MODE_CONFLICTS[:row_share] = %i[ | ||
exclusive | ||
access_exclusive | ||
] | ||
|
||
MODE_CONFLICTS[:row_exclusive] = %i[ | ||
share | ||
share_row_exclusive | ||
exclusive | ||
access_exclusive | ||
] | ||
|
||
MODE_CONFLICTS[:share_update_exclusive] = %i[ | ||
share_update_exclusive | ||
share | ||
share_row_exclusive | ||
exclusive | ||
access_exclusive | ||
] | ||
|
||
MODE_CONFLICTS[:share] = %i[ | ||
row_exclusive | ||
share_update_exclusive | ||
share_row_exclusive | ||
exclusive | ||
access_exclusive | ||
] | ||
|
||
MODE_CONFLICTS[:share_row_exclusive] = %i[ | ||
row_exclusive | ||
share_update_exclusive | ||
share | ||
share_row_exclusive | ||
exclusive | ||
access_exclusive | ||
] | ||
|
||
MODE_CONFLICTS[:exclusive] = %i[ | ||
row_share | ||
row_exclusive | ||
share_update_exclusive | ||
share | ||
share_row_exclusive | ||
exclusive | ||
access_exclusive | ||
] | ||
|
||
MODE_CONFLICTS[:access_exclusive] = %i[ | ||
access_share | ||
row_share | ||
row_exclusive | ||
share_update_exclusive | ||
share | ||
share_row_exclusive | ||
exclusive | ||
access_exclusive | ||
] | ||
|
||
attr_reader :mode | ||
|
||
delegate :to_s, to: :mode | ||
|
||
def initialize(mode) | ||
@mode = mode | ||
.to_s | ||
.underscore | ||
.delete_suffix("_lock") | ||
.to_sym | ||
|
||
if !MODE_CONFLICTS.keys.include?(@mode) | ||
raise ArgumentError, "Unrecognized lock mode #{@mode.inspect}. Valid modes: #{MODE_CONFLICTS.keys}" | ||
end | ||
end | ||
|
||
def to_sql | ||
mode | ||
.to_s | ||
.upcase | ||
.gsub("_", " ") | ||
end | ||
|
||
def <=>(other) | ||
MODE_CONFLICTS.keys.index(mode) <=> MODE_CONFLICTS.keys.index(other.mode) | ||
end | ||
|
||
def conflicts_with?(other) | ||
MODE_CONFLICTS[mode].include?(other.mode) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lock conflicts pulled from this table: https://www.postgresql.org/docs/current/explicit-locking.html#TABLE-LOCK-COMPATIBILITY