-
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
Vtctl Materialize optimizations #6207
Vtctl Materialize optimizations #6207
Conversation
read PR w/ |
12f6bcb
to
b217f5b
Compare
Signed-off-by: Toliver Jue <toliver@planetscale.com>
b217f5b
to
368ccd3
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.
Other than the issue I commented about LGTM.
Nice, this should help greatly once we add --all to MoveTables as well!
go/vt/wrangler/materializer_test.go
Outdated
@@ -1970,7 +1970,7 @@ func TestMaterializerTableMismatch(t *testing.T) { | |||
delete(env.tmc.schema, "targetks.t1") | |||
|
|||
err := env.wr.Materialize(context.Background(), ms) | |||
assert.EqualError(t, err, "source and target table names must match for copying schema: t2 vs t1") | |||
assert.EqualError(t, err, "copy: source tables do not exist: [t1].") |
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.
It is the target table that is missing, right? We are copying over "select * from t2" from source into t1 on target ... Validations have to take into account that we could have tables missing in the source or tables missing in the target where we are materializing to a different table ...
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've split the test now into 2 cases, "copy" and not. "copy" still requires the same table name, and thus this is right error.
the other "non copy" case is a separate test, where CreateDdl=""
, and has the same original error.
go/vt/wrangler/materializer.go
Outdated
|
||
if ts.CreateDdl == createDDLAsCopy { | ||
needsCopy = true | ||
copyTables[ts.TargetTable] = true |
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.
Target table and source table can be different, so the table to be copied will have to use sqlparser.TableFromStatement(ts.SourceExpression) if the source expression is present ...
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.
see other comment
Signed-off-by: Toliver Jue <toliver@planetscale.com>
@rohit-nayak-ps ptal. adjusted only the tests. the logic was still right, but the tests were not sufficiently granular previously. |
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 feels a little over-complicated. Maybe you were not aware that you could GetSchema
for all tables using []string{"/.*/"}
.
What I would do is a full GetSchema
for target outside the table loop.
For the source, I'd lazy-load a full GetSchema
of source on first use, or even just load it upfront to keep it simple.
Then the existing code would be practically unchanged except for the additional logic for SourceExpression
.
@sougou, I had wanted to keep So are you suggesting what I should change in this PR is just grabbing the whole schemas without making the sub table lists? The parsing of the table lists into maps would still be necessary, since we need to otherwise index on them. |
@sougou I've made the changes to grab and index the full schemas before going through the table loop. PTAL. |
c7564b7
to
b33f629
Compare
Signed-off-by: Toliver Jue <toliver@planetscale.com>
b33f629
to
9171b55
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.
I was hoping it would be simpler, but the fact that the schema returned is not a map complicates this code a bit more.
We need a test to demonstrate the new behavior. After this, we're good to go.
go/vt/wrangler/materializer.go
Outdated
if mz.targetVSchema.Keyspace.Sharded && mz.targetVSchema.Tables[ts.TargetTable].Type != vindexes.TypeReference { | ||
cv, err := vindexes.FindBestColVindex(mz.targetVSchema.Tables[ts.TargetTable]) | ||
|
||
if ts.SourceExpression != "" { |
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.
Change this to:
if ts.SourceExpression == "" {
continue
}
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.
but don't i still need to add to the Filter.Rules after this block?
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.
Oh. Right. Missed that. You can duplicate that append line here before continuing.
Main concern is that there are already too many indents. I'm not happy about the existing if-else block already.
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.
duped. also i pulled out the filter
as default assign so that we can get rid of an else as well.
Signed-off-by: Toliver Jue <toliver@planetscale.com>
@sougou also what test are you proposing for this new behavior? that we don't get multiple requests for GetSchema in particular? |
Mainly one where the source expression is empty. |
Signed-off-by: Toliver Jue <toliver@planetscale.com>
8a9c6d2
to
ccdcb63
Compare
} | ||
|
||
rule.Filter = filter |
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.
nice.
source
entries to be equivalent toselect * from table
, as used by VReplication