-
Notifications
You must be signed in to change notification settings - Fork 48
Make heap apply retry loop configurable via spock.read_retry_count #475
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
Open
ibrarahmad
wants to merge
1
commit into
main
Choose a base branch
from
SPOC-553
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+155
−2
Open
Changes from all commits
Commits
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,130 @@ | ||
| use strict; | ||
| use warnings; | ||
| use Test::More; | ||
| use lib '.'; | ||
| use lib 't'; | ||
| use SpockTest qw( | ||
| create_cluster destroy_cluster | ||
| get_test_config system_or_bail | ||
| psql_or_bail scalar_query | ||
| ); | ||
|
|
||
| # ============================================================================= | ||
| # Test: 030_read_retry_count_guc.pl | ||
| # | ||
| # Verifies the spock.read_retry_count GUC: | ||
| # 1. is registered with the expected default (5) | ||
| # 2. is read by the apply path on each iteration via SHOW | ||
| # 3. accepts ALTER SYSTEM SET + pg_reload_conf() updates at runtime | ||
| # 4. rejects values outside the documented [0, 100] range | ||
| # | ||
| # The GUC controls the retry loop in spock_apply_heap_update() and | ||
| # spock_apply_heap_delete() — the apply worker re-reads the local | ||
| # relation up to spock.read_retry_count times when a row targeted by a | ||
| # remote UPDATE/DELETE is not yet visible locally. | ||
| # ============================================================================= | ||
|
|
||
| create_cluster(2, 'Create 2-node Spock cluster for read_retry_count GUC'); | ||
|
|
||
| my $config = get_test_config(); | ||
| my $host = $config->{host}; | ||
| my $primary_port = $config->{node_ports}->[0]; | ||
|
|
||
| # ----------------------------------------------------------------------------- | ||
| # 1. Default value is 5 | ||
| # ----------------------------------------------------------------------------- | ||
| my $default = scalar_query(1, "SHOW spock.read_retry_count"); | ||
| $default =~ s/\s+//g; | ||
| is($default, '5', | ||
| "spock.read_retry_count default is 5 (matches prior hardcoded behaviour)"); | ||
|
|
||
| # ----------------------------------------------------------------------------- | ||
| # 2. The GUC is reported in pg_settings with the expected metadata | ||
| # ----------------------------------------------------------------------------- | ||
| my $context = scalar_query(1, | ||
| "SELECT context FROM pg_settings WHERE name = 'spock.read_retry_count'"); | ||
| $context =~ s/\s+//g; | ||
| is($context, 'sighup', | ||
| "spock.read_retry_count GUC context is PGC_SIGHUP (settable via reload)"); | ||
|
|
||
| my $unit = scalar_query(1, | ||
| "SELECT coalesce(unit::text, '') FROM pg_settings WHERE name = 'spock.read_retry_count'"); | ||
| $unit =~ s/\s+//g; | ||
| is($unit, '', | ||
| "spock.read_retry_count is unit-less (raw retry count, not a time/size)"); | ||
|
|
||
| my $min = scalar_query(1, | ||
| "SELECT min_val FROM pg_settings WHERE name = 'spock.read_retry_count'"); | ||
| $min =~ s/\s+//g; | ||
| is($min, '0', "spock.read_retry_count min_val is 0"); | ||
|
|
||
| my $max = scalar_query(1, | ||
| "SELECT max_val FROM pg_settings WHERE name = 'spock.read_retry_count'"); | ||
| $max =~ s/\s+//g; | ||
| is($max, '100', "spock.read_retry_count max_val is 100"); | ||
|
|
||
| # ----------------------------------------------------------------------------- | ||
| # 3. ALTER SYSTEM SET + pg_reload_conf() takes effect at runtime | ||
| # ----------------------------------------------------------------------------- | ||
| psql_or_bail(1, "ALTER SYSTEM SET spock.read_retry_count = 10"); | ||
| psql_or_bail(1, "SELECT pg_reload_conf()"); | ||
|
|
||
| # Open a fresh psql session (the SIGHUP needs a new backend to pick up the | ||
| # value from the postmaster). scalar_query opens a new connection each call. | ||
| sleep(1); | ||
| my $after_set = scalar_query(1, "SHOW spock.read_retry_count"); | ||
| $after_set =~ s/\s+//g; | ||
| is($after_set, '10', | ||
| "spock.read_retry_count picks up new value (10) after ALTER SYSTEM + reload"); | ||
|
|
||
| # Reset to default | ||
| psql_or_bail(1, "ALTER SYSTEM RESET spock.read_retry_count"); | ||
| psql_or_bail(1, "SELECT pg_reload_conf()"); | ||
| sleep(1); | ||
| my $after_reset = scalar_query(1, "SHOW spock.read_retry_count"); | ||
| $after_reset =~ s/\s+//g; | ||
| is($after_reset, '5', | ||
| "spock.read_retry_count returns to default (5) after ALTER SYSTEM RESET"); | ||
|
|
||
| # ----------------------------------------------------------------------------- | ||
| # 4. Out-of-range values are rejected | ||
| # ----------------------------------------------------------------------------- | ||
| # Use system() so we can check the exit code without psql_or_bail dying. | ||
| my $pg_bin = $config->{pg_bin}; | ||
| my $dbname = $config->{db_name}; | ||
| my $db_user = $config->{db_user}; | ||
|
|
||
| my $rc_neg = system( | ||
| "$pg_bin/psql -X -h $host -p $primary_port -d $dbname -U $db_user " | ||
| . "-v ON_ERROR_STOP=1 " | ||
| . "-c \"ALTER SYSTEM SET spock.read_retry_count = -1\" " | ||
| . ">/dev/null 2>&1"); | ||
| isnt($rc_neg, 0, "spock.read_retry_count rejects value below 0 (-1)"); | ||
|
|
||
| my $rc_hi = system( | ||
| "$pg_bin/psql -X -h $host -p $primary_port -d $dbname -U $db_user " | ||
| . "-v ON_ERROR_STOP=1 " | ||
| . "-c \"ALTER SYSTEM SET spock.read_retry_count = 101\" " | ||
| . ">/dev/null 2>&1"); | ||
| isnt($rc_hi, 0, "spock.read_retry_count rejects value above 100 (101)"); | ||
|
|
||
| # Boundary values must succeed | ||
| my $rc_zero = system( | ||
| "$pg_bin/psql -X -h $host -p $primary_port -d $dbname -U $db_user " | ||
| . "-v ON_ERROR_STOP=1 " | ||
| . "-c \"ALTER SYSTEM SET spock.read_retry_count = 0\" " | ||
| . ">/dev/null 2>&1"); | ||
| is($rc_zero, 0, "spock.read_retry_count accepts the lower boundary (0)"); | ||
|
|
||
| my $rc_max = system( | ||
| "$pg_bin/psql -X -h $host -p $primary_port -d $dbname -U $db_user " | ||
| . "-v ON_ERROR_STOP=1 " | ||
| . "-c \"ALTER SYSTEM SET spock.read_retry_count = 100\" " | ||
| . ">/dev/null 2>&1"); | ||
| is($rc_max, 0, "spock.read_retry_count accepts the upper boundary (100)"); | ||
|
|
||
| # Cleanup so the destroy_cluster restart leaves no residue | ||
| psql_or_bail(1, "ALTER SYSTEM RESET spock.read_retry_count"); | ||
|
|
||
| destroy_cluster('Destroy test cluster'); | ||
| done_testing(); |
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.
This is a little bit too verbose, no need to mention which functions. Can you please shorten? Something like the first 4 lines and the "Set to 0" sentence?