Skip to content

Commit

Permalink
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
8 people committed Feb 23, 2021
8 parents b1d518f + 72692ef + 7bc9782 + aa343ff + 5519afb + 9e2d142 + bf563bc + 00e2981 commit e9f5f8c
Show file tree
Hide file tree
Showing 17 changed files with 234 additions and 123 deletions.
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Aditya Maru <adityamaru@gmail.com> <@cockroachlabs.com>
Aid Idrizović <idrizovicaid@gmail.com>
Ajaya Agrawal <ajku.agr@gmail.com>
Alan Acosta <acostas.alan@gmail.com>
Alex Barganier <abarganier@cockroachlabs.com>
Alex Gaynor <alex.gaynor@gmail.com>
Alex Lunev <lunevalex@gmail.com> <alexl@cockroachlabs.com>
Alex Robinson <alexdwanerobinson@gmail.com> <arob@google.com> <@cockroachlabs.com>
Expand Down Expand Up @@ -119,10 +120,12 @@ embark <wolfire9@users.noreply.github.com>
Emmanuel Sales <absolutezero2a03@gmail.com> Emmanuel <absolutezero2a03@gmail.com> <emsal1863@gmail.com> <@cockroachlabs.com>
Ernie Cordeiro <ernie@cockroachlabs.com>
Eric Wang <ericw@cockroachlabs.com>
Erik Grinaker <grinaker@cockroachlabs.com>
Erik Trinh <erik@cockroachlabs.com>
es-chow <es-chow@users.noreply.github.com> <es_chow@163.com>
Evgeniy Vasilev <aquilax@gmail.com>
fabio <fabio@cockroachlabs.com>
Faizan Qazi <faizan@cockroachlabs.com> <faizanqazi@gmail.com>
fangwens <pananc@126.com>
Francis Bergin <bergin.francis@gmail.com>
funkygao <funky.gao@gmail.com>
Expand Down
5 changes: 3 additions & 2 deletions build/packer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Each `.json` file is a packer template.
```bash
brew install packer
```
2. Run:
2. Configure `gcloud` with your personal [User Application Default Credentials][gauth].
3. Run:
```bash
packer build <VM_TEMPLATE>.json
```
Expand All @@ -30,4 +31,4 @@ the `gcloud` tool or provide your Google Cloud JSON credentials in a
[Packer]: https://www.packer.io
[gauth]: https://www.packer.io/docs/builders/googlecompute.html#running-without-a-compute-engine-service-account
[gauth]: https://www.packer.io/docs/builders/googlecompute#running-locally-on-your-workstation
3 changes: 3 additions & 0 deletions build/packer/teamcity-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ add-apt-repository ppa:longsleep/golang-backports
add-apt-repository ppa:git-core/ppa
apt-get update --yes

# Install the sudo version patched for CVE-2021-3156
apt-get install --yes sudo

# Install the necessary dependencies. Keep this list small!
apt-get install --yes \
docker-ce \
Expand Down
1 change: 1 addition & 0 deletions pkg/ccl/backupccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ go_test(
"main_test.go",
"partitioned_backup_test.go",
"restore_mid_schema_change_test.go",
"restore_old_sequences_test.go",
"restore_old_versions_test.go",
"show_test.go",
"split_and_scatter_processor_test.go",
Expand Down
104 changes: 104 additions & 0 deletions pkg/ccl/backupccl/restore_old_sequences_test.go
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 pkg/ccl/backupccl/testdata/restore_old_sequences/create.sql
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 not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
57 changes: 54 additions & 3 deletions pkg/sql/colexec/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load(":COLEXEC.bzl", "eg_go_filegroup", "gen_eg_go_rules")
load("//pkg/sql/colexecbase:EXECGEN.bzl", "eg_go_filegroup", "gen_eg_go_rules")

go_library(
name = "colexec",
Expand Down Expand Up @@ -211,8 +211,59 @@ go_test(
],
)

# Map between target name and relevant template.
targets = [
("and_or_projection.eg.go", "and_or_projection_tmpl.go"),
("cast.eg.go", "cast_tmpl.go"),
("const.eg.go", "const_tmpl.go"),
("crossjoiner.eg.go", "crossjoiner_tmpl.go"),
("default_cmp_expr.eg.go", "default_cmp_expr_tmpl.go"),
("default_cmp_proj_ops.eg.go", "default_cmp_proj_ops_tmpl.go"),
("default_cmp_sel_ops.eg.go", "default_cmp_sel_ops_tmpl.go"),
("distinct.eg.go", "distinct_tmpl.go"),
("hash_aggregator.eg.go", "hash_aggregator_tmpl.go"),
("hash_utils.eg.go", "hash_utils_tmpl.go"),
("hashjoiner.eg.go", "hashjoiner_tmpl.go"),
("hashtable_distinct.eg.go", "hashtable_tmpl.go"),
("hashtable_full_default.eg.go", "hashtable_tmpl.go"),
("hashtable_full_deleting.eg.go", "hashtable_tmpl.go"),
("is_null_ops.eg.go", "is_null_ops_tmpl.go"),
("mergejoinbase.eg.go", "mergejoinbase_tmpl.go"),
("mergejoiner_exceptall.eg.go", "mergejoiner_tmpl.go"),
("mergejoiner_fullouter.eg.go", "mergejoiner_tmpl.go"),
("mergejoiner_inner.eg.go", "mergejoiner_tmpl.go"),
("mergejoiner_intersectall.eg.go", "mergejoiner_tmpl.go"),
("mergejoiner_leftanti.eg.go", "mergejoiner_tmpl.go"),
("mergejoiner_leftouter.eg.go", "mergejoiner_tmpl.go"),
("mergejoiner_leftsemi.eg.go", "mergejoiner_tmpl.go"),
("mergejoiner_rightanti.eg.go", "mergejoiner_tmpl.go"),
("mergejoiner_rightouter.eg.go", "mergejoiner_tmpl.go"),
("mergejoiner_rightsemi.eg.go", "mergejoiner_tmpl.go"),
("ordered_synchronizer.eg.go", "ordered_synchronizer_tmpl.go"),
("proj_const_left_ops.eg.go", "proj_const_ops_tmpl.go"),
("proj_const_right_ops.eg.go", "proj_const_ops_tmpl.go"),
("proj_like_ops.eg.go", "proj_const_ops_tmpl.go"),
("proj_non_const_ops.eg.go", "proj_non_const_ops_tmpl.go"),
("quicksort.eg.go", "quicksort_tmpl.go"),
("rank.eg.go", "rank_tmpl.go"),
("relative_rank.eg.go", "relative_rank_tmpl.go"),
("row_number.eg.go", "row_number_tmpl.go"),
("rowstovec.eg.go", "rowstovec_tmpl.go"),
("select_in.eg.go", "select_in_tmpl.go"),
("selection_ops.eg.go", "selection_ops_tmpl.go"),
("sel_like_ops.eg.go", "selection_ops_tmpl.go"),
("sort.eg.go", "sort_tmpl.go"),
("substring.eg.go", "substring_tmpl.go"),
("values_differ.eg.go", "values_differ_tmpl.go"),
("vec_comparators.eg.go", "vec_comparators_tmpl.go"),
("window_peer_grouper.eg.go", "window_peer_grouper_tmpl.go"),
]

# Define a file group for all the .eg.go targets.
eg_go_filegroup(name = "gen-exec")
eg_go_filegroup(
name = "gen-exec",
targets = targets,
)

# Define gen rules for individual eg.go files.
gen_eg_go_rules()
gen_eg_go_rules(targets)
85 changes: 0 additions & 85 deletions pkg/sql/colexec/COLEXEC.bzl

This file was deleted.

31 changes: 28 additions & 3 deletions pkg/sql/colexec/colexecagg/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load(":COLEXECAGG.bzl", "eg_go_filegroup", "gen_eg_go_rules")
load("//pkg/sql/colexecbase:EXECGEN.bzl", "eg_go_filegroup", "gen_eg_go_rules")

go_library(
name = "colexecagg",
Expand Down Expand Up @@ -30,8 +30,33 @@ go_library(
],
)

# Map between target name and relevant template.
targets = [
("hash_any_not_null_agg.eg.go", "any_not_null_agg_tmpl.go"),
("hash_avg_agg.eg.go", "avg_agg_tmpl.go"),
("hash_bool_and_or_agg.eg.go", "bool_and_or_agg_tmpl.go"),
("hash_concat_agg.eg.go", "concat_agg_tmpl.go"),
("hash_count_agg.eg.go", "count_agg_tmpl.go"),
("hash_default_agg.eg.go", "default_agg_tmpl.go"),
("hash_min_max_agg.eg.go", "min_max_agg_tmpl.go"),
("hash_sum_agg.eg.go", "sum_agg_tmpl.go"),
("hash_sum_int_agg.eg.go", "sum_agg_tmpl.go"),
("ordered_any_not_null_agg.eg.go", "any_not_null_agg_tmpl.go"),
("ordered_avg_agg.eg.go", "avg_agg_tmpl.go"),
("ordered_bool_and_or_agg.eg.go", "bool_and_or_agg_tmpl.go"),
("ordered_concat_agg.eg.go", "concat_agg_tmpl.go"),
("ordered_count_agg.eg.go", "count_agg_tmpl.go"),
("ordered_default_agg.eg.go", "default_agg_tmpl.go"),
("ordered_min_max_agg.eg.go", "min_max_agg_tmpl.go"),
("ordered_sum_agg.eg.go", "sum_agg_tmpl.go"),
("ordered_sum_int_agg.eg.go", "sum_agg_tmpl.go"),
]

# Define a file group for all the .eg.go targets.
eg_go_filegroup(name = "gen-exec")
eg_go_filegroup(
name = "gen-exec",
targets = targets,
)

# Define gen rules for individual eg.go files.
gen_eg_go_rules()
gen_eg_go_rules(targets)
Loading

0 comments on commit e9f5f8c

Please sign in to comment.