Skip to content

Commit

Permalink
sql,sql/schemachanger/scdeps,scexec: rename IndexValidator to Validator
Browse files Browse the repository at this point in the history
This PR renames `IndexValidator` in package `scexec` to `Validator`
because we are going to enable it to validate a check constraint in the
next few commits.
  • Loading branch information
Xiang-Gu committed Oct 10, 2022
1 parent eb84eba commit 239786a
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion pkg/server/server_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ func newSQLServer(ctx context.Context, cfg sqlServerArgs) (*SQLServer, error) {
jobRegistry.SetInternalExecutorFactory(ieFactory)
execCfg.IndexBackfiller = sql.NewIndexBackfiller(execCfg)
execCfg.IndexMerger = sql.NewIndexBackfillerMergePlanner(execCfg)
execCfg.IndexValidator = scdeps.NewIndexValidator(
execCfg.Validator = scdeps.NewValidator(
execCfg.DB,
execCfg.Codec,
execCfg.Settings,
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/exec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1257,8 +1257,8 @@ type ExecutorConfig struct {
// IndexMerger is also used to backfill indexes and is also rather circular.
IndexMerger *IndexBackfillerMergePlanner

// IndexValidator is used to validate indexes.
IndexValidator scexec.IndexValidator
// Validator is used to validate indexes and check constraints.
Validator scexec.Validator

// ContentionRegistry is a node-level registry of contention events used for
// contention observability.
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/schema_change_plan_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func newSchemaChangerTxnRunDependencies(
// nothing to save because nobody will ever try to resume.
scdeps.NewNoOpBackfillerTracker(execCfg.Codec),
scdeps.NewNoopPeriodicProgressFlusher(),
execCfg.IndexValidator,
execCfg.Validator,
scdeps.NewConstantClock(evalContext.GetTxnTimestamp(time.Microsecond).Time),
metaDataUpdater,
NewSchemaChangerEventLogger(txn, execCfg, 1),
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/schemachanger/scdeps/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ go_library(
srcs = [
"build_deps.go",
"exec_deps.go",
"index_validator.go",
"run_deps.go",
"validator.go",
],
importpath = "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scdeps",
visibility = ["//visibility:public"],
Expand Down
10 changes: 5 additions & 5 deletions pkg/sql/schemachanger/scdeps/exec_deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewExecutorDependencies(
merger scexec.Merger,
backfillTracker scexec.BackfillerTracker,
backfillFlusher scexec.PeriodicProgressFlusher,
indexValidator scexec.IndexValidator,
validator scexec.Validator,
clock scmutationexec.Clock,
metadataUpdater scexec.DescriptorMetadataUpdater,
eventLogger scexec.EventLogger,
Expand All @@ -79,7 +79,7 @@ func NewExecutorDependencies(
codec: codec,
descsCollection: descsCollection,
jobRegistry: jobRegistry,
indexValidator: indexValidator,
validator: validator,
eventLogger: eventLogger,
statsRefresher: statsRefresher,
schemaChangerJobID: schemaChangerJobID,
Expand All @@ -105,7 +105,7 @@ type txnDeps struct {
descsCollection *descs.Collection
jobRegistry JobRegistry
createdJobs []jobspb.JobID
indexValidator scexec.IndexValidator
validator scexec.Validator
statsRefresher scexec.StatsRefresher
tableStatsToRefresh []descpb.ID
eventLogger scexec.EventLogger
Expand Down Expand Up @@ -395,8 +395,8 @@ func (d *execDeps) PeriodicProgressFlusher() scexec.PeriodicProgressFlusher {
return d.periodicProgressFlusher
}

func (d *execDeps) IndexValidator() scexec.IndexValidator {
return d.indexValidator
func (d *execDeps) Validator() scexec.Validator {
return d.validator
}

// IndexSpanSplitter implements the scexec.Dependencies interface.
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/schemachanger/scdeps/run_deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewJobRunDependencies(
job *jobs.Job,
codec keys.SQLCodec,
settings *cluster.Settings,
indexValidator scexec.IndexValidator,
indexValidator scexec.Validator,
metadataUpdaterFactory MetadataUpdaterFactory,
statsRefresher scexec.StatsRefresher,
testingKnobs *scexec.TestingKnobs,
Expand Down Expand Up @@ -87,7 +87,7 @@ type jobExecutionDeps struct {
job *jobs.Job
kvTrace bool

indexValidator scexec.IndexValidator
indexValidator scexec.Validator

codec keys.SQLCodec
settings *cluster.Settings
Expand Down Expand Up @@ -117,7 +117,7 @@ func (d *jobExecutionDeps) WithTxnInJob(ctx context.Context, fn scrun.JobTxnFunc
codec: d.codec,
descsCollection: descriptors,
jobRegistry: d.jobRegistry,
indexValidator: d.indexValidator,
validator: d.indexValidator,
eventLogger: d.eventLoggerFactory(txn),
statsRefresher: d.statsRefresher,
schemaChangerJobID: d.job.ID(),
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/schemachanger/scdeps/sctestdeps/test_deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ func (s *TestState) WithTxnInJob(ctx context.Context, fn scrun.JobTxnFunc) (err
return err
}

// ValidateForwardIndexes implements the index validator interface.
// ValidateForwardIndexes implements the validator interface.
func (s *TestState) ValidateForwardIndexes(
_ context.Context,
tbl catalog.TableDescriptor,
Expand All @@ -950,7 +950,7 @@ func (s *TestState) ValidateForwardIndexes(
return nil
}

// ValidateInvertedIndexes implements the index validator interface.
// ValidateInvertedIndexes implements the validator interface.
func (s *TestState) ValidateInvertedIndexes(
_ context.Context,
tbl catalog.TableDescriptor,
Expand All @@ -965,8 +965,8 @@ func (s *TestState) ValidateInvertedIndexes(
return nil
}

// IndexValidator implements the scexec.Dependencies interface.
func (s *TestState) IndexValidator() scexec.IndexValidator {
// Validator implements the scexec.Dependencies interface.
func (s *TestState) Validator() scexec.Validator {
return s
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type ValidateInvertedIndexesFn func(
// for the internal executor.
type NewFakeSessionDataFn func(sv *settings.Values) *sessiondata.SessionData

type indexValidator struct {
type validator struct {
db *kv.DB
codec keys.SQLCodec
settings *cluster.Settings
Expand All @@ -61,7 +61,7 @@ type indexValidator struct {
}

// ValidateForwardIndexes checks that the indexes have entries for all the rows.
func (iv indexValidator) ValidateForwardIndexes(
func (vd validator) ValidateForwardIndexes(
ctx context.Context,
tbl catalog.TableDescriptor,
indexes []catalog.Index,
Expand All @@ -70,14 +70,14 @@ func (iv indexValidator) ValidateForwardIndexes(

const withFirstMutationPublic = true
const gatherAllInvalid = false
return iv.validateForwardIndexes(
ctx, tbl, indexes, iv.makeHistoricalInternalExecTxnRunner(),
return vd.validateForwardIndexes(
ctx, tbl, indexes, vd.makeHistoricalInternalExecTxnRunner(),
withFirstMutationPublic, gatherAllInvalid, override,
)
}

// ValidateInvertedIndexes checks that the indexes have entries for all the rows.
func (iv indexValidator) ValidateInvertedIndexes(
func (vd validator) ValidateInvertedIndexes(
ctx context.Context,
tbl catalog.TableDescriptor,
indexes []catalog.Index,
Expand All @@ -86,39 +86,39 @@ func (iv indexValidator) ValidateInvertedIndexes(

const withFirstMutationPublic = true
const gatherAllInvalid = false
return iv.validateInvertedIndexes(
ctx, iv.codec, tbl, indexes, iv.makeHistoricalInternalExecTxnRunner(),
return vd.validateInvertedIndexes(
ctx, vd.codec, tbl, indexes, vd.makeHistoricalInternalExecTxnRunner(),
withFirstMutationPublic, gatherAllInvalid, override,
)
}

// makeHistoricalInternalExecTxnRunner creates a new transaction runner which
// always runs at the same time and that time is the current time as of when
// this constructor was called.
func (iv indexValidator) makeHistoricalInternalExecTxnRunner() sqlutil.HistoricalInternalExecTxnRunner {
now := iv.db.Clock().Now()
func (vd validator) makeHistoricalInternalExecTxnRunner() sqlutil.HistoricalInternalExecTxnRunner {
now := vd.db.Clock().Now()
return func(ctx context.Context, fn sqlutil.InternalExecFn) error {
validationTxn := iv.db.NewTxn(ctx, "validation")
validationTxn := vd.db.NewTxn(ctx, "validation")
err := validationTxn.SetFixedTimestamp(ctx, now)
if err != nil {
return err
}
return fn(ctx, validationTxn, iv.ieFactory.NewInternalExecutor(iv.newFakeSessionData(&iv.settings.SV)))
return fn(ctx, validationTxn, vd.ieFactory.NewInternalExecutor(vd.newFakeSessionData(&vd.settings.SV)))
}
}

// NewIndexValidator creates a IndexValidator interface
// NewValidator creates a Validator interface
// for the new schema changer.
func NewIndexValidator(
func NewValidator(
db *kv.DB,
codec keys.SQLCodec,
settings *cluster.Settings,
ieFactory sqlutil.InternalExecutorFactory,
validateForwardIndexes ValidateForwardIndexesFn,
validateInvertedIndexes ValidateInvertedIndexesFn,
newFakeSessionData NewFakeSessionDataFn,
) scexec.IndexValidator {
return indexValidator{
) scexec.Validator {
return validator{
db: db,
codec: codec,
settings: settings,
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/schemachanger/scexec/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Dependencies interface {
IndexMerger() Merger
BackfillProgressTracker() BackfillerTracker
PeriodicProgressFlusher() PeriodicProgressFlusher
IndexValidator() IndexValidator
Validator() Validator
IndexSpanSplitter() IndexSpanSplitter
EventLogger() EventLogger
DescriptorMetadataUpdater(ctx context.Context) DescriptorMetadataUpdater
Expand Down Expand Up @@ -196,8 +196,8 @@ type Merger interface {
) error
}

// IndexValidator provides interfaces that allow indexes to be validated.
type IndexValidator interface {
// Validator provides interfaces that allow indexes and check constraints to be validated.
type Validator interface {
ValidateForwardIndexes(
ctx context.Context,
tbl catalog.TableDescriptor,
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/schemachanger/scexec/exec_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func executeValidateUniqueIndex(
User: username.RootUserName(),
}
if index.GetType() == descpb.IndexDescriptor_FORWARD {
err = deps.IndexValidator().ValidateForwardIndexes(ctx, table, []catalog.Index{index}, execOverride)
err = deps.Validator().ValidateForwardIndexes(ctx, table, []catalog.Index{index}, execOverride)
} else {
err = deps.IndexValidator().ValidateInvertedIndexes(ctx, table, []catalog.Index{index}, execOverride)
err = deps.Validator().ValidateInvertedIndexes(ctx, table, []catalog.Index{index}, execOverride)
}
if err != nil {
return scerrors.SchemaChangerUserError(err)
Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/schemachanger/scexec/executor_external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (ti testInfra) newExecDeps(
noopMerger{},
scdeps.NewNoOpBackfillerTracker(ti.lm.Codec()),
scdeps.NewNoopPeriodicProgressFlusher(),
noopIndexValidator{},
noopValidator{},
scdeps.NewConstantClock(timeutil.Now()),
noopMetadataUpdater{},
noopEventLogger{},
Expand Down Expand Up @@ -461,11 +461,11 @@ func (n noopMerger) MergeIndexes(
return nil
}

type noopIndexValidator struct{}
type noopValidator struct{}

var _ scexec.IndexValidator = noopIndexValidator{}
var _ scexec.Validator = noopValidator{}

func (noopIndexValidator) ValidateForwardIndexes(
func (noopValidator) ValidateForwardIndexes(
ctx context.Context,
tableDesc catalog.TableDescriptor,
indexes []catalog.Index,
Expand All @@ -474,7 +474,7 @@ func (noopIndexValidator) ValidateForwardIndexes(
return nil
}

func (noopIndexValidator) ValidateInvertedIndexes(
func (noopValidator) ValidateInvertedIndexes(
ctx context.Context,
tableDesc catalog.TableDescriptor,
indexes []catalog.Index,
Expand Down Expand Up @@ -571,7 +571,7 @@ func (noopMetadataUpdater) UpsertZoneConfig(
}

var _ scexec.Backfiller = noopBackfiller{}
var _ scexec.IndexValidator = noopIndexValidator{}
var _ scexec.Validator = noopValidator{}
var _ scexec.EventLogger = noopEventLogger{}
var _ scexec.StatsRefresher = noopStatsReferesher{}
var _ scexec.DescriptorMetadataUpdater = noopMetadataUpdater{}
28 changes: 14 additions & 14 deletions pkg/sql/schemachanger/scexec/mocks_generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/sql/schemachanger/scjob/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (n *newSchemaChangeResumer) run(ctx context.Context, execCtxI interface{})
n.job,
execCfg.Codec,
execCfg.Settings,
execCfg.IndexValidator,
execCfg.Validator,
func(ctx context.Context, descriptors *descs.Collection, txn *kv.Txn) scexec.DescriptorMetadataUpdater {
return descmetadata.NewMetadataUpdater(ctx,
execCfg.InternalExecutorFactory,
Expand Down

0 comments on commit 239786a

Please sign in to comment.