forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
40793: sql,sqlbase,client: bootstrap TableDescriptor timestamps from MVCC r=ajwerner a=ajwerner This PR adds back the changes in cockroachdb#40581 and deals with the fallout that led to cockroachdb#40781 in the 3rd commit. Release Justification: Fixes a bug formerly considered to be a release blocker. Co-authored-by: Andrew Werner <[email protected]>
- Loading branch information
Showing
79 changed files
with
861 additions
and
230 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2019 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_test | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"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 wipe local | ||
// roachprod stage local release ${VERSION} | ||
// roachprod start local | ||
// # If the version is v1.0.7 then you need to enable enterprise with the | ||
// # enterprise.enabled cluster setting. | ||
// roachprod sql local:1 -- -e "$(cat pkg/ccl/backupccl/testdata/restore_old_versions/create.sql)" | ||
// # Create an S3 bucket to store the backup. | ||
// roachprod sql local:1 -- -e "BACKUP DATABASE test TO 's3://<bucket-name>/${VERSION}?AWS_ACCESS_KEY_ID=<...>&AWS_SECRET_ACCESS_KEY=<...>'" | ||
// # Then download the backup from s3 and plop the files into the appropriate | ||
// # testdata directory. | ||
// | ||
func TestRestoreOldVersions(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
const ( | ||
testdataBase = "testdata/restore_old_versions" | ||
exportDirs = testdataBase + "/exports" | ||
) | ||
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(), restoreOldVersionTest(exportDir)) | ||
} | ||
} | ||
|
||
func restoreOldVersionTest(exportDir string) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
params := base.TestServerArgs{} | ||
const numAccounts = 1000 | ||
_, _, sqlDB, dir, cleanup := backupRestoreTestSetupWithParams(t, singleNode, numAccounts, | ||
initNone, 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, &unused, | ||
) | ||
const totalRows = 12 | ||
if importedRows != totalRows { | ||
t.Fatalf("expected %d rows, got %d", totalRows, importedRows) | ||
} | ||
results := [][]string{ | ||
{"1", "1", "1"}, | ||
{"2", "2", "2"}, | ||
{"3", "3", "3"}, | ||
} | ||
sqlDB.CheckQueryResults(t, `SELECT * FROM test.t1 ORDER BY k`, results) | ||
sqlDB.CheckQueryResults(t, `SELECT * FROM test.t2 ORDER BY k`, results) | ||
sqlDB.CheckQueryResults(t, `SELECT * FROM test.t4 ORDER BY k`, results) | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
pkg/ccl/backupccl/testdata/restore_old_versions/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,35 @@ | ||
-- The below SQL is used to create the data that is then exported with BACKUP | ||
-- for use in the RestoreOldVersions test. Each of t1, t2, and t3 should contain | ||
-- the same rows when ordered by k. | ||
|
||
CREATE DATABASE test; | ||
|
||
SET database = test; | ||
|
||
-- t1 gets some modifications. | ||
|
||
CREATE TABLE t1 (k INT8 PRIMARY KEY, v1 INT8); | ||
|
||
ALTER TABLE t1 ADD COLUMN v2 INT8; | ||
|
||
CREATE INDEX t1_v2 ON t1 (v2); | ||
|
||
-- t2 is an unmodified table. | ||
|
||
CREATE TABLE t2 (k INT8 PRIMARY KEY, v1 INT8, v2 INT8); | ||
|
||
-- t3 and t4 are interleaved. | ||
|
||
CREATE TABLE t3 (k INT8 PRIMARY KEY); | ||
|
||
CREATE TABLE t4 (k INT8 PRIMARY KEY, v1 INT8, v2 INT8, CONSTRAINT fk_t3 FOREIGN KEY (k) REFERENCES t3) | ||
INTERLEAVE IN PARENT t3 (k); | ||
|
||
INSERT INTO t1 VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3); | ||
|
||
INSERT INTO t2 VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3); | ||
|
||
INSERT INTO t3 VALUES (1), (2), (3); | ||
|
||
INSERT INTO t4 VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3); | ||
|
Binary file added
BIN
+945 Bytes
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v1.0.7/486711033700122625.sst
Binary file not shown.
Binary file added
BIN
+945 Bytes
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v1.0.7/486711033700253697.sst
Binary file not shown.
Binary file added
BIN
+2.87 KB
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v1.0.7/486711033700483073.sst
Binary file not shown.
Binary file added
BIN
+936 Bytes
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v1.0.7/486711033700843521.sst
Binary file not shown.
Binary file added
BIN
+986 Bytes
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v1.0.7/486711033757466625.sst
Binary file not shown.
Binary file added
BIN
+1.51 KB
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v1.0.7/BACKUP
Binary file not shown.
Binary file added
BIN
+945 Bytes
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v1.1.9/486711187401211905.sst
Binary file not shown.
Binary file added
BIN
+945 Bytes
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v1.1.9/486711187490635777.sst
Binary file not shown.
Binary file added
BIN
+936 Bytes
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v1.1.9/486711187725058049.sst
Binary file not shown.
Binary file added
BIN
+986 Bytes
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v1.1.9/486711187746521089.sst
Binary file not shown.
Binary file added
BIN
+3.18 KB
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v1.1.9/486711187748749313.sst
Binary file not shown.
Binary file added
BIN
+2.07 KB
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v1.1.9/BACKUP
Binary file not shown.
Binary file added
BIN
+1.63 KB
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v1.1.9/BACKUP-CHECKPOINT
Binary file not shown.
Binary file added
BIN
+846 Bytes
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v19.1.4/486711494153863169.sst
Binary file not shown.
Binary file added
BIN
+846 Bytes
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v19.1.4/486711494249414657.sst
Binary file not shown.
Binary file added
BIN
+837 Bytes
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v19.1.4/486711494320259073.sst
Binary file not shown.
Binary file added
BIN
+889 Bytes
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v19.1.4/486711494785302529.sst
Binary file not shown.
Binary file added
BIN
+1.69 KB
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v19.1.4/BACKUP
Binary file not shown.
Binary file added
BIN
+1.02 KB
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v2.0.7/486711288918671361.sst
Binary file not shown.
Binary file added
BIN
+1005 Bytes
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v2.0.7/486711288998658049.sst
Binary file not shown.
Binary file added
BIN
+996 Bytes
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v2.0.7/486711289118064641.sst
Binary file not shown.
Binary file added
BIN
+1005 Bytes
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v2.0.7/486711289209061377.sst
Binary file not shown.
Binary file added
BIN
+1.66 KB
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v2.0.7/BACKUP
Binary file not shown.
Binary file added
BIN
+1.1 KB
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v2.1.8/486711390409097217.sst
Binary file not shown.
Binary file added
BIN
+1.09 KB
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v2.1.8/486711390490296321.sst
Binary file not shown.
Binary file added
BIN
+1.1 KB
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v2.1.8/486711390560256001.sst
Binary file not shown.
Binary file added
BIN
+1.14 KB
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v2.1.8/486711390640865281.sst
Binary file not shown.
Binary file added
BIN
+1.66 KB
pkg/ccl/backupccl/testdata/restore_old_versions/exports/v2.1.8/BACKUP
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 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.