Commit 955ccb95 authored by craig[bot]'s avatar craig[bot]

Merge #50759

50759: backupccl: fix bug when restoring cluster with empty db as highest id r=pbardea a=pbardea

Previously, there was a bug where cluster restore would fail when the
largest descriptor in the backup was a database. This commit fixes the
bug.

Fixes #50561.

Release note (bug fix): Previously, there was a bug where cluster
restore would fail when the largest descriptor in the backup was a
database. This is typically seen when the last action in backing up
cluster was a database creation.
Co-authored-by: default avatarPaul Bardea <[email protected]>
parents 0b65365f 1b539369
......@@ -277,6 +277,25 @@ func TestEmptyFullClusterRestore(t *testing.T) {
sqlDBRestore.CheckQueryResults(t, checkQuery, sqlDB.QueryStr(t, checkQuery))
}
// Regression test for #50561.
func TestClusterRestoreEmptyDB(t *testing.T) {
defer leaktest.AfterTest(t)()
const numAccounts = 10
_, _, sqlDB, tempDir, cleanupFn := BackupRestoreTestSetup(t, singleNode, numAccounts, InitNone)
_, _, sqlDBRestore, cleanupEmptyCluster := backupRestoreTestSetupEmpty(t, singleNode, tempDir, InitNone)
defer cleanupFn()
defer cleanupEmptyCluster()
sqlDB.Exec(t, `CREATE DATABASE some_db`)
sqlDB.Exec(t, `CREATE DATABASE some_db_2`)
sqlDB.Exec(t, `BACKUP TO $1`, LocalFoo)
sqlDBRestore.Exec(t, `RESTORE FROM $1`, LocalFoo)
checkQuery := "SHOW DATABASES"
sqlDBRestore.CheckQueryResults(t, checkQuery, sqlDB.QueryStr(t, checkQuery))
}
func TestDisallowFullClusterRestoreOnNonFreshCluster(t *testing.T) {
defer leaktest.AfterTest(t)()
......
......@@ -221,6 +221,13 @@ func allocateDescriptorRewrites(
}
}
// Include the database descriptors when calculating the max ID.
for _, database := range databasesByID {
if int64(database.ID) > maxDescIDInBackup {
maxDescIDInBackup = int64(database.ID)
}
}
// Include the type descriptors when calculating the max ID.
for _, typ := range typesByID {
if int64(typ.ID) > maxDescIDInBackup {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment