Skip to content

Commit

Permalink
schemachanger: add zone config interfaces/functions in builder
Browse files Browse the repository at this point in the history
This patch adds the necessary interfaces/functions for
zone config verification and retrieval.

Informs: cockroachdb#117574
Release note: None
  • Loading branch information
annrpom committed May 29, 2024
1 parent cbca2d8 commit a3015a4
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 5 deletions.
5 changes: 5 additions & 0 deletions pkg/sql/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,11 @@ func (p *planner) TemporarySchemaName() string {
return temporarySchemaName(p.ExtendedEvalContext().SessionID)
}

// GetRegions implements scbuildstmt.GetRegions.
func (p *planner) GetRegions(ctx context.Context) (*serverpb.RegionsResponse, error) {
return p.regionsProvider().GetRegions(ctx)
}

// DistSQLPlanner returns the DistSQLPlanner
func (p *planner) DistSQLPlanner() *DistSQLPlanner {
return p.extendedEvalCtx.DistSQLPlanner
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/schema_change_plan_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (p *planner) newSchemaChangeBuilderDependencies(statements []string) scbuil
NewReferenceProviderFactory(p),
p.EvalContext().DescIDGenerator,
p,
p.ExecCfg().NodesStatusServer,
)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/sql/schemachanger/scbuild/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ type buildCtx struct {
scbuildstmt.TreeAnnotator
scbuildstmt.SchemaFeatureChecker
TemporarySchemaProvider
RegionProvider
}

