Skip to content

Commit

Permalink
democluster: fix `cockroach demo movr --geo-partitioned-replicas --mu…
Browse files Browse the repository at this point in the history
…lti-region`

When using `--geo-partitioned-replicas`, some secondary regions are
added, which is only supported with multitenancy if a cluster setting
is also set. So this commit ensures the cluster setting is set.

NB: no unit tests in this commit because the next commit will ensure
this gets tested.

Release note: None
  • Loading branch information
knz committed May 24, 2022
1 parent 48e48db commit 3965a6c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/cli/democluster/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ go_library(
"//pkg/server/pgurl",
"//pkg/server/serverpb",
"//pkg/server/status",
"//pkg/sql",
"//pkg/sql/catalog/catalogkeys",
"//pkg/sql/distsql",
"//pkg/sql/sem/catconstants",
Expand Down
30 changes: 29 additions & 1 deletion pkg/cli/democluster/demo_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/server/pgurl"
"github.com/cockroachdb/cockroach/pkg/server/serverpb"
"github.com/cockroachdb/cockroach/pkg/server/status"
"github.com/cockroachdb/cockroach/pkg/sql"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys"
"github.com/cockroachdb/cockroach/pkg/sql/distsql"
"github.com/cockroachdb/cockroach/pkg/sql/sem/catconstants"
Expand Down Expand Up @@ -1175,10 +1176,37 @@ func (c *transientCluster) GetSQLCredentials() (
return c.adminUser, c.adminPassword, c.demoDir
}

func (c *transientCluster) maybeEnableMultiTenantMultiRegion(ctx context.Context) error {
if !c.demoCtx.Multitenant {
return nil
}

storageURL, err := c.getNetworkURLForServer(ctx, 0, false /* includeAppName */, false /* isTenant */)
if err != nil {
return err
}
db, err := gosql.Open("postgres", storageURL.ToPQ().String())
if err != nil {
return err
}
defer db.Close()

if _, err = db.Exec(`ALTER TENANT ALL SET CLUSTER SETTING ` +
sql.SecondaryTenantsMultiRegionAbstractionsEnabledSettingName + " = true"); err != nil {
return err
}

return nil
}

func (c *transientCluster) SetupWorkload(ctx context.Context, licenseDone <-chan error) error {
gen := c.demoCtx.WorkloadGenerator
if err := c.maybeEnableMultiTenantMultiRegion(ctx); err != nil {
return err
}

// If there is a load generator, create its database and load its
// fixture.
gen := c.demoCtx.WorkloadGenerator
if gen != nil {
db, err := gosql.Open("postgres", c.connURL)
if err != nil {
Expand Down

0 comments on commit 3965a6c

Please sign in to comment.