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

Add -rename_tables to DropSources #6383

Merged
merged 1 commit into from
Jun 29, 2020
Merged

Add -rename_tables to DropSources #6383

merged 1 commit into from
Jun 29, 2020

Conversation

tomkrouper
Copy link
Collaborator

This addition allows the optional bool -rename_tables for DropSources.
This can be useful when dropping sources for larger tables. Instead of a
drop table, a rename table is run. This will be faster in most cases
but will require the user to clean up the tables at a later date.

Signed-off-by: Tom Krouper tomkrouper@github.com

This addition allows the optional bool -rename_tables for DropSources.
This can be useful when dropping sources for larger tables. Instead of a
`drop table`, a `rename table` is run. This will be faster in most cases
but will require the user to clean up the tables at a later date.

Signed-off-by: Tom Krouper <tomkrouper@github.com>
@tomkrouper tomkrouper requested a review from sougou as a code owner June 26, 2020 03:56
@tomkrouper
Copy link
Collaborator Author

Is there a way to re-kick local_example / Legacy local example using k8s on ubuntu-latest (pull_request)?

@tomkrouper
Copy link
Collaborator Author

cc: #6361 (comment)

@shlomi-noach I moved the PR change over here from ☝️. I've added a test for the -rename_tables and prevented the table length of the renamed table to be too long. Any other suggestions or help would be greatly appreciated.

@sougou sougou merged commit 1f54847 into vitessio:master Jun 29, 2020
@tomkrouper tomkrouper deleted the dropsource-rename-tables branch June 29, 2020 21:21
@shlomi-noach
Copy link
Contributor

Heh, didn;t even get a chance to review 🤷‍♂️

@sougou
Copy link
Contributor

sougou commented Jun 30, 2020

You can still review, and we'll fix forward :)

Copy link
Contributor

@shlomi-noach shlomi-noach left a comment

Choose a reason for hiding this comment

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

@tomkrouper I'm so glad you made this PR! I had it on my (short? long? -term) plan to implement a transparent DROP/RENAME/nibble logic, completely within vitess, and this ticks the first step for it.

Looks good! I'd do a minor golang-style change as suggested in review comments, but good to go as it is!

types := [...]string{
"DROP TABLE",
"RENAME TABLE",
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth extracting the above code outside the method, since it always generates the same. Also, suggesting to make it a map, such that e.g. types[DropTable]="DROP TABLE".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@shlomi-noach from a logical perspective, it makes total sense to move the code outside a method that gets repeatedly called. However, I don't understand what you mean by "make it a map". I mean, I could figure out how, but I don't get why.

Copy link
Contributor

@shlomi-noach shlomi-noach Jun 30, 2020

Choose a reason for hiding this comment

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

@tomkrouper yeah, so I believe it would be a more idiomatic way; for example, right now the code runs if trt < DropTable || trt > RenameTable {, but, if we add a new, third option, then we'd need to change trt > RenameTable to trt > SomethingNew ; where in fact we don't care about ranges, but of existence, and that's where maps are idiomatic and their use is widespread.

So, if we have:

mymap := map[string]string{DropTable: "DROP TABLE", RenameTable: "RENAME TABLE"}

we can then:

if t, ok := mymap[trt] ; ok {

and that answers "is trt known or unknown to us".

Anyway, that's the why the way I understand it, but I may be just biased towards my own habits.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes total sense. Thanks.

"DROP TABLE",
"RENAME TABLE",
}
if trt < DropTable || trt > RenameTable {
Copy link
Contributor

Choose a reason for hiding this comment

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

following the above map suggestion, the above would turn to:

if t, ok := tableRemovalTypeMap[trt] ; ok {
  return t
}
return "Unknown"

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.

3 participants