var _ scbuildstmt.BuildCtx = buildCtx{}
Expand Down
6 changes: 2 additions & 4 deletions pkg/sql/schemachanger/scbuild/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type Dependencies interface {
DescriptorCommentGetter() CommentGetter

// ZoneConfigGetter returns a zone config reader.
ZoneConfigGetter() ZoneConfigGetter
ZoneConfigGetter() scdecomp.ZoneConfigGetter

// ClientNoticeSender returns a eval.ClientNoticeSender.
ClientNoticeSender() eval.ClientNoticeSender
Expand Down Expand Up @@ -217,9 +217,6 @@ type AstFormatter interface {
FormatAstAsRedactableString(statement tree.Statement, annotations *tree.Annotations) redact.RedactableString
}

// ZoneConfigGetter see scdecomp.ZoneConfigGetter.
type ZoneConfigGetter scdecomp.ZoneConfigGetter

// CommentGetter see scdecomp.CommentGetter.
type CommentGetter scdecomp.CommentGetter

Expand Down Expand Up @@ -265,4 +262,5 @@ type (
FeatureChecker = scbuildstmt.SchemaFeatureChecker

TemporarySchemaProvider = scbuildstmt.TemporarySchemaProvider
RegionProvider = scbuildstmt.RegionProvider
)
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ go_library(
"//pkg/geo/geoindex",
"//pkg/keys",
"//pkg/security/username",
"//pkg/server/serverpb",
"//pkg/server/telemetry",
"//pkg/settings",
"//pkg/settings/cluster",
Expand Down
19 changes: 19 additions & 0 deletions pkg/sql/schemachanger/scbuild/internal/scbuildstmt/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import (

"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/security/username"
"github.com/cockroachdb/cockroach/pkg/server/serverpb"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scdecomp"
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb"
"github.com/cockroachdb/cockroach/pkg/sql/sem/catid"
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
Expand All @@ -43,6 +45,7 @@ type BuildCtx interface {
TreeAnnotator
TreeContextBuilder
Telemetry
RegionProvider

// Add adds an absent element to the BuilderState, targeting PUBLIC.
Add(element scpb.Element)
Expand All @@ -60,6 +63,9 @@ type BuildCtx interface {

// Codec returns the codec for the current tenant.
Codec() keys.SQLCodec

// ZoneConfigGetter returns the zone config getter.
ZoneConfigGetter() scdecomp.ZoneConfigGetter
}

// ClusterAndSessionInfo provides general cluster and session info.
Expand All @@ -70,6 +76,10 @@ type ClusterAndSessionInfo interface {

// SessionData returns the current session data, as in execCtx.
SessionData() *sessiondata.SessionData

// NodesStatusServer gives access to the NodesStatus service and is only
// available when running as a system tenant.
NodesStatusServer() *serverpb.OptionalNodesStatusServer
}

// BuilderState encapsulates the state of the planned schema changes, hiding
Expand Down Expand Up @@ -443,3 +453,12 @@ type TemporarySchemaProvider interface {
// session.
TemporarySchemaName() string
}

// RegionProvider abstracts the lookup of regions. It is used to implement
// crdb_internal.regions, which ultimately drives `SHOW REGIONS` and the
// logic in the commands to manipulate multi-region features.
type RegionProvider interface {
// GetRegions provides access to the set of regions available to the
// current tenant.
GetRegions(ctx context.Context) (*serverpb.RegionsResponse, error)
}
2 changes: 2 additions & 0 deletions pkg/sql/schemachanger/scdeps/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ go_library(
"//pkg/kv",
"//pkg/roachpb",
"//pkg/security/username",
"//pkg/server/serverpb",
"//pkg/server/telemetry",
"//pkg/settings/cluster",
"//pkg/sql/catalog",
Expand All @@ -29,6 +30,7 @@ go_library(
"//pkg/sql/isql",
"//pkg/sql/rowenc",
"//pkg/sql/schemachanger/scbuild",
"//pkg/sql/schemachanger/scdecomp",
"//pkg/sql/schemachanger/scexec",
"//pkg/sql/schemachanger/scexec/backfiller",
"//pkg/sql/schemachanger/scexec/scmutationexec",
Expand Down
12 changes: 11 additions & 1 deletion pkg/sql/schemachanger/scdeps/build_deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/server/serverpb"
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
Expand All @@ -26,6 +27,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/catalog/resolver"
"github.com/cockroachdb/cockroach/pkg/sql/rowenc"
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scbuild"
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scdecomp"
"github.com/cockroachdb/cockroach/pkg/sql/sem/catconstants"
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
Expand Down Expand Up @@ -56,6 +58,7 @@ func NewBuilderDependencies(
referenceProviderFactory scbuild.ReferenceProviderFactory,
descIDGenerator eval.DescIDGenerator,
temporarySchemaProvider scbuild.TemporarySchemaProvider,
nodesStatusServer serverpb.OptionalNodesStatusServer,
) scbuild.Dependencies {
return &buildDeps{
clusterID: clusterID,
Expand All @@ -76,6 +79,7 @@ func NewBuilderDependencies(
descIDGenerator: descIDGenerator,
referenceProviderFactory: referenceProviderFactory,
temporarySchemaProvider: temporarySchemaProvider,
nodesStatusServer: nodesStatusServer,
}
}

Expand All @@ -96,6 +100,7 @@ type buildDeps struct {
referenceProviderFactory scbuild.ReferenceProviderFactory
descIDGenerator eval.DescIDGenerator
temporarySchemaProvider scbuild.TemporarySchemaProvider
nodesStatusServer serverpb.OptionalNodesStatusServer
}

var _ scbuild.CatalogReader = (*buildDeps)(nil)
Expand Down Expand Up @@ -360,6 +365,11 @@ func (d *buildDeps) ClusterSettings() *cluster.Settings {
return d.settings
}

// NodesStatusServer implements the scbuild.Dependencies interface.
func (d *buildDeps) NodesStatusServer() *serverpb.OptionalNodesStatusServer {
return &d.nodesStatusServer
}

// Statements implements the scbuild.Dependencies interface.
func (d *buildDeps) Statements() []string {
return d.statements
Expand Down Expand Up @@ -455,7 +465,7 @@ func (d *buildDeps) DescriptorCommentGetter() scbuild.CommentGetter {
return d.descsCollection
}

func (d *buildDeps) ZoneConfigGetter() scbuild.ZoneConfigGetter {
func (d *buildDeps) ZoneConfigGetter() scdecomp.ZoneConfigGetter {
return &zoneConfigGetter{
txn: d.txn,
descriptors: d.descsCollection,
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/schemachanger/scdeps/sctestutils/sctestutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func WithBuilderDependenciesFromTestServer(
refProviderFactory,
descidgen.NewGenerator(s.ClusterSettings(), s.Codec(), s.DB()),
planner,
execCfg.NodesStatusServer,
))
}

Expand Down

0 comments on commit a3015a4

Please sign in to comment.