Skip to content

Commit 11cec76

Browse files
committed
mark datastateat
1 parent e01f970 commit 11cec76

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

pkg/retrieval/engine/postgres/snapshot/physical.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,10 @@ func (p *PhysicalInitial) promoteInstance(ctx context.Context, clonePath string)
474474
return errors.Wrap(err, "failed to readiness check")
475475
}
476476

477+
if err := p.markDSA(ctx, promoteCont.ID); err != nil {
478+
return errors.Wrap(err, "failed to mark dataStateAt")
479+
}
480+
477481
shouldBePromoted, err := p.checkRecovery(ctx, promoteCont.ID)
478482
if err != nil {
479483
return errors.Wrap(err, "failed to check recovery mode")
@@ -483,25 +487,6 @@ func (p *PhysicalInitial) promoteInstance(ctx context.Context, clonePath string)
483487

484488
// Detect dataStateAt.
485489
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-
505490
// Promote PGDATA.
506491
if err := p.runPromoteCommand(ctx, promoteCont.ID, clonePath); err != nil {
507492
return errors.Wrapf(err, "failed to promote PGDATA: %s", clonePath)
@@ -544,6 +529,29 @@ func (p *PhysicalInitial) promoteInstance(ctx context.Context, clonePath string)
544529
return nil
545530
}
546531

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+
547555
func (p *PhysicalInitial) buildContainerConfig(clonePath, promoteImage, password string) *container.Config {
548556
hcPromotionInterval := health.DefaultRestoreInterval
549557
hcPromotionRetries := health.DefaultRestoreRetries

0 commit comments

Comments
 (0)