Skip to content

Commit

Permalink
ccl: add 23.2 version gate to regionless restore
Browse files Browse the repository at this point in the history
This patch adds a >= 23.2 version gate to the `remove_regions`
RESTORE option, in addition to a mixed-version test to ensure
that RESTORE fails fast if it is on a cluster version < 23.32.

Epic: none
Fixes: cockroachdb#111348
Part of: https://cockroachlabs.atlassian.net/browse/CRDB-29129

Release note (sql change): Clusters with versions < 23.2 are not able to use
the RESTORE option `remove_regions` (this feature has been version
gated).
  • Loading branch information
annrpom committed Oct 4, 2023
1 parent 1168035 commit 059f55f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/ccl/backupccl/datadriven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ var localityCfgs = map[string]roachpb.Locality{
var clusterVersionKeys = map[string]clusterversion.Key{
"23_1_Start": clusterversion.V23_1Start,
"23_1_MVCCTombstones": clusterversion.V23_1_MVCCRangeTombstonesUnconditionallyEnabled,
"23_2_Start": clusterversion.V23_2Start,
"23_2": clusterversion.V23_2,
}

type sqlDBKey struct {
Expand Down
5 changes: 5 additions & 0 deletions pkg/ccl/backupccl/restore_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,11 @@ func restorePlanHook(
return nil, nil, nil, false, err
}

if restoreStmt.Options.RemoveRegions && !p.ExecCfg().Settings.Version.IsActive(ctx, clusterversion.V23_2) {
return nil, nil, nil, false,
errors.Newf("to set the remove_regions option, cluster version must be >= %s", clusterversion.V23_2.String())
}

if !restoreStmt.Options.SchemaOnly && restoreStmt.Options.VerifyData {
return nil, nil, nil, false,
errors.New("to set the verify_backup_table_data option, the schema_only option must be set")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
new-cluster name=s1 beforeVersion=23_2_Start disable-tenant localities=us-east-1,us-west-1,eu-central-1
----

exec-sql
CREATE DATABASE d PRIMARY REGION "us-east-1" REGIONS "us-west-1", "eu-central-1";
CREATE TABLE d.t (x INT);
INSERT INTO d.t VALUES (1), (2), (3);
----

query-sql
SELECT region FROM [SHOW REGIONS FROM DATABASE d] ORDER BY 1;
----
eu-central-1
us-east-1
us-west-1

query-sql
SHOW DATABASES;
----
d root us-east-1 {eu-central-1,us-east-1,us-west-1} zone
data root <nil> <nil> {} <nil>
defaultdb root <nil> <nil> {} <nil>
postgres root <nil> <nil> {} <nil>
system node <nil> <nil> {} <nil>

# backup a cluster
exec-sql
BACKUP INTO 'nodelocal://1/cluster_backup/';
----

new-cluster name=s2 beforeVersion=23_2_Start share-io-dir=s1 disable-tenant
----

# restore fails when cluster is in mixed version state while upgrading to 23.2
exec-sql
RESTORE FROM LATEST IN 'nodelocal://1/cluster_backup/' WITH remove_regions;
----
pq: to set the remove_regions option, cluster version must be >= 1000023.1-26

# upgrade cluster
upgrade-cluster version=23_2
----

exec-sql
RESTORE DATABASE d FROM LATEST IN 'nodelocal://1/cluster_backup/' WITH remove_regions;
----

exec-sql
INSERT INTO d.t VALUES (4), (5);
----

query-sql
SELECT * FROM d.t
----
1
2
3
4
5

0 comments on commit 059f55f

Please sign in to comment.