Skip to content
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

Materialize: Only get schema from source tablets if target is missing tables #6601

Merged
merged 2 commits into from Aug 22, 2020

Conversation

rohit-nayak-ps
Copy link
Contributor

@rohit-nayak-ps rohit-nayak-ps commented Aug 20, 2020

During materialize we sometimes need to copy the schema from source to target, depending on the value of the CreateDDL setting. A recent change introduced a regression where we request schema from sources even if we don't need the schema
to be copied.

This has a side-effect that the source needs to have a master (since we only query masters for schemas). Some users setup source keyspaces only with a replica for the purpose of vreplication into a target keyspace. In these cases the vtctl Materialize
command fails.

This PR requests the schema lazily, only if the target is missing tables.

Signed-off-by: Rohit Nayak rohit@planetscale.com

… tables

Signed-off-by: Rohit Nayak <rohit@planetscale.com>
@rohit-nayak-ps rohit-nayak-ps marked this pull request as ready for review August 20, 2020 20:04
@deepthi
Copy link
Member

deepthi commented Aug 20, 2020

Is this a regression introduced in #6251?

@deepthi deepthi mentioned this pull request Aug 21, 2020
@rohit-nayak-ps
Copy link
Contributor Author

Is this a regression introduced in #6251?

This one: #6207.

I guess you are asking whether this should be backported into 7.0. Not sure technically if it is a regression since we haven't said explicitly that we work with source keyspaces without masters. But it seems to have affected a couple of users already who are using source keyspaces with just replicas.

@deepthi
Copy link
Member

deepthi commented Aug 21, 2020

Is this a regression introduced in #6251?

This one: #6207.

I guess you are asking whether this should be backported into 7.0. Not sure technically if it is a regression since we haven't said explicitly that we work with source keyspaces without masters. But it seems to have affected a couple of users already who are using source keyspaces with just replicas.

Still a regression, I think we should backport. Running with replicas seems like a common usage with unmanaged vttablet mode.

@deepthi deepthi added this to the 7.0.1 milestone Aug 21, 2020
@deepthi deepthi requested a review from teejae August 21, 2020 13:40
}

targetTablet, err := mz.wr.ts.GetTablet(ctx, target.MasterAlias)
if err != nil {
return err
}

applyDDLs := []string{}
var applyDDLs []string
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this an empty clause?

func (mz *materializer) deploySchema(ctx context.Context) error {
var tableDDLs map[string]string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var tableDDLs map[string]string
var sourceDDLs map[string]string

i think it's clearer that it's from the source, hence the name

@@ -589,51 +590,55 @@ func (wr *Wrangler) buildMaterializer(ctx context.Context, ms *vtctldatapb.Mater
}, nil
}

func (mz *materializer) getTableDDLs(ctx context.Context) (map[string]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (mz *materializer) getTableDDLs(ctx context.Context) (map[string]string, error) {
func (mz *materializer) getSourceTableDDLs(ctx context.Context) (map[string]string, error) {

@@ -50,6 +50,7 @@ type materializer struct {
targetVSchema *vindexes.KeyspaceSchema
sourceShards []*topo.ShardInfo
targetShards []*topo.ShardInfo
mu sync.Mutex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional, but wanna mention why this mutex exists? it's not really protecting anything inside the materializer right? i think it's protecting the getting of the getTableDDLs? and is that only an optimization? if so, does it make sense to just have it inside the deploy?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this mutex is needed, but for a different reason, given below.

@@ -50,6 +50,7 @@ type materializer struct {
targetVSchema *vindexes.KeyspaceSchema
sourceShards []*topo.ShardInfo
targetShards []*topo.ShardInfo
mu sync.Mutex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this mutex is needed, but for a different reason, given below.

@@ -589,51 +590,55 @@ func (wr *Wrangler) buildMaterializer(ctx context.Context, ms *vtctldatapb.Mater
}, nil
}

func (mz *materializer) getTableDDLs(ctx context.Context) (map[string]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should run only once per invocation, and all others should use the result: it should populate a new tableDDLs member of mz. Right now, it returns the value to the calling goroutine, which will cause it to execute for each one of those.

Using sync.Once would have been ideal, but you have to handle the error return. So, you may have to live with the global mu. So, it may be better to rename it to schemaMu.

Copy link
Contributor

@sougou sougou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nvm. I see that tableDDLs is a local variable of the function. Forget everything I said. Instead move this mu right where the tableDDLs variable is declared.

Signed-off-by: Rohit Nayak <rohit@planetscale.com>
@sougou sougou merged commit 1943751 into vitessio:master Aug 22, 2020
@rohit-nayak-ps rohit-nayak-ps mentioned this pull request Aug 25, 2020
@deepthi deepthi removed this from the 7.0.1 milestone Aug 25, 2020
@askdba askdba added this to the v8.0 milestone Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants