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

Make DROP/CREATE DATABASE pluggable #7381

Merged
merged 27 commits into from
Mar 11, 2021

Conversation

systay
Copy link
Collaborator

@systay systay commented Jan 26, 2021

Allows CREATE and DROP database to have behaviour controlled by a plugin.

Fixes #7525

Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
@systay systay closed this Feb 2, 2021
@systay systay reopened this Feb 22, 2021
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
@systay systay changed the title Start of making CREATE DATABASE pluggable Make DROP/CREATE DATABASE pluggable Feb 22, 2021
Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

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

👍

go/vt/vtgate/planbuilder/create_database_pluggable.go Outdated Show resolved Hide resolved
go/vt/vtgate/engine/create_database.go Outdated Show resolved Hide resolved
go/vt/vtgate/engine/create_database.go Outdated Show resolved Hide resolved
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
systay and others added 12 commits March 3, 2021 08:43
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
@harshit-gangal harshit-gangal marked this pull request as ready for review March 5, 2021 11:53
@harshit-gangal harshit-gangal self-requested a review as a code owner March 5, 2021 11:53
Copy link
Member

@enisoc enisoc left a comment

Choose a reason for hiding this comment

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

This looks great! I just had one question about adding a wait step for DROP DATABASE as well.

return &sqltypes.Result{RowsAffected: 1}, nil
}

err := plugin.DropDatabase(ctx, c.name)
Copy link
Member

Choose a reason for hiding this comment

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

We had discussed that after the plugin says it's done, we should wait until vtgate observes that the keyspace is gone. The idea is to mimic the semantic in MySQL, which is that it's safe to re-create a database immediately after DROP DATABASE returns. So we should probably check whatever signal we check when handling CREATE DATABASE here and wait for that signal to say the keyspace doesn't exist. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

We had discussed that after the plugin says it's done, we should wait until vtgate observes that the keyspace is gone. The idea is to mimic the semantic in MySQL, which is that it's safe to re-create a database immediately after DROP DATABASE returns. So we should probably check whatever signal we check when handling CREATE DATABASE here and wait for that signal to say the keyspace doesn't exist. WDYT?

Just want to call it out that the current implementation depends on the plugin to take care of changing topo server metadata to tell us that keyspace is created or deleted.
I have added the necessary checks to ensure that.

Also you can change the query timeout with query like create database /*vt+ QUERY_TIMEOUT_MS=30000 */ <database_name>

Copy link
Member

Choose a reason for hiding this comment

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

Just want to call it out that the current implementation depends on the plugin to take care of changing topo server metadata to tell us that keyspace is created or deleted.

That works for me. I just wanted vtgate to take care of the question, "Can this vtgate instance see the keyspace yet/still?" since the plugin can't determine that from topo alone.

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
return &sqltypes.Result{RowsAffected: 1}, nil
}

err := plugin.DropDatabase(ctx, c.name)
Copy link
Member

Choose a reason for hiding this comment

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

Just want to call it out that the current implementation depends on the plugin to take care of changing topo server metadata to tell us that keyspace is created or deleted.

That works for me. I just wanted vtgate to take care of the question, "Can this vtgate instance see the keyspace yet/still?" since the plugin can't determine that from topo alone.

if err != nil {
return nil, err
}
for vcursor.FindKeyspace(c.name) {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like vcursor.FindKeyspace() does a direct topo call, which checks the source of truth, but it doesn't check whether this particular vtgate instance has observed the change yet.

My goal was to guarantee that an immediate CREATE DATABASE x after DROP DATABASE x on the same vtgate session will succeed. It looks like CREATE DATABASE checks vschema.KeyspaceExists(ksName) to determine whether the keyspace exists. Wouldn't we want to check the same thing to guarantee that vtgate will allow it?

Copy link
Member

Choose a reason for hiding this comment

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

I changed it to use vschema.


func (vc *vcursorImpl) FindKeyspace(ks string) bool {
_, err := vc.topoServer.GetKeyspace(vc.ctx, ks)
return err == nil
Copy link
Member

Choose a reason for hiding this comment

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

Won't this mean that a transient error communicating with topo will make us assume the keyspace doesn't exist? It seems like anything that makes a remote call should return error as well to be honest about the possibility that it might fail to get an answer at all. We would only translate the NotFound/NoNode error to false, nil.

Copy link
Member

Choose a reason for hiding this comment

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

now this is not an issue.

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
@deepthi deepthi mentioned this pull request Mar 9, 2021
7 tasks
}

func (vc *vcursorImpl) FindKeyspace(ks string) bool {
return vc.KeyspaceExists(ks)
Copy link
Member

Choose a reason for hiding this comment

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

It looks like KeyspaceExists() reads from the vschema.Keyspaces map without a mutex, which implies that the map is never updated by another goroutine. Doesn't that mean the result of this call will never change, even if vtgate has refreshed vschema in the background?

Copy link
Member

Choose a reason for hiding this comment

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

I changed that to see the executor view of VSchema.
The e2e test confirms that you can do create/drop multiple times in order.

RebuildVSchemaGraph is necessary to update the executor's view.

harshit-gangal and others added 4 commits March 11, 2021 01:07
… available

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
…ger available to be served

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Copy link
Member

@enisoc enisoc left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for doing the heavy lifting on waiting for vtgate to observe changes. This should make my job writing the plugin very easy! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow plugin implementation for CREATE and DROP DATABASE
5 participants