Skip to content

Commit

Permalink
server: use a single setting for tenant waiting
Browse files Browse the repository at this point in the history
We can use a zero-wait time to indicate no waiting, saving a cluster
setting.

Epic: none

Release note: None
  • Loading branch information
stevendanna committed Nov 6, 2023
1 parent 2c7571b commit aeffaed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
16 changes: 3 additions & 13 deletions pkg/multitenant/tenant_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,12 @@ var VerifyTenantService = settings.RegisterBoolSetting(
settings.WithName(DefaultClusterSelectSettingName+".check_service.enabled"),
)

// WaitForClusterStart, if enabled, instructs the tenant controller to
// wait up to WaitForClusterStartTimeout for the defuault virtual
// cluster to have an active SQL server.
var WaitForClusterStart = settings.RegisterBoolSetting(
settings.SystemOnly,
"server.controller.mux_virtual_cluster_wait.enabled",
"wait up to server.controller_mux_virtual_cluster_wait.timeout for the default virtual cluster to become available for SQL connections",
false,
)

// WaitForClusterStartTimeout is the amoutn of time the the tenant
// WaitForClusterStartTimeout is the amount of time the tenant
// controller will wait for the default virtual cluster to have an
// active SQL server, if WaitForClusterStart is true.
// active SQL server.
var WaitForClusterStartTimeout = settings.RegisterDurationSetting(
settings.SystemOnly,
"server.controller.mux_virtual_cluster_wait.timeout",
"amount of time to wait for a default virtual cluster to become available when serving SQL connections",
"amount of time to wait for a default virtual cluster to become available when serving SQL connections (0 to disable)",
10*time.Second,
)
2 changes: 1 addition & 1 deletion pkg/server/server_controller_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (c *serverController) shouldWaitForTenantServer(name roachpb.TenantName) bo
return false
}

return multitenant.WaitForClusterStart.Get(&c.st.SV)
return multitenant.WaitForClusterStartTimeout.Get(&c.st.SV) > 0
}

func (c *serverController) waitForTenantServer(
Expand Down
5 changes: 4 additions & 1 deletion pkg/server/server_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/errors"
Expand Down Expand Up @@ -138,7 +139,9 @@ func TestServerControllerWaitForDefaultCluster(t *testing.T) {
defer s.Stopper().Stop(ctx)

sqlRunner := sqlutils.MakeSQLRunner(db)
sqlRunner.Exec(t, "SET CLUSTER SETTING server.controller.mux_virtual_cluster_wait.enabled = true")
if util.RaceEnabled {
sqlRunner.Exec(t, "SET CLUSTER SETTING server.controller.mux_virtual_cluster_wait.timeout = '1m'")
}

tryConnect := func() error {
conn, err := s.SystemLayer().SQLConnE(serverutils.DBName("cluster:hello"))
Expand Down

0 comments on commit aeffaed

Please sign in to comment.