Skip to content

v3: write_only support for unique lookup vindexes#3658

Merged
alainjobart merged 3 commits intovitessio:masterfrom
sougou:v3
Feb 22, 2018
Merged

v3: write_only support for unique lookup vindexes#3658
alainjobart merged 3 commits intovitessio:masterfrom
sougou:v3

Conversation

@sougou
Copy link
Copy Markdown
Contributor

@sougou sougou commented Feb 15, 2018

The first commit changes the vindex API to allow for unique vindexes to return a keyrange instead of a specific keyspace id. This is a way for a unique vindex to tell the engine that it doesn't know the keyspace id, and ask it to scatter the query.

The second commit uses the above feature to support write_only mode for unique vindexes: during this mode the vindex will be written to, but not read from, allowing you to backfill missing entries while new ones continue to be populated. Once the back-fill is complete, write_only can be turned off.

@sougou sougou requested review from demmer and rafael February 15, 2018 02:54
There are use cases where a unique vindex may not know the target
keyspace id. If so, we should allow it to return a keyrange, which
will allow the vtgate engine to scatter the query.

The unique vindex property is still useful for the optimizer because
it can still use the unique property to deduce within-shard joins.

This feature may not be 100% relational, but it satisfies certain
use cases that would otherwise become very inefficient.
Now that unique lookup vindexes can return a scatter, we can add
write_only support for them.
@sougou
Copy link
Copy Markdown
Contributor Author

sougou commented Feb 15, 2018

@alainjobart I had to resolve a merge conflict with executor.go. Can you verify that I interpreted your change correctly?

@tirsen
Copy link
Copy Markdown
Collaborator

tirsen commented Feb 15, 2018

This does not contain "autocommit" yet? Or has that been merged separately?

@sougou
Copy link
Copy Markdown
Contributor Author

sougou commented Feb 15, 2018

autocommit is already merged #3600.

Copy link
Copy Markdown
Member

@rafael rafael left a comment

Choose a reason for hiding this comment

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

Given @alainjobart confirmation about the executor, change LGTM. The part that makes a bit nervous is the same concern I had in #3600. I feel that when we come back to this code and try to follow up what's going on between range or ID, it will be hard to reason about it. I think more documentation in the code will be helpful. However, I can't think of way of changing this without a major refactor. 😅

if ksid == nil {
continue
switch {
case ksid.Range != nil:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should add a comment here explaining in which cases it will be a range vs an ID (i.e when using this feature). Otherwise, in this context it's going to be hard to understand why it could be one way or the other.

executor, _, _, _ := createExecutorEnv()

// If a unique vindex returns a keyrange, we fail the insert
_, err := executorExec(executor, "insert into keyrange_table(krcol_unique, krcol) values(1, 1)", nil)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I had a question around this that @sougou responded in Slack. For future reference, adding here. It was not clear to me what would happen if you have an unique LookupIndex that is in write mode and then it enters in this code path.

In that case, it would mean that lookup was the primary vindex and it should fail.

@sougou
Copy link
Copy Markdown
Contributor Author

sougou commented Feb 22, 2018

@alainjobart this can be merged.

@alainjobart
Copy link
Copy Markdown
Contributor

alainjobart commented Feb 22, 2018

LGTM

Approved with PullApprove

@alainjobart alainjobart merged commit 376a070 into vitessio:master Feb 22, 2018
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.

5 participants