@@ -474,6 +474,10 @@ func (p *PhysicalInitial) promoteInstance(ctx context.Context, clonePath string)
474
474
return errors .Wrap (err , "failed to readiness check" )
475
475
}
476
476
477
+ if err := p .markDSA (ctx , promoteCont .ID ); err != nil {
478
+ return errors .Wrap (err , "failed to mark dataStateAt" )
479
+ }
480
+
477
481
shouldBePromoted , err := p .checkRecovery (ctx , promoteCont .ID )
478
482
if err != nil {
479
483
return errors .Wrap (err , "failed to check recovery mode" )
@@ -483,25 +487,6 @@ func (p *PhysicalInitial) promoteInstance(ctx context.Context, clonePath string)
483
487
484
488
// Detect dataStateAt.
485
489
if shouldBePromoted == "t" {
486
- extractedDataStateAt , err := p .extractDataStateAt (ctx , promoteCont .ID )
487
- if err != nil {
488
- return errors .Wrap (err ,
489
- `Failed to get data_state_at: PGDATA should be promoted, but pg_last_xact_replay_timestamp() returns empty result.
490
- Check if pg_data is correct, or explicitly define DATA_STATE_AT via an environment variable.` )
491
- }
492
-
493
- log .Msg ("Extracted Data state at: " , extractedDataStateAt )
494
-
495
- if p .dbMark .DataStateAt != "" && extractedDataStateAt == p .dbMark .DataStateAt {
496
- return newSkipSnapshotErr (fmt .Sprintf (
497
- `The previous snapshot already contains the latest data: %s. Skip taking a new snapshot.` ,
498
- p .dbMark .DataStateAt ))
499
- }
500
-
501
- p .dbMark .DataStateAt = extractedDataStateAt
502
-
503
- log .Msg ("Data state at: " , p .dbMark .DataStateAt )
504
-
505
490
// Promote PGDATA.
506
491
if err := p .runPromoteCommand (ctx , promoteCont .ID , clonePath ); err != nil {
507
492
return errors .Wrapf (err , "failed to promote PGDATA: %s" , clonePath )
@@ -544,6 +529,29 @@ func (p *PhysicalInitial) promoteInstance(ctx context.Context, clonePath string)
544
529
return nil
545
530
}
546
531
532
+ func (p * PhysicalInitial ) markDSA (ctx context.Context , containerID string ) error {
533
+ extractedDataStateAt , err := p .extractDataStateAt (ctx , containerID )
534
+ if err != nil {
535
+ return errors .Wrap (err ,
536
+ `Failed to get data_state_at: PGDATA should be promoted, but pg_last_xact_replay_timestamp() returns empty result.
537
+ Check if pg_data is correct, or explicitly define DATA_STATE_AT via an environment variable.` )
538
+ }
539
+
540
+ log .Msg ("Extracted Data state at: " , extractedDataStateAt )
541
+
542
+ if p .dbMark .DataStateAt != "" && extractedDataStateAt == p .dbMark .DataStateAt {
543
+ return newSkipSnapshotErr (fmt .Sprintf (
544
+ `The previous snapshot already contains the latest data: %s. Skip taking a new snapshot.` ,
545
+ p .dbMark .DataStateAt ))
546
+ }
547
+
548
+ p .dbMark .DataStateAt = extractedDataStateAt
549
+
550
+ log .Msg ("Data state at: " , p .dbMark .DataStateAt )
551
+
552
+ return nil
553
+ }
554
+
547
555
func (p * PhysicalInitial ) buildContainerConfig (clonePath , promoteImage , password string ) * container.Config {
548
556
hcPromotionInterval := health .DefaultRestoreInterval
549
557
hcPromotionRetries := health .DefaultRestoreRetries
0 commit comments