From 8eaa89f7582141e615e3ce2d78a9d61636fa4383 Mon Sep 17 00:00:00 2001 From: adityamaru Date: Thu, 19 Jan 2023 13:21:25 -0500 Subject: [PATCH] backupccl: fix flaky TestExcludeDataFromBackupAndRestore We don't need to wait for the table to split, inspecting the state of the leaseholders replica is adequate and a more correct source of truth to rely on. In some cases the test would not wait for `data.bar` to split into its own range and so it would incorrectly be excluded from the backup resulting in 0 rows instead of 10 in the final assertion. Fixes: #95350 Release note: None --- pkg/ccl/backupccl/backup_test.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/ccl/backupccl/backup_test.go b/pkg/ccl/backupccl/backup_test.go index 4d0a3ab567f8..33195366346a 100644 --- a/pkg/ccl/backupccl/backup_test.go +++ b/pkg/ccl/backupccl/backup_test.go @@ -9251,17 +9251,21 @@ func TestExcludeDataFromBackupAndRestore(t *testing.T) { // Set foo to exclude_data_from_backup and back it up. The ExportRequest // should be a noop and backup no data. sqlDB.Exec(t, `ALTER TABLE data.foo SET (exclude_data_from_backup = true)`) - waitForTableSplit(t, conn, "foo", "data") waitForReplicaFieldToBeSet(t, tc, conn, "foo", "data", func(r *kvserver.Replica) (bool, error) { if !r.ExcludeDataFromBackup() { - return false, errors.New("waiting for exclude_data_from_backup to be applied") + return false, errors.New("waiting for the range containing table data.foo to split") } return true, nil }) - waitForTableSplit(t, conn, "bar", "data") - sqlDB.Exec(t, `BACKUP DATABASE data TO $1`, localFoo) + waitForReplicaFieldToBeSet(t, tc, conn, "bar", "data", func(r *kvserver.Replica) (bool, error) { + if r.ExcludeDataFromBackup() { + return false, errors.New("waiting for the range containing table data.bar to split") + } + return true, nil + }) + sqlDB.Exec(t, `BACKUP DATABASE data INTO $1`, localFoo) - restoreDB.Exec(t, `RESTORE DATABASE data FROM $1`, localFoo) + restoreDB.Exec(t, `RESTORE DATABASE data FROM LATEST IN $1`, localFoo) require.Len(t, restoreDB.QueryStr(t, `SELECT * FROM data.foo`), 0) require.Len(t, restoreDB.QueryStr(t, `SELECT * FROM data.bar`), 10) }