|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | +use PostgresNode; |
| 4 | +use TestLib; |
| 5 | +use Test::More tests => 2; |
| 6 | +use DBI; |
| 7 | +use DBD::Pg ':async'; |
| 8 | + |
| 9 | +############################################################################### |
| 10 | +# Aux routines |
| 11 | +############################################################################### |
| 12 | + |
| 13 | +sub PostgresNode::inet_connstr { |
| 14 | + my ($self, $dbname) = @_; |
| 15 | + my $pgport = $self->port; |
| 16 | + my $pghost = '127.0.0.1'; |
| 17 | + my $pgdata = $self->data_dir; |
| 18 | + |
| 19 | + if (!defined($dbname)) |
| 20 | + { |
| 21 | + return "port=$pgport host=$pghost"; |
| 22 | + } |
| 23 | + return "port=$pgport host=$pghost dbname=$dbname"; |
| 24 | +} |
| 25 | + |
| 26 | +############################################################################### |
| 27 | +# Setup nodes |
| 28 | +############################################################################### |
| 29 | + |
| 30 | +my $nnodes = 3; |
| 31 | +my @nodes = (); |
| 32 | +my $pgconf_common = qq( |
| 33 | + listen_addresses = '127.0.0.1' |
| 34 | + max_prepared_transactions = 10 |
| 35 | + max_worker_processes = 10 |
| 36 | + max_wal_senders = 10 |
| 37 | + max_replication_slots = 10 |
| 38 | + wal_level = logical |
| 39 | + shared_preload_libraries = 'multimaster' |
| 40 | + multimaster.workers=4 |
| 41 | + multimaster.queue_size=10485760 # 10mb |
| 42 | +); |
| 43 | + |
| 44 | +# Init nodes |
| 45 | +for (my $i=0; $i < $nnodes; $i++) { |
| 46 | + push(@nodes, get_new_node("node$i")); |
| 47 | + $nodes[$i]->init; |
| 48 | +} |
| 49 | + |
| 50 | +# Collect conn info |
| 51 | +my $mm_connstr = join(', ', map { "${ \$_->inet_connstr('postgres') }" } @nodes); |
| 52 | + |
| 53 | +# Configure and start nodes |
| 54 | +for (my $i=0; $i < $nnodes; $i++) { |
| 55 | + $nodes[$i]->append_conf('postgresql.conf', $pgconf_common); |
| 56 | + $nodes[$i]->append_conf('postgresql.conf', qq( |
| 57 | + multimaster.node_id = @{[ $i + 1 ]} |
| 58 | + multimaster.conn_strings = '$mm_connstr' |
| 59 | + #multimaster.arbiter_port = ${ \$nodes[0]->port } |
| 60 | + )); |
| 61 | + $nodes[$i]->append_conf('pg_hba.conf', qq( |
| 62 | + host replication all 127.0.0.1/32 trust |
| 63 | + )); |
| 64 | + $nodes[$i]->start; |
| 65 | +} |
| 66 | + |
| 67 | +############################################################################### |
| 68 | +# Wait until nodes are up |
| 69 | +############################################################################### |
| 70 | + |
| 71 | +my $psql_out; |
| 72 | +# XXX: change to poll_untill |
| 73 | +sleep(7); |
| 74 | + |
| 75 | +############################################################################### |
| 76 | +# Replication check |
| 77 | +############################################################################### |
| 78 | + |
| 79 | +$nodes[0]->psql('postgres', " |
| 80 | + create extension multimaster; |
| 81 | + create table if not exists t(k int primary key, v int); |
| 82 | + insert into t values(1, 10); |
| 83 | +"); |
| 84 | + |
| 85 | +$nodes[1]->psql('postgres', "select v from t where k=1;", stdout => \$psql_out); |
| 86 | +is($psql_out, '10', "Check sanity while all nodes are up."); |
| 87 | + |
| 88 | +############################################################################### |
| 89 | +# Isolation regress checks |
| 90 | +############################################################################### |
| 91 | + |
| 92 | +# we can call pg_regress here |
| 93 | + |
| 94 | +############################################################################### |
| 95 | +# Work after node stop |
| 96 | +############################################################################### |
| 97 | + |
| 98 | +$nodes[2]->teardown_node; |
| 99 | + |
| 100 | +# $nodes[0]->poll_query_until('postgres', |
| 101 | +# "select disconnected = true from mtm.get_nodes_state() where id=3;") |
| 102 | +# or die "Timed out while waiting for node to disconnect"; |
| 103 | + |
| 104 | +$nodes[0]->psql('postgres', " |
| 105 | + insert into t values(2, 20); |
| 106 | +"); |
| 107 | + |
| 108 | +$nodes[1]->psql('postgres', "select v from t where k=2;", stdout => \$psql_out); |
| 109 | +is($psql_out, '20', "Check that we can commit after one node disconnect."); |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | + |
0 commit comments