@@ -124,18 +124,21 @@ func TestInitWithMultipleKeepers(t *testing.T) {
124124}
125125
126126func setupServers (t * testing.T , clusterName , dir string , numKeepers , numSentinels uint8 , syncRepl bool , usePgrewind bool , primaryKeeper * TestKeeper ) (testKeepers , testSentinels , * TestProxy , * TestStore ) {
127- var initialClusterSpec * cluster.ClusterSpec
127+ var initialClusterSpec = & cluster.ClusterSpec {
128+ SleepInterval : & cluster.Duration {Duration : 2 * time .Second },
129+ FailInterval : & cluster.Duration {Duration : 5 * time .Second },
130+ ConvergenceTimeout : & cluster.Duration {Duration : 30 * time .Second },
131+ MaxStandbyLag : cluster .Uint32P (50 * 1024 ), // limit lag to 50kiB
132+ SynchronousReplication : cluster .BoolP (syncRepl ),
133+ PGParameters : defaultPGParameters ,
134+ // If we want to pg_rewind then also checkpoint beforehand, otherwise we may fail due
135+ // to uncheckpoint'ed timeline changes that have us silently fallback to basebackup.
136+ UsePgrewind : cluster .BoolP (usePgrewind ),
137+ CheckpointBeforePgrewind : cluster .BoolP (usePgrewind ),
138+ }
139+
128140 if primaryKeeper == nil {
129- initialClusterSpec = & cluster.ClusterSpec {
130- InitMode : cluster .ClusterInitModeP (cluster .ClusterInitModeNew ),
131- SleepInterval : & cluster.Duration {Duration : 2 * time .Second },
132- FailInterval : & cluster.Duration {Duration : 5 * time .Second },
133- ConvergenceTimeout : & cluster.Duration {Duration : 30 * time .Second },
134- MaxStandbyLag : cluster .Uint32P (50 * 1024 ), // limit lag to 50kiB
135- SynchronousReplication : cluster .BoolP (syncRepl ),
136- UsePgrewind : cluster .BoolP (usePgrewind ),
137- PGParameters : defaultPGParameters ,
138- }
141+ initialClusterSpec .InitMode = cluster .ClusterInitModeP (cluster .ClusterInitModeNew )
139142 } else {
140143 // if primaryKeeper is provided then we should create a standby cluster and do a
141144 // pitr recovery from the external primary database
@@ -147,22 +150,14 @@ func setupServers(t *testing.T, clusterName, dir string, numKeepers, numSentinel
147150 pgpass .WriteString (fmt .Sprintf ("%s:%s:*:%s:%s\n " , primaryKeeper .pgListenAddress , primaryKeeper .pgPort , primaryKeeper .pgReplUsername , primaryKeeper .pgReplPassword ))
148151 pgpass .Close ()
149152
150- initialClusterSpec = & cluster.ClusterSpec {
151- InitMode : cluster .ClusterInitModeP (cluster .ClusterInitModePITR ),
152- Role : cluster .ClusterRoleP (cluster .ClusterRoleStandby ),
153- SleepInterval : & cluster.Duration {Duration : 2 * time .Second },
154- FailInterval : & cluster.Duration {Duration : 5 * time .Second },
155- ConvergenceTimeout : & cluster.Duration {Duration : 30 * time .Second },
156- MaxStandbyLag : cluster .Uint32P (50 * 1024 ), // limit lag to 50kiB
157- SynchronousReplication : cluster .BoolP (syncRepl ),
158- PGParameters : defaultPGParameters ,
159- PITRConfig : & cluster.PITRConfig {
160- DataRestoreCommand : fmt .Sprintf ("PGPASSFILE=%s pg_basebackup -D %%d -h %s -p %s -U %s" , pgpass .Name (), primaryKeeper .pgListenAddress , primaryKeeper .pgPort , primaryKeeper .pgReplUsername ),
161- },
162- StandbyConfig : & cluster.StandbyConfig {
163- StandbySettings : & cluster.StandbySettings {
164- PrimaryConninfo : fmt .Sprintf ("sslmode=disable host=%s port=%s user=%s password=%s" , primaryKeeper .pgListenAddress , primaryKeeper .pgPort , primaryKeeper .pgReplUsername , primaryKeeper .pgReplPassword ),
165- },
153+ initialClusterSpec .InitMode = cluster .ClusterInitModeP (cluster .ClusterInitModePITR )
154+ initialClusterSpec .Role = cluster .ClusterRoleP (cluster .ClusterRoleStandby )
155+ initialClusterSpec .PITRConfig = & cluster.PITRConfig {
156+ DataRestoreCommand : fmt .Sprintf ("PGPASSFILE=%s pg_basebackup -D %%d -h %s -p %s -U %s" , pgpass .Name (), primaryKeeper .pgListenAddress , primaryKeeper .pgPort , primaryKeeper .pgReplUsername ),
157+ }
158+ initialClusterSpec .StandbyConfig = & cluster.StandbyConfig {
159+ StandbySettings : & cluster.StandbySettings {
160+ PrimaryConninfo : fmt .Sprintf ("sslmode=disable host=%s port=%s user=%s password=%s" , primaryKeeper .pgListenAddress , primaryKeeper .pgPort , primaryKeeper .pgReplUsername , primaryKeeper .pgReplPassword ),
166161 },
167162 }
168163 }
@@ -1011,6 +1006,23 @@ func testTimelineFork(t *testing.T, syncRepl, usePgrewind bool) {
10111006 t .Fatalf ("unexpected err: %v" , err )
10121007 }
10131008
1009+ ctx , cancel := context .WithCancel (context .Background ())
1010+ defer cancel ()
1011+ go func (ctx context.Context ) {
1012+ var cd string
1013+ for {
1014+ select {
1015+ case <- ctx .Done ():
1016+ return
1017+ case <- time .After (100 * time .Millisecond ):
1018+ if newCd := standbys [0 ].PGControldata (); newCd != cd {
1019+ t .Logf ("standby[0] controldata changed: %s" , newCd )
1020+ cd = newCd
1021+ }
1022+ }
1023+ }
1024+ }(ctx )
1025+
10141026 // Stop standby[0]
10151027 t .Logf ("Stopping standby[0]: %s" , standbys [0 ].uid )
10161028 standbys [0 ].Stop ()
@@ -1112,19 +1124,19 @@ func testTimelineFork(t *testing.T, syncRepl, usePgrewind bool) {
11121124 if usePgrewind {
11131125 output := standbys [1 ].ReadOutput ()
11141126 if ! strings .Contains (output , "running pg_rewind" ) {
1115- t .Error ("expected to run pg_rewind but could not find it in logs" )
1127+ t .Errorf ("expected logs to contain evidence of running pg_rewind: %s" , standbys [ 1 ]. uid )
11161128 }
11171129
11181130 // This will occur whenever pg_rewind is run against a Postgres that has not
11191131 // checkpointed since its timeline previously forked. pg_rewind first grabs the
11201132 // pg_control file to check if timelines are diverged, and this file won't have been
11211133 // updated until a checkpoint takes place.
1122- if ! strings .Contains (output , "no rewind required" ) {
1123- t .Error ("keeper tried rewinding but rewind thought it was not required" )
1134+ if strings .Contains (output , "no rewind required" ) {
1135+ t .Errorf ("keeper tried rewinding but rewind thought it was not required: %s" , standbys [ 1 ]. uid )
11241136 }
11251137
11261138 if strings .Contains (output , "running pg_basebackup" ) {
1127- t .Error ("pg_rewind is enabled but we performed a pg_basebackup anyway" )
1139+ t .Errorf ("pg_rewind is enabled but we performed a pg_basebackup anyway: %s" , standbys [ 1 ]. uid )
11281140 }
11291141 }
11301142
0 commit comments