|
50 | 50 | $node_1->safe_psql('postgres', 'CREATE TABLE public.bar (t TEXT)');
|
51 | 51 | $node_1->safe_psql('postgres', "INSERT INTO public.bar VALUES ('in both')");
|
52 | 52 |
|
53 |
| - |
54 |
| -# Take backup |
| 53 | +# |
| 54 | +# Create node_2 and node_3 as standbys following node_1 |
| 55 | +# |
55 | 56 | my $backup_name = 'my_backup';
|
56 | 57 | $node_1->backup($backup_name);
|
57 | 58 |
|
58 |
| -# Create streaming standby from backup |
59 | 59 | my $node_2 = get_new_node('node_2');
|
60 | 60 | $node_2->init_from_backup($node_1, $backup_name,
|
61 | 61 | has_streaming => 1);
|
62 | 62 | $node_2->start;
|
63 | 63 |
|
64 |
| -# Create streaming standby from backup |
65 | 64 | my $node_3 = get_new_node('node_3');
|
66 | 65 | $node_3->init_from_backup($node_1, $backup_name,
|
67 | 66 | has_streaming => 1);
|
68 | 67 | $node_3->start;
|
69 | 68 |
|
70 |
| -# Stop node_1 |
| 69 | +# Wait until node 3 has connected and caught up |
| 70 | +my $lsn = $node_1->lsn('insert'); |
| 71 | +$node_1->wait_for_catchup('node_3', 'replay', $lsn); |
71 | 72 |
|
| 73 | +# |
| 74 | +# Swap the roles of node_1 and node_3, so that node_1 follows node_3. |
| 75 | +# |
72 | 76 | $node_1->stop('fast');
|
73 |
| - |
74 |
| -# Promote node_3 |
75 | 77 | $node_3->promote;
|
76 | 78 |
|
77 |
| -# node_1 rejoins node_3 |
78 |
| - |
| 79 | +# reconfigure node_1 as a standby following node_3 |
79 | 80 | my $node_3_connstr = $node_3->connstr;
|
80 | 81 |
|
81 | 82 | unlink($node_2->data_dir . '/recovery.conf');
|
82 | 83 | $node_1->append_conf('recovery.conf', qq(
|
83 | 84 | standby_mode=on
|
84 |
| -primary_conninfo='$node_3_connstr' |
| 85 | +primary_conninfo='$node_3_connstr application_name=node_1' |
85 | 86 | recovery_target_timeline='latest'
|
86 | 87 | ));
|
87 | 88 | $node_1->start();
|
88 | 89 |
|
89 |
| -# node_2 follows node_3 |
90 |
| - |
| 90 | +# also reconfigure node_2 to follow node_3 |
91 | 91 | unlink($node_2->data_dir . '/recovery.conf');
|
92 | 92 | $node_2->append_conf('recovery.conf', qq(
|
93 | 93 | standby_mode=on
|
94 |
| -primary_conninfo='$node_3_connstr' |
| 94 | +primary_conninfo='$node_3_connstr application_name=node_2' |
95 | 95 | recovery_target_timeline='latest'
|
96 | 96 | ));
|
97 | 97 | $node_2->restart();
|
98 | 98 |
|
99 |
| -# Promote node_1 |
| 99 | +# |
| 100 | +# Promote node_1, to create a split-brain scenario. |
| 101 | +# |
| 102 | + |
| 103 | +# make sure node_1 is full caught up with node_3 first |
| 104 | +$lsn = $node_3->lsn('insert'); |
| 105 | +$node_3->wait_for_catchup('node_1', 'replay', $lsn); |
100 | 106 |
|
101 | 107 | $node_1->promote;
|
102 | 108 |
|
| 109 | +# |
103 | 110 | # We now have a split-brain with two primaries. Insert a row on both to
|
104 | 111 | # demonstratively create a split brain. After the rewind, we should only
|
105 | 112 | # see the insert on 1, as the insert on node 3 is rewound away.
|
| 113 | +# |
106 | 114 | $node_1->safe_psql('postgres', "INSERT INTO public.foo (t) VALUES ('keep this')");
|
107 | 115 |
|
108 | 116 | # Insert more rows in node 1, to bump up the XID counter. Otherwise, if
|
|
0 commit comments