Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
b24d1b3 (2026-10-16)
Other Environment Information
- Hardware: macOS arm64 (Apple Silicon)
- Topology: single-node standalone
- OS: macOS
Actual Behavior
PITR RESTORE DATABASE silently returns wrong data when the restore-point baseline is not yet fully materialized: instead of failing or waiting, it hands back either the current table state or a partial state — with no error or warning. Which databases are hit depends on the order in which restores are executed, proving a readiness race rather than random corruption.
Experiment 1 (8 identical databases, one shared timestamp, restores issued in order zb1→zb8):
- Setup: 8 fresh databases
zb1..zb8, eachtloaded with ids 1..10;T = now()immediately after the last insert;delete id<=5in all 8; sleep 45s; then restore in creation order. - Result: zb1..zb4 (the first four) all restored to
6,7,8,9,10— i.e. the post-DELETE current state, exactly as if the restore were a no-op. zb5..zb8 restored correctly to1..10. Same timestamps, same commands — only execution order differs.
Experiment 2 (6 databases, same setup, restores issued in REVERSE order rb6→rb1):
- Result: rb6 — the first restore executed — restored to
1..9(silently missing row 10, the last-inserted row); rb5..rb1 all correct (1..10).
Experiment 3 (5 rounds, single database per round, but with a 5-second gap between the last insert and taking T): all 5/5 rounds restore correctly.
The three experiments triangulate the cause: when T is taken immediately after the last commit, the first restore(s) executed after the PITR window read a baseline whose storage-side materialization (checkpoint/flush of the tail data) has not completed. Those restores silently degrade — sometimes to the current data, sometimes dropping the tail rows — instead of failing loudly or blocking until the baseline is ready. Later restores (seconds after) succeed, which is why users will see this as intermittent "PITR restore didn't bring my data back", unreproducible when they retry.
Steps to Reproduce
-- repeat with 2+ databases to see the ordering effect; minimal version:
create database r1; create table r1.t (id int primary key, v int);
insert into r1.t values (1,1),(2,2),...,(10,10);
-- T = SELECT NOW(); -- taken immediately, no settling delay
-- delete from r1.t where id <= 5;
-- sleep 45s, then immediately:
restore database r1 from pitr p1 '<T>';
select group_concat(id order by id) from r1.t; -- chance of getting 6..10 (no-op) or 1..9 (tail rows lost) instead of 1..10Reliable reproduction needs the batch-order protocol from Experiment 1 (first-restored databases fail deterministically in our runs: 4/8 then 1/6-of-first).
Expected Behavior
A restore to timestamp T must either (a) reflect the exact committed state at T — which requires waiting for/blocking on baseline materialization for that timestamp, or (b) fail with a clear "restore point not yet materialized, retry" error. Silently returning non-T data from a recovery tool is the worst failure mode: the user has no way to know the restore is wrong.
Root cause direction
The restore path resolves T against PITR storage without a readiness fence: tail commits (and possibly the whole DB image for freshly-created databases) are still being checkpointed/flushed when the first restore lands. The snapshot/pit reader presumably uses whatever partial state exists (hence current-state or tail-truncated outputs), and nothing re-validates completeness after reading. Same "silent wrong result rather than loud failure" family as #30614/#30615 (metadata) — here affecting row data itself.
Additional information
- This also retroactively explains the "unstable row restore" symptoms recorded as additional evidence in [Bug]: Restore paths must preserve target-time data and foreign-key integrity #30615 (rounds 2/3 of the FK test losing rows): those rounds had T taken immediately after DDL+insert and were restored earliest.
- Repro scripts: matrix4.sh (order-dependent 4/8 failure), matrix5.sh (reversed-order first-restore tail loss), matrix3.sh (5s settle → 5/5 pass).
Activity
Ariznawlll commentedon Oct 19, 2026
Consolidated diagnosis: the restore-subsystem defect map (as of 2026-10-19 evening)
While isolating this race, a systematic audit of both restore paths (database-level) produced a four-quadrant asymmetry that maintainers may find useful when prioritizing fixes — each quadrant is a separate filed issue with 3/3-or-better reproduction:
Structural takeaway: the two restore paths each implement about half of the metadata/integrity reconstruction and none of the missing halves are covered by BVT (
test/distributed/cases/pitr/has no index/FK publication database-restore scenarios;snapshot/has no publication-preservation scenario). Every defect above is in the intersection "restore × metadata-projection" — reading historical catalog state ({MO_TS}) and rebuilding what was read. The mo_role_privs reader gets this right by selecting explicit cast columns (snapshot_catalog_restore.go:563-566 rolePrivilegeRestoreSelectSQL); the mo_pubs/mo_subs readers get it wrong by positional reads. Suggest considering a shared "historical catalog restore" helper that reads by column name with layout negotiation, which would fix #30607, harden the mo_subs latent mismatch (snapshot.go:90 getSubsSqlFmt hardcodes the new layout on {MO_TS} reads — an upgrade-compatibility hazard awaiting older clusters), and prevent the index/FK/publication asymmetry class.Also for completeness: snapshot-side zero-delay restore was verified clean 8/8 with the same batch protocol that fails 4/8 on PITR (snap-race1.sh) — so this race is PITR-specific, consistent with its background-sampling design vs. synchronous snapshot creation.
XuPeng-SH commentedon Oct 22, 2026
This report is now tracked together with #30615. The canonical issue retains explicit acceptance cases for the behavior described here. This is an administrative duplicate/consolidation closure only; the underlying defect is not claimed fixed. The original description and discussion remain available on this issue.
fix(sql): keep foreign-key integrity through restore and deferred FK …