Skip to content

Commit 8820b29

Browse files
committed
Merge branch 'comment-dsa-extraction-logic' into 'master'
Describe how dataStateAt is determined See merge request postgres-ai/database-lab!356
2 parents 65623af + ad38b1b commit 8820b29

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,24 @@ func (p *PhysicalInitial) checkRecovery(ctx context.Context, containerID string)
880880
return output, err
881881
}
882882

883+
/* "Data state at" (DSA) is a timestamp that represents the database's state. This function tries to
884+
determine its value based on various sources. If it fails, an error is reported. Using the current
885+
time as a last resort would be misleading, especially in the case when the "sync" container
886+
is running, and users deal with multiple snapshots.
887+
888+
Current steps to determine DSA:
889+
890+
Step 1. Using pg_last_xact_replay_timestamp() (either in the "promote" or the "sync" Postgres).
891+
It may be empty if there are no transactions recently committed on the source.
892+
893+
Step 2. Parsing available WALs using pg_waldump. We check WALs in reverse order and try to find
894+
the latest available Transaction record.
895+
Again, this may be not working - for example, WALs may be empty if archive_timeout is non-zero
896+
and the source doesn't have enough activity.
897+
898+
Step 3. Use the timestamp of the latest checkpoint. This is extracted from PGDATA using the
899+
pg_controldata utility. Note that this is not an exact value of the latest activity in the source
900+
before we took a copy of PGDATA, but we suppose it is not far from it. */
883901
func (p *PhysicalInitial) extractDataStateAt(ctx context.Context, containerID, dataDir string, pgVersion float64,
884902
defaultDSA string) (string, error) {
885903
output, err := p.getLastXActReplayTimestamp(ctx, containerID)

0 commit comments

Comments
 (0)