Skip to content

Commit

Permalink
[WIP] backupccl: add feature flag support for backup command
Browse files Browse the repository at this point in the history
Adds a cluster setting to toggle a feature flag for the
BACKUP command off and on. It is being introduced to address a
Cockroach Cloud SRE use case of wanting to disable certain
categories of features in case of cluster failure.

Release note category, description TBD

Release note: None
  • Loading branch information
angelapwen committed Nov 11, 2020
1 parent 237284b commit d16438f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<tr><td><code>enterprise.license</code></td><td>string</td><td><code></code></td><td>the encoded cluster license</td></tr>
<tr><td><code>external.graphite.endpoint</code></td><td>string</td><td><code></code></td><td>if nonempty, push server metrics to the Graphite or Carbon server at the specified host:port</td></tr>
<tr><td><code>external.graphite.interval</code></td><td>duration</td><td><code>10s</code></td><td>the interval at which metrics are pushed to Graphite (if enabled)</td></tr>
<tr><td><code>feature.backup.enabled</code></td><td>boolean</td><td><code>true</code></td><td>set to true to enable backups, false to disable; default is true</td></tr>
<tr><td><code>jobs.retention_time</code></td><td>duration</td><td><code>336h0m0s</code></td><td>the amount of time to retain records for completed jobs before</td></tr>
<tr><td><code>kv.allocator.load_based_lease_rebalancing.enabled</code></td><td>boolean</td><td><code>true</code></td><td>set to enable rebalancing of range leases based on load and latency</td></tr>
<tr><td><code>kv.allocator.load_based_rebalancing</code></td><td>enumeration</td><td><code>leases and replicas</code></td><td>whether to rebalance based on the distribution of QPS across stores [off = 0, leases = 1, leases and replicas = 2]</td></tr>
Expand Down
13 changes: 13 additions & 0 deletions pkg/ccl/backupccl/backup_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/sql"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
Expand Down Expand Up @@ -79,6 +80,12 @@ type backupKMSEnv struct {

var _ cloud.KMSEnv = &backupKMSEnv{}

// featureBackupEnabled is used to enable and disable the BACKUP feature.
var featureBackupEnabled = settings.RegisterPublicBoolSetting(
"feature.backup.enabled",
"set to true to enable backups, false to disable; default is true",
true /* enabled by default */)

func (p *backupKMSEnv) ClusterSettings() *cluster.Settings {
return p.settings
}
Expand Down Expand Up @@ -501,6 +508,12 @@ func backupPlanHook(
return nil, nil, nil, false, nil
}

// Check whether feature backup is enabled or not.
if !featureBackupEnabled.Get(&p.ExecCfg().Settings.SV) {
return nil, nil, nil, false,
pgerror.Newf(pgcode.OperatorIntervention, "BACKUP feature was disabled by the database administrator.")
}

var err error
subdirFn := func() (string, error) { return "", nil }
if backupStmt.Subdir != nil {
Expand Down
22 changes: 22 additions & 0 deletions pkg/ccl/backupccl/testdata/backup-restore/feature-flags
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
new-server name=s1
----

# Test running backup when feature flag is disabled.
exec-sql
CREATE DATABASE d;
CREATE TABLE d.t (x INT);
INSERT INTO d.t VALUES (1), (2), (3);
----

# Cluster backup should fail.
exec-sql
SET CLUSTER SETTING feature.backup.enabled = FALSE;
BACKUP TO 'nodelocal://0/test-root/';
----
pq: BACKUP feature was disabled by the database administrator.

# Test running backup when feature flag is enabled.
exec-sql
SET CLUSTER SETTING feature.backup.enabled = TRUE;
BACKUP TO 'nodelocal://0/test-root/';
----

0 comments on commit d16438f

Please sign in to comment.