Repository navigation
Conversation
A concurrent TRUNCATE can replace table storage after the backup snapshot but before table locks are acquired. Backup and restore can then report success while restoring an empty table. On Cloudberry, validate storage and table identity after locking, including descendant partitions. Add --snapshot-attempts (default 3) to retry with a fresh shared snapshot, rebuild filters, and discard heap file hashes. Fail the backup when the limit is reached.
|
Hi @talmacschen-arch @liang8283, welcome to help review when you're available. Thanks! |
|
Reviewed by Claude Code. FYI. |
|
Storage-change check also trips on MVCC-safe rewrites, and can fail backups.
On a Cloudberry cluster with 60 heap tables, running this branch's Another run only succeeded on the last attempt. The same workload backed up by Besides failing backups whose data was fine, every false-positive retry also discards |
MisterRaindrop
left a comment
There was a problem hiding this comment.
Tested this on Apache Cloudberry 3.0.0-devel and confirmed it fixes the concurrent TRUNCATE silent data-loss issue for both heap and ao_row tables.
While testing concurrent DDL scenarios against this branch, I reproduced a few remaining issues:
1. Stale quotedRoleNames after snapshot retry (backup/backup.go:96, backup/snapshot.go:111)
getQuotedRoleNames() is only called once in DoSetup() and not refreshed after restartBackupTransactions().
Repro:
- Create
public.t(id int)with(1),(2),(3). - In an uncommitted transaction:
CREATE ROLE "RetryRole"; GRANT SELECT ON public.t TO "RetryRole"; TRUNCATE public.t; INSERT INTO public.t VALUES (4),(5),(6);
- Run
gpbackup, wait forAccessShareLockonpublic.t, then commit the writer. gpbackupretries on attempt 2 and exits0, butgprestorefails:ERROR: role "retryrole" does not exist (SQLSTATE 42704)
Refreshing getQuotedRoleNames(connectionPool) on retry (or calling it after RetrieveAndProcessTables()) should fix this.
2. Concurrent DETACH / ATTACH PARTITION bypass CheckSnapshotTables (backup/snapshot.go:34)
Neither changes relfilenode, name, or OID, so CheckSnapshotTables reports no conflict (tested without --leaf-partition-data):
DETACH PARTITION(withoutDROP):- Create partitioned
public.twith leafpublic.t_p1containing(1),(2),(3). - In an uncommitted transaction, run
ALTER TABLE public.t DETACH PARTITION public.t_p1;. - Start
gpbackup, wait forAccessShareLockonpublic.t, then commit. - Result: no retry;
gpbackupcrashes inGetPartitionTableMap(backup/queries_table_defs.go:189) with:sql: Scan error on column index 1, name "rootname": converting NULL to string is unsupported
- Create partitioned
ATTACH PARTITION:- Create partitioned
public.twithpublic.t_p1(0..10, rows1,2,3) and standalonepublic.t_p2(rows11,12,13). - In an uncommitted transaction, run
ALTER TABLE public.t ATTACH PARTITION public.t_p2 FOR VALUES FROM (10) TO (20);. - Start
gpbackup, wait forAccessShareLockonpublic.t_p2(orpublic.t_defif aDEFAULTpartition exists), then commit. - Result:
gpbackupexits0, thengprestoreeither fails withERROR: no partition of relation "t" found for row (SQLSTATE 22M01), or—whenpublic.thas aDEFAULTpartition—exits0while silently duplicating11,12,13into both the restoredDEFAULTpartition and standalonepublic.t_p2.
- Create partitioned
Validating partition membership consistency (e.g., comparing snapshot pg_inherits/relispartition against current pg_partition_root() / pg_partition_tree()) in CheckSnapshotTables would catch these cases.
3. +1 on @liang8283's comment about MVCC-safe heap rewrites
Also reproduced with concurrent CLUSTER on a heap table: main backs up and restores {1,2,3} cleanly on attempt 1, while this branch flags table storage changed after the snapshot, fails with --snapshot-attempts 1, and disables --heap-file-hash on retry.
Problem
gpbackuptakes its snapshot before acquiring table locks. ConcurrentTRUNCATEcan replace storage while it waits, so backup and restore report success but restore an empty table, hiding data loss.Reproduction
{1,2,3}on Cloudberry.TRUNCATEand insert{4,5,6}without committing.gpbackup, wait untilpg_locksshows the backup waiting forAccessShareLockon this table, then commit the writer.0, but the restored table is empty.Fix
--snapshot-attempts(default3) to retry with a fresh shared snapshot and fail the backup when attempts are exhausted.