-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
60957: sql: add backup/restore tests for sequences r=the-ericwang35 a=the-ericwang35 This patch just adds tests for backup/restore with respect to sequences. Now that all new sequences are referenced by ID and can be renamed, we want to test that previously created sequences are not affected, and still follow the old rules (i.e. cannot be renamed and and are referenced by their names. Part of #51090 In the future, we'll want to convert these old sequences to new sequences (i.e. can be renamed and are referenced by ID, see #60942) which means these tests will need to change, but for now, we'll keep the old sequences as is. Release note (None): add backup/restore tests for sequences 60972: sql: error if SURVIVE is set with no regions r=ajstorm a=otan Release justification: bug fix to new functionality Release note: None 60993: colexec: remove duplication around bazel utility functions r=yuzefovich a=yuzefovich Previously, we had essentially duplicated `.bzl` files in two packages that need to generate code using `execgen`, but this can be avoided by defining a separate `.bzl` file as an extension used in both places. Release note: None 61008: TeamCity: update build agents to use the latest sudo r=rail a=rail Release note: None 61024: authors: add erikgrinaker r=erikgrinaker a=erikgrinaker Release note: none 61025: authors: add fqazi to authors r=fqazi a=fqazi authors: add fqazi to authors Release note: None 61026: authors: add abarganier to authors r=abarganier a=abarganier Release note: None Co-authored-by: Eric Wang <ericw@cockroachlabs.com> Co-authored-by: Oliver Tan <otan@cockroachlabs.com> Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com> Co-authored-by: Rail Aliiev <rail@iqchoice.com> Co-authored-by: Erik Grinaker <grinaker@cockroachlabs.com> Co-authored-by: Faizan Qazi <faizan@cockroachlabs.com> Co-authored-by: Alex Barganier <abarganier@cockroachlabs.com>
- Loading branch information
Showing
17 changed files
with
234 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package backupccl | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestRestoreOldVersions ensures that we can successfully restore tables | ||
// and databases exported by old version. | ||
// | ||
// The files being restored live in testdata and are all made from the same | ||
// input SQL which lives in <testdataBase>/create.sql. | ||
// | ||
// The SSTs were created via the following commands: | ||
// | ||
// VERSION=... | ||
// roachprod create local | ||
// roachprod wipe local | ||
// roachprod stage local release ${VERSION} | ||
// roachprod start local | ||
// roachprod sql local:1 -- -e "$(cat pkg/ccl/backupccl/testdata/restore_old_sequences/create.sql)" | ||
// roachprod sql local:1 -- -e "BACKUP DATABASE test TO 'nodelocal://1/backup'" | ||
// # Then grab the backups and put the files into the appropriate | ||
// # testdata directory. | ||
// | ||
func TestRestoreOldSequences(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
defer log.Scope(t).Close(t) | ||
const ( | ||
testdataBase = "testdata/restore_old_sequences" | ||
exportDirs = testdataBase + "/exports" | ||
) | ||
|
||
t.Run("sequences-restore", func(t *testing.T) { | ||
dirs, err := ioutil.ReadDir(exportDirs) | ||
require.NoError(t, err) | ||
for _, dir := range dirs { | ||
require.True(t, dir.IsDir()) | ||
exportDir, err := filepath.Abs(filepath.Join(exportDirs, dir.Name())) | ||
require.NoError(t, err) | ||
t.Run(dir.Name(), restoreOldSequencesTest(exportDir)) | ||
} | ||
}) | ||
} | ||
|
||
func restoreOldSequencesTest(exportDir string) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
params := base.TestServerArgs{} | ||
const numAccounts = 1000 | ||
_, _, sqlDB, dir, cleanup := backupRestoreTestSetupWithParams(t, singleNode, numAccounts, | ||
InitManualReplication, base.TestClusterArgs{ServerArgs: params}) | ||
defer cleanup() | ||
err := os.Symlink(exportDir, filepath.Join(dir, "foo")) | ||
require.NoError(t, err) | ||
sqlDB.Exec(t, `CREATE DATABASE test`) | ||
var unused string | ||
var importedRows int | ||
sqlDB.QueryRow(t, `RESTORE test.* FROM $1`, LocalFoo).Scan( | ||
&unused, &unused, &unused, &importedRows, &unused, &unused, | ||
) | ||
const totalRows = 3 | ||
if importedRows != totalRows { | ||
t.Fatalf("expected %d rows, got %d", totalRows, importedRows) | ||
} | ||
|
||
// Verify that sequences created in older versions cannot be renamed, nor can the | ||
// database they are referencing. | ||
sqlDB.ExpectErr(t, | ||
`pq: cannot rename relation "test.public.s" because view "t1" depends on it`, | ||
`ALTER SEQUENCE test.s RENAME TO test.s2`) | ||
sqlDB.ExpectErr(t, | ||
`pq: cannot rename relation "test.public.t1_i_seq" because view "t1" depends on it`, | ||
`ALTER SEQUENCE test.t1_i_seq RENAME TO test.t1_i_seq_new`) | ||
sqlDB.ExpectErr(t, | ||
`pq: cannot rename database because relation "test.public.t1" depends on relation "test.public.s"`, | ||
`ALTER DATABASE test RENAME TO new_test`) | ||
|
||
sequenceResults := [][]string{ | ||
{"1", "1"}, | ||
{"2", "2"}, | ||
} | ||
|
||
// Verify that tables with old sequences aren't corrupted. | ||
//sqlDB.Exec(t, `SET database = test`) | ||
//sqlDB.Exec(t, `USE test`) | ||
sqlDB.Exec(t, `SET database = test; INSERT INTO test.t1 VALUES (default, default)`) | ||
sqlDB.CheckQueryResults(t, `SELECT * FROM test.t1 ORDER BY i`, sequenceResults) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
pkg/ccl/backupccl/testdata/restore_old_sequences/create.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- The below SQL is used to create the data that is then exported with BACKUP | ||
-- for use in the RestoreOldSequences test. | ||
|
||
CREATE DATABASE test; | ||
|
||
SET database = test; | ||
|
||
-- t1 is a table with a SERIAL sequence and a DEFAULT value sequence. | ||
|
||
CREATE SEQUENCE s; | ||
|
||
SET serial_normalization = 'sql_sequence'; | ||
|
||
CREATE TABLE t1 (i SERIAL PRIMARY KEY, j INT NOT NULL DEFAULT nextval('test.public.s')); | ||
|
||
INSERT INTO t1 VALUES (default, default); | ||
|
Binary file added
BIN
+925 Bytes
pkg/ccl/backupccl/testdata/restore_old_sequences/exports/v20.2.5/635573714396577793.sst
Binary file not shown.
Binary file added
BIN
+925 Bytes
pkg/ccl/backupccl/testdata/restore_old_sequences/exports/v20.2.5/635573714396610561.sst
Binary file not shown.
Binary file added
BIN
+926 Bytes
pkg/ccl/backupccl/testdata/restore_old_sequences/exports/v20.2.5/635573714396643329.sst
Binary file not shown.
Empty file.
Binary file added
BIN
+1.06 KB
pkg/ccl/backupccl/testdata/restore_old_sequences/exports/v20.2.5/BACKUP_MANIFEST
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.