Repository navigation
fix(subscriptions): release advisory locks when the lock connection reconnects on a new session #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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5d1e13e
chore(test): show a subscription keeps running after its lock session…
yordis 493a970
fix(subscriptions): release advisory locks when the lock connection r…
yordis d02d188
chore(test): show lock owners wait for the reconnect to learn their l…
yordis 32ee3fb
fix(subscriptions): tell lock owners their lock is gone as soon as th…
yordis 4872a35
chore(test): show the lock server crashes when the lock connection sw…
yordis 6277431
fix(subscriptions): identify the lock session without reading pg_stat…
yordis ad78c07
chore(test): show a lock connection made before the lock server start…
yordis f28cde1
fix(subscriptions): replace a lock connection made before the lock se…
yordis 37ccc30
chore(test): show a pending unlock is abandoned when its session cann…
yordis f1eac04
fix(subscriptions): retry a pending unlock until a recovered session …
yordis d1d2edf
fix(subscriptions): retry session verification for active locks after…
yordis 62d1356
chore(test): show an active lock is reconciled when a reconnect verif…
yordis 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,4 @@ | ||
| SELECT pg_backend_pid(), COALESCE( | ||
| NULLIF(current_setting('eventstore.session_id', true), ''), | ||
| set_config('eventstore.session_id', md5(random()::text || clock_timestamp()::text), false) | ||
| ); |
7 changes: 7 additions & 0 deletions
7
lib/event_store/sql/statements/try_advisory_session_lock.sql.eex
This file contains hidden or 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,7 @@ | ||
| SELECT pg_try_advisory_lock( | ||
| '"<%= schema %>".subscriptions'::regclass::oid::int, | ||
| (CASE WHEN $1 > 2147483647 THEN mod($1, 2147483647) ELSE $1 END)::int | ||
| ), pg_backend_pid(), COALESCE( | ||
| NULLIF(current_setting('eventstore.session_id', true), ''), | ||
| set_config('eventstore.session_id', md5(random()::text || clock_timestamp()::text), false) | ||
| ); |
This file contains hidden or 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 hidden or 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,26 @@ | ||
| defmodule EventStore.Storage.Session do | ||
| @moduledoc false | ||
|
|
||
| # The id is a session level setting the session sets the first time it is read, | ||
| # because pg_stat_activity hides backend_start from a role switched to with SET ROLE. | ||
|
|
||
| alias EventStore.Sql.Statements | ||
|
|
||
| @type t :: %__MODULE__{backend_pid: pos_integer(), id: String.t()} | ||
|
|
||
| defstruct [:backend_pid, :id] | ||
|
|
||
| def new(backend_pid, id) when is_integer(backend_pid) and is_binary(id) and id != "" do | ||
| %__MODULE__{backend_pid: backend_pid, id: id} | ||
| end | ||
|
|
||
| def current(conn, opts) do | ||
| case Postgrex.query(conn, Statements.query_session(), [], opts) do | ||
| {:ok, %Postgrex.Result{rows: [[backend_pid, id]]}} -> | ||
| {:ok, new(backend_pid, id)} | ||
|
|
||
| {:error, _error} = reply -> | ||
| reply | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.