Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit196b72f

Browse files
committed
Add regression tests for multiple synchronous standbys.
Authors: Suraj Kharage, Michael Paquier, Masahiko Sawada, refactored by meReviewed-By: Kyotaro Horiguchi
1 parent0711803 commit196b72f

File tree

2 files changed

+167
-0
lines changed

2 files changed

+167
-0
lines changed

‎src/test/perl/PostgresNode.pm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,24 @@ sub stop
668668

669669
=pod
670670
671+
=item$node->reload()
672+
673+
Reload configuration parameters on the node.
674+
675+
=cut
676+
677+
subreload
678+
{
679+
my ($self) =@_;
680+
my$port =$self->port;
681+
my$pgdata =$self->data_dir;
682+
my$name =$self->name;
683+
print"### Reloading node\"$name\"\n";
684+
TestLib::system_log('pg_ctl','-D',$pgdata,'reload');
685+
}
686+
687+
=pod
688+
671689
=item$node->restart()
672690
673691
Wrapper for pg_ctl -w restart

‎src/test/recovery/t/007_sync_rep.pl

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Minimal test testing synchronous replication sync_state transition
2+
use strict;
3+
use warnings;
4+
use PostgresNode;
5+
use TestLib;
6+
use Test::Moretests=> 8;
7+
8+
# Query checking sync_priority and sync_state of each standby
9+
my$check_sql ="SELECT application_name, sync_priority, sync_state FROM pg_stat_replication ORDER BY application_name;";
10+
11+
# Check that sync_state of each standby is expected.
12+
# If $setting is given, synchronous_standby_names is set to it and
13+
# the configuration file is reloaded before the test.
14+
subtest_sync_state
15+
{
16+
my ($self,$expected,$msg,$setting) =@_;
17+
18+
if (defined($setting))
19+
{
20+
$self->psql('postgres',
21+
"ALTER SYSTEM SET synchronous_standby_names = '$setting';");
22+
$self->reload;
23+
}
24+
25+
my$result =$self->safe_psql('postgres',$check_sql);
26+
is($result,$expected,$msg);
27+
}
28+
29+
# Initialize master node
30+
my$node_master = get_new_node('master');
31+
$node_master->init(allows_streaming=> 1);
32+
$node_master->start;
33+
my$backup_name ='master_backup';
34+
35+
# Take backup
36+
$node_master->backup($backup_name);
37+
38+
# Create standby1 linking to master
39+
my$node_standby_1 = get_new_node('standby1');
40+
$node_standby_1->init_from_backup($node_master,$backup_name,
41+
has_streaming=> 1);
42+
$node_standby_1->start;
43+
44+
# Create standby2 linking to master
45+
my$node_standby_2 = get_new_node('standby2');
46+
$node_standby_2->init_from_backup($node_master,$backup_name,
47+
has_streaming=> 1);
48+
$node_standby_2->start;
49+
50+
# Create standby3 linking to master
51+
my$node_standby_3 = get_new_node('standby3');
52+
$node_standby_3->init_from_backup($node_master,$backup_name,
53+
has_streaming=> 1);
54+
$node_standby_3->start;
55+
56+
# Check that sync_state is determined correctly when
57+
# synchronous_standby_names is specified in old syntax.
58+
test_sync_state($node_master,qq(standby1|1|sync
59+
standby2|2|potential
60+
standby3|0|async),
61+
'old syntax of synchronous_standby_names',
62+
'standby1,standby2');
63+
64+
# Check that all the standbys are considered as either sync or
65+
# potential when * is specified in synchronous_standby_names.
66+
# Note that standby1 is chosen as sync standby because
67+
# it's stored in the head of WalSnd array which manages
68+
# all the standbys though they have the same priority.
69+
test_sync_state($node_master,qq(standby1|1|sync
70+
standby2|1|potential
71+
standby3|1|potential),
72+
'asterisk in synchronous_standby_names',
73+
'*');
74+
75+
# Stop and start standbys to rearrange the order of standbys
76+
# in WalSnd array. Now, if standbys have the same priority,
77+
# standby2 is selected preferentially and standby3 is next.
78+
$node_standby_1->stop;
79+
$node_standby_2->stop;
80+
$node_standby_3->stop;
81+
82+
$node_standby_2->start;
83+
$node_standby_3->start;
84+
85+
# Specify 2 as the number of sync standbys.
86+
# Check that two standbys are in 'sync' state.
87+
test_sync_state($node_master,qq(standby2|2|sync
88+
standby3|3|sync),
89+
'2 synchronous standbys',
90+
'2(standby1,standby2,standby3)');
91+
92+
# Start standby1
93+
$node_standby_1->start;
94+
95+
# Create standby4 linking to master
96+
my$node_standby_4 = get_new_node('standby4');
97+
$node_standby_4->init_from_backup($node_master,$backup_name,
98+
has_streaming=> 1);
99+
$node_standby_4->start;
100+
101+
# Check that standby1 and standby2 whose names appear earlier in
102+
# synchronous_standby_names are considered as sync. Also check that
103+
# standby3 appearing later represents potential, and standby4 is
104+
# in 'async' state because it's not in the list.
105+
test_sync_state($node_master,qq(standby1|1|sync
106+
standby2|2|sync
107+
standby3|3|potential
108+
standby4|0|async),
109+
'2 sync, 1 potential and 1 async');
110+
111+
# Check that sync_state of each standby is determined correctly
112+
# when num_sync exceeds the number of names of potential sync standbys
113+
# specified in synchronous_standby_names.
114+
test_sync_state($node_master,qq(standby1|0|async
115+
standby2|4|sync
116+
standby3|3|sync
117+
standby4|1|sync),
118+
'num_sync exceeds the num of potential sync standbys',
119+
'6(standby4,standby0,standby3,standby2)');
120+
121+
# The setting that * comes before another standby name is acceptable
122+
# but does not make sense in most cases. Check that sync_state is
123+
# chosen properly even in case of that setting.
124+
# The priority of standby2 should be 2 because it matches * first.
125+
test_sync_state($node_master,qq(standby1|1|sync
126+
standby2|2|sync
127+
standby3|2|potential
128+
standby4|2|potential),
129+
'asterisk comes before another standby name',
130+
'2(standby1,*,standby2)');
131+
132+
# Check that the setting of '2(*)' chooses standby2 and standby3 that are stored
133+
# earlier in WalSnd array as sync standbys.
134+
test_sync_state($node_master,qq(standby1|1|potential
135+
standby2|1|sync
136+
standby3|1|sync
137+
standby4|1|potential),
138+
'multiple standbys having the same priority are chosen as sync',
139+
'2(*)');
140+
141+
# Stop Standby3 which is considered in 'sync' state.
142+
$node_standby_3->stop;
143+
144+
# Check that the state of standby1 stored earlier in WalSnd array than
145+
# standby4 is transited from potential to sync.
146+
test_sync_state($node_master,qq(standby1|1|sync
147+
standby2|1|sync
148+
standby4|1|potential),
149+
'potential standby found earlier in array is promoted to sync');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp