Repository navigation
fix(subscriptions): keep a failed catch-up read visible, single and short, and correct the PgBouncer guide #116
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
15 commits
Select commit
Hold shift + click to select a range
745e13d
test(subscriptions): catch the lock error clause and catch-up retry m…
yordis a1933c1
test(subscriptions): keep a single catch-up retry pending while in-fl…
yordis 4e1cd3c
fix(subscriptions): keep one catch-up retry pending when events are a…
yordis aa642bd
test(subscriptions): log why a catch-up read failed
yordis b94534b
fix(subscriptions): log why a catch-up read failed and when it will r…
yordis 493fa04
test(subscriptions): read again on a catch-up request or new events i…
yordis 30ca64a
fix(subscriptions): read again on a catch-up request or new events in…
yordis 1a7043f
docs(cluster): say PgBouncer's reset query releases a dead node's loc…
yordis 0a86462
test(subscriptions): run the lock refusal test on PostgreSQL 12 and m…
yordis 36f3a06
test(subscriptions): ignore a retry that was already due when an earl…
yordis e30df74
fix(subscriptions): ignore a retry that was already due when an early…
yordis 5902247
docs(cluster): link the PgBouncer section so it resolves on HexDocs, …
yordis 327f245
test(subscriptions): drop the pending catch-up retry when the subscri…
yordis f3f7a89
fix(subscriptions): drop the pending catch-up retry when the subscrip…
yordis ea96143
test(storage): wait for the lock test's sessions to end before droppi…
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
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,82 @@ | ||
| defmodule EventStore.Storage.SubscriptionLockRefusedTest do | ||
| use EventStore.StorageCase | ||
|
|
||
| alias EventStore.Storage.Lock | ||
|
|
||
| @database "eventstore_test_xact_lock_denied" | ||
| @role "eventstore_xact_lock_denied" | ||
|
|
||
| setup %{conn: conn, postgrex_config: postgrex_config} do | ||
| drop = fn -> | ||
| # DROP DATABASE ... WITH (FORCE) needs PostgreSQL 13, so end the sessions first. | ||
| Postgrex.query!( | ||
| conn, | ||
| "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = $1", | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| [@database] | ||
| ) | ||
|
|
||
| # Sessions end asynchronously and the drop waits only five seconds for them. | ||
| await_no_sessions(conn, 100) | ||
|
|
||
| Postgrex.query!(conn, ~s|DROP DATABASE IF EXISTS "#{@database}"|, []) | ||
| Postgrex.query!(conn, ~s|DROP ROLE IF EXISTS "#{@role}"|, []) | ||
| end | ||
|
|
||
| drop.() | ||
| on_exit(fn -> drop.() end) | ||
|
|
||
| Postgrex.query!(conn, ~s|CREATE ROLE "#{@role}" LOGIN PASSWORD 'secret'|, []) | ||
| Postgrex.query!(conn, ~s|CREATE DATABASE "#{@database}" TEMPLATE template0|, []) | ||
|
|
||
| {:ok, admin} = Postgrex.start_link(Keyword.put(postgrex_config, :database, @database)) | ||
|
|
||
| Postgrex.query!( | ||
| admin, | ||
| "CREATE TABLE public.subscriptions (subscription_id bigint PRIMARY KEY, " <> | ||
| "lock_generation bigint NOT NULL DEFAULT 0, last_seen bigint)", | ||
| [] | ||
| ) | ||
|
|
||
| Postgrex.query!(admin, "INSERT INTO public.subscriptions (subscription_id) VALUES (1)", []) | ||
| Postgrex.query!(admin, ~s|GRANT SELECT, UPDATE ON public.subscriptions TO "#{@role}"|, []) | ||
|
|
||
| Postgrex.query!( | ||
| admin, | ||
| "REVOKE EXECUTE ON FUNCTION pg_catalog.pg_try_advisory_xact_lock(integer, integer) FROM PUBLIC", | ||
| [] | ||
| ) | ||
|
|
||
| GenServer.stop(admin) | ||
|
|
||
| role_config = | ||
| Keyword.merge(postgrex_config, database: @database, username: @role, password: "secret") | ||
|
|
||
| [role_conn: start_supervised!({Postgrex, role_config}, id: :role_conn)] | ||
| end | ||
|
|
||
| test "a claim returns the error when only the advisory lock statement is refused", context do | ||
| assert {:error, %Postgrex.Error{postgres: %{code: :insufficient_privilege} = postgres}} = | ||
| Lock.claim_subscription_lock(context.role_conn, 1, schema: "public") | ||
|
|
||
| assert postgres.message =~ "pg_try_advisory_xact_lock" | ||
| end | ||
|
|
||
| defp await_no_sessions(conn, attempts) do | ||
| %Postgrex.Result{rows: [[sessions]]} = | ||
| Postgrex.query!(conn, "SELECT count(*) FROM pg_stat_activity WHERE datname = $1", [ | ||
| @database | ||
| ]) | ||
|
|
||
| cond do | ||
| sessions == 0 -> | ||
| :ok | ||
|
|
||
| attempts > 0 -> | ||
| Process.sleep(100) | ||
| await_no_sessions(conn, attempts - 1) | ||
|
|
||
| true -> | ||
| flunk("#{sessions} sessions on #{@database} did not end") | ||
| end | ||
| end | ||
| end | ||
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.