-
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
Online DDL: DROP TABLE translated to RENAME TABLE statement #7221
Online DDL: DROP TABLE translated to RENAME TABLE statement #7221
Conversation
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
artifact tables are named after the migration UUID (this helps in tracking their origin) Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Depends on: #7151 |
… DDL, otherwise consider them as direct regardless of ddl_strategy Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Documentation PR to follow. |
…o-rename Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Request for review |
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.
lgtm
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
go/vt/schema/online_ddl.go
Outdated
stmt, err := sqlparser.Parse(sql) | ||
if err != nil { | ||
return action, ddlStmt, fmt.Errorf("Error parsing statement: SQL=%s, error=%+v", sql, err) | ||
return ddlStmt, action, fmt.Errorf("Error parsing statement: SQL=%s, error=%+v", sql, 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.
:nit: :rant: This is confusing code. I know the old code did this, but we should fix it while we are in here. ddlStmt and action have not been assigned to here, so this is equivalent to
return nil, nil, fmt.Errorf("Error parsing statement: SQL=%s, error=%+v", sql, err)
I would suggest to not use named return arguments unless they help readability or need to be changed by a defer.
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 personally find this to be more idiomatic, because I don't need to think about the actual datatype for those return variables and I don't need to think about what's the default return value -- it's implicitly done on my behalf. Also, to me, it more readable to see what's being returned semantically.
Having said that I don't feel strongly and I'll adapt per your review.
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.
resolved
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 are right to point out that confusing is highly subjective.
Let me explain where I'm coming from. I've always felt that it's important to return empty or nil values from a function when an error occurs. Some functions allow you to return both a valid value and an error (example: https://golang.org/src/io/io.go?s=11741:11795#L322), so I always make sure to explicitly return nil or empty values when the function doesn't have a valid value to return.
The named return argument pattern makes it a little more difficult for a casual reader to see if we are returning the result as far as we got when the error occurred, or an empty value to signal that nothing was actually done.
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.
The way I see it, when an error is returned, in vast majority of cases the other values do not matter (are expected to be ignored). Therefore, it is only a rare occasion where those values will be checked. To me the code is more readable where I understand what it is that I'm returning semantically (e.g. this is the uuid
rather than ""
). And it's only the rare occasions where I need to worry about the actual values returned.
So I guess my confusion is the inversion of yours...
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
fixing failed tests after merging conflicts |
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
endtoend tests fixed |
to be followed by a documentation PR |
documentation added and merged in vitessio/website#663 |
Description
Starting #7083,
CREATE
andDROP
tables can execute as Online-DDL, meaning they're scheduled, audited and executed by tablet servers.With this PR, a
DROP TABLE
statement is not only treated as online DDL, it is actually converted to aRENAME TABLE
statement, to work with the table lifecycle mechanism.The table is renamed into something like
_vt_HOLD_b0d1fb34450a11ebb980f875a4d24e90_20201226103654
. By just having that kind of name, the table is later garbage-collected by the lifecycle mechanism, to be purged->evacuated->dropped.We take care of
DROP TABLE IF EXISTS
by checking the return code from theRENAME TABLE
statement, and ignoring the specific error that indicates the table does not exist.Also in this PR,
CREATE
andDROP
are supported throughvtgate
. Previously they were only supported byvtctl
.Last, also in this PR, is retaining the GC UUID (
b0d1fb34450a11ebb980f875a4d24e90
in the above_vt_HOLD_b0d1fb34450a11ebb980f875a4d24e90_20201226103654
example) such that:_vt_PURGE_b0d1fb34450a11ebb980f875a4d24e90_20201230103654
ALTER TABLE
artifacts are similarly named after the Online DDL UUIDThere can be no conflict of naming because both
state
(HOLD
,PURGE
, etc.) as well as timestamps differ, even when using same UUID.Related Issue(s)
tracking: #6689, #6926
Related: #7083
Depends on: #7151
Checklist
Impacted Areas in Vitess
Components that this PR will affect: