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

Send advisory lock requests to the master #198

Merged
merged 1 commit into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def custom_error_message?(connection, message)
hijack_method :execute, :select_rows, :exec_query, :transaction
send_to_all :connect, :reconnect!, :verify!, :clear_cache!, :reset!

SQL_MASTER_MATCHERS = [/\A\s*select.+for update\Z/i, /select.+lock in share mode\Z/i, /\A\s*select.+(nextval|currval|lastval)\(/i].map(&:freeze).freeze
SQL_MASTER_MATCHERS = [/\A\s*select.+for update\Z/i, /select.+lock in share mode\Z/i, /\A\s*select.+(nextval|currval|lastval|get_lock|release_lock|pg_advisory_lock|pg_advisory_unlock)\(/i].map(&:freeze).freeze
SQL_SLAVE_MATCHERS = [/\A\s*(select|with.+\)\s*select)\s/i].map(&:freeze).freeze
SQL_ALL_MATCHERS = [/\A\s*set\s/i].map(&:freeze).freeze
SQL_SKIP_STICKINESS_MATCHERS = [/\A\s*show\s([\w]+\s)?(field|table|database|schema|view|index)(es|s)?/i, /\A\s*(set|describe|explain|pragma)\s/i].map(&:freeze).freeze
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
'select currval(\'users_id_seq\')' => true,
'select lastval()' => true,
'with fence as (select * from users) select * from fence' => false,
'with fence as (select * from felines) insert to cats' => true
'with fence as (select * from felines) insert to cats' => true,
'select get_lock(\'foo\', 0)' => true,
'select release_lock(\'foo\')' => true,
'select pg_advisory_lock(12345)' => true,
'select pg_advisory_unlock(12345)' => true
}.each do |sql, should_go_to_master|

it "determines that \"#{sql}\" #{should_go_to_master ? 'requires' : 'does not require'} master" do
Expand Down