-
Notifications
You must be signed in to change notification settings - Fork 42
zodan.sql - add subscription health check (Spoc 294). #266
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| use strict; | ||
| use warnings; | ||
| use Test::More; | ||
| use lib '.'; | ||
| use lib 't'; | ||
| use SpockTest qw(create_cluster destroy_cluster get_test_config psql_or_bail scalar_query); | ||
|
|
||
| my ($result); | ||
|
|
||
| create_cluster(3, 'Create basic Spock test cluster'); | ||
|
|
||
| # Get cluster configuration | ||
| my $config = get_test_config(); | ||
| my $node_count = $config->{node_count}; | ||
| my $node_ports = $config->{node_ports}; | ||
| my $host = $config->{host}; | ||
| my $dbname = $config->{db_name}; | ||
| my $db_user = $config->{db_user}; | ||
| my $db_password = $config->{db_password}; | ||
| my $pg_bin = $config->{pg_bin}; | ||
|
|
||
| psql_or_bail(2, "SELECT spock.node_drop('n2')"); | ||
| psql_or_bail(3, "SELECT spock.node_drop('n3')"); | ||
| psql_or_bail(1, "CREATE EXTENSION amcheck"); | ||
| psql_or_bail(2, "CREATE EXTENSION dblink"); | ||
| psql_or_bail(3, "CREATE EXTENSION dblink"); | ||
| psql_or_bail(2, "\\i ../../samples/Z0DAN/zodan.sql"); | ||
| psql_or_bail(3, "\\i ../../samples/Z0DAN/zodan.sql"); | ||
| psql_or_bail(1, "CREATE TABLE test(x serial PRIMARY KEY)"); | ||
| psql_or_bail(1, "INSERT INTO test DEFAULT VALUES"); | ||
|
|
||
| print STDERR "All supporting stuff has been installed successfully\n"; | ||
|
|
||
| # ############################################################################## | ||
| # | ||
| # Basic check that Z0DAN correctly add node to the single-node cluster | ||
| # | ||
| # ############################################################################## | ||
|
|
||
| print STDERR "Call Z0DAN: n2 => n1\n"; | ||
| psql_or_bail(2, " | ||
| CALL spock.add_node( | ||
| src_node_name := 'n1', | ||
| src_dsn := 'host=$host dbname=$dbname port=$node_ports->[0] user=$db_user password=$db_password', | ||
| new_node_name := 'n2', | ||
| new_node_dsn := 'host=$host dbname=$dbname port=$node_ports->[1] user=$db_user password=$db_password', | ||
| verb := false | ||
| )"); | ||
| print STDERR "Z0DAN (n2 => n1) has finished the attach process\n"; | ||
| $result = scalar_query(2, "SELECT x FROM test"); | ||
| print STDERR "Check result: $result\n"; | ||
| ok($result eq '1', "Check state of the test table after the attachment"); | ||
|
|
||
| psql_or_bail(1, "SELECT spock.sub_disable('sub_n1_n2')"); | ||
|
|
||
| # ############################################################################## | ||
| # | ||
| # Z0DAN reject node addition if some subscriptions are disabled | ||
| # | ||
| # ############################################################################## | ||
|
|
||
| print STDERR "Call Z0DAN: n3 => n2\n"; | ||
| scalar_query(3, " | ||
| CALL spock.add_node( | ||
| src_node_name := 'n2', | ||
| src_dsn := 'host=$host dbname=$dbname port=$node_ports->[1] user=$db_user password=$db_password', | ||
| new_node_name := 'n3', new_node_dsn := 'host=$host dbname=$dbname port=$node_ports->[2] user=$db_user password=$db_password', | ||
| verb := false)"); | ||
|
|
||
| $result = scalar_query(3, "SELECT count(*) FROM spock.local_node"); | ||
| ok($result eq '0', "N3 is not in the cluster yet"); | ||
| print STDERR "Z0DAN should fail because of a disabled subscription\n"; | ||
|
|
||
| psql_or_bail(1, "SELECT spock.sub_enable('sub_n1_n2')"); | ||
| psql_or_bail(3, " | ||
| CALL spock.add_node( | ||
| src_node_name := 'n2', | ||
| src_dsn := 'host=$host dbname=$dbname port=$node_ports->[1] user=$db_user password=$db_password', | ||
| new_node_name := 'n3', new_node_dsn := 'host=$host dbname=$dbname port=$node_ports->[2] user=$db_user password=$db_password', | ||
| verb := true)"); | ||
|
|
||
| $result = scalar_query(3, "SELECT count(*) FROM spock.local_node"); | ||
| ok($result eq '1', "N3 is in the cluster"); | ||
| $result = scalar_query(3, "SELECT x FROM test"); | ||
| print STDERR "Check result: $result\n"; | ||
| ok($result eq '1', "Check state of the test table on N3 after the attachment"); | ||
| print STDERR "Z0DAN should add N3 to the cluster\n"; | ||
|
|
||
| # ############################################################################## | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the reason?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reason for what exactly?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Do you mean, reason for a new test or some check inside? |
||
| # | ||
| # Test that Z0DAN correctly doesn't add node to the cluster if something happens | ||
| # during the SYNC process. | ||
| # | ||
| # ############################################################################## | ||
|
|
||
| # Remove node from the cluster and data leftovers. | ||
| psql_or_bail(3, "\\i ../../samples/Z0DAN/zodremove.sql"); | ||
| psql_or_bail(3, "CALL spock.remove_node(target_node_name := 'n3', | ||
| target_node_dsn := 'host=$host dbname=$dbname port=$node_ports->[2] user=$db_user password=$db_password', | ||
| verbose_mode := true)"); | ||
| psql_or_bail(3, "DROP TABLE test"); | ||
|
|
||
| psql_or_bail(1, "CREATE FUNCTION fake_fn() RETURNS integer LANGUAGE sql AS \$\$ SELECT 1\$\$"); | ||
| psql_or_bail(3, "CREATE FUNCTION fake_fn() RETURNS integer LANGUAGE sql AS \$\$ SELECT 1\$\$"); | ||
| scalar_query(3, " | ||
| CALL spock.add_node( | ||
| src_node_name := 'n2', | ||
| src_dsn := 'host=$host dbname=$dbname port=$node_ports->[1] user=$db_user password=$db_password', | ||
| new_node_name := 'n3', new_node_dsn := 'host=$host dbname=$dbname port=$node_ports->[2] user=$db_user password=$db_password', | ||
| verb := true)"); | ||
|
|
||
| # TODO: | ||
| # It seems that add_node keeps remnants after unsuccessful execution. It is | ||
| # happened because we have commited some intermediate results before. | ||
| # It would be better to keep remote transaction opened until the end of the | ||
| # operation or just remove these remnants at the end pretending to be a | ||
| # distributed transaction. | ||
| # | ||
| # $result = scalar_query(3, "SELECT count(*) FROM spock.local_node"); | ||
| # ok($result eq '0', "N3 is not in the cluster"); | ||
|
|
||
| # Clean up | ||
| destroy_cluster('Destroy test cluster'); | ||
| done_testing(); | ||
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.
What is reason to change that?
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.
It is just because of boring complain in the log. We assign this GUC in terms of megabytes, so we need to declare units and proper limits too.