-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added ValidateVSchema #8012
Added ValidateVSchema #8012
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there, I think. I think the current refactor makes the ValidateSchemaShard
a little overloaded, and pulling out the vschema validation to its own function will make this a bit clearer.
go/vt/vtctl/vtctl.go
Outdated
@@ -2802,7 +2802,7 @@ func commandValidateSchemaKeyspace(ctx context.Context, wr *wrangler.Wrangler, s | |||
if *excludeTables != "" { | |||
excludeTableArray = strings.Split(*excludeTables, ",") | |||
} | |||
return wr.ValidateSchemaKeyspace(ctx, keyspace, excludeTableArray, *includeViews, *skipNoMaster) | |||
return wr.ValidateSchemaKeyspace(ctx, keyspace, excludeTableArray, *includeViews, *skipNoMaster, false /*includeVSchema*/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a flag to this command (and probably ValidateSchemaShard
, sorry for not pointing that out earlier) to be able to pass true
through here.
499c991
to
5d90c86
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything I have is pretty minor changes; I think Rafa was saying he had other thoughts so we should wait for him as well.
go/vt/vtctl/vtctl.go
Outdated
} | ||
|
||
func commandValidateSchemaKeyspace(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { | ||
excludeTables := subFlags.String("exclude_tables", "", "Specifies a comma-separated list of tables to exclude. Each is either an exact match, or a regular expression of the form /regexp/") | ||
includeViews := subFlags.Bool("include-views", false, "Includes views in the validation") | ||
skipNoMaster := subFlags.Bool("skip-no-master", false, "Skip shards that don't have master when performing validation") | ||
includeVSchema := subFlags.Bool("include-vschema", true, "Validate schemas against the vschema") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should be false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed 👍
go/vt/wrangler/schema.go
Outdated
wg.Add(len(shards)) | ||
|
||
for _, shard := range shards { | ||
go func(shard string, shardFailures *concurrency.AllErrorRecorder) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need to pass a reference to the recorder here; it's in scope in the closure of the goroutine (similar to how you're using the wait group).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually got linting errors when I did not pass in the recorder or shard which is why I passed them in
Linting go/vt/wrangler
go/vt/wrangler/schema.go:289:45: loopclosure: loop variable shard captured by func literal (govet)
si, err := wr.ts.GetShard(ctx, keyspace, shard)
^
go/vt/wrangler/schema.go:291:83: loopclosure: loop variable shard captured by func literal (govet)
shardFailures.RecordError(fmt.Errorf("GetShard(%v, %v) failed: %v", keyspace, shard, err))
^
go/vt/wrangler/schema.go:297:45: loopclosure: loop variable shard captured by func literal (govet)
excludeTables, includeViews, keyspace, shard, err,
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those lint errors are complaining about the shard
variable specifically (which is a correct error). I'm talking about just the shardFailures
variable which isn't part of the range
loop.
To illustrate what the linter is warning about, check out the difference between these two loops: https://play.golang.org/p/eQtSzSI60lR
go/vt/wrangler/schema.go
Outdated
} | ||
|
||
// ValidateVSchemaKeyspace compares the schema of each primary tablet in "keyspace" and errs if there are differences | ||
func (wr *Wrangler) ValidateVSchemaKeyspace(ctx context.Context, keyspace string, excludeTables []string, includeViews bool) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unused currently but thought that this functionality may be needed at some point. Instead of requiring the caller to pass in all shard names to ValidateVSchema
we can use this. In the two instances in which I've seen us validate the vschema we also have had the shards we are trying to validate so I understand if we should remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think if we don't need it now (and we don't expect to immediately need it in the short-term), then we should hold off. We can always add it back later!
go/vt/wrangler/schema.go
Outdated
@@ -142,6 +142,12 @@ func (wr *Wrangler) diffSchema(ctx context.Context, masterSchema *tabletmanagerd | |||
tmutils.DiffSchema(topoproto.TabletAliasString(masterTabletAlias), masterSchema, topoproto.TabletAliasString(alias), replicaSchema, er) | |||
} | |||
|
|||
// helper method to asynchronously validate a shards schema | |||
func (wr *Wrangler) validateSchemaShardConcurrent(ctx context.Context, keyspace, shard string, excludeTables []string, includeViews bool, includeVSchema bool, wg *sync.WaitGroup) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
59e4a05
to
3c847b2
Compare
Signed-off-by: Malcolm Akinje <[email protected]>
3c847b2
to
3479947
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for addressing all the comments. This looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me! thanks Malcolm ❤️
Signed-off-by: Malcolm Akinje [email protected]
Description
This PR adds in
ValidateVSchema
.ValidateSchemaShard
now uses this method as a helper whenincludeVSchema
is provided to it. This also gives the oppourtunity to validate that a shards schema is equivalent to the vschema in other areas besides the aforementioned method like when we create a resharding workflow.Related Issue(s)
Checklist
Deployment Notes