-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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 DATABASE #4291
add RENAME DATABASE #4291
Conversation
Thanks @linearb -- I think there are more changes required to the TSDB layer. To see this you should add tests that query for data in a database, get results back, rename the database, and run the exact same query against the renamed database. You should get the same data back. Make sense? |
Thanks @otoolep . Adding that test is a good suggestion. But are you sure TSDB changes are needed?--- it works when I do such a test by hand: curl -G 'http://localhost:8086/query' --data-urlencode "q=CREATE DATABASE db_old" curl -XPOST 'http://localhost:8086/write?db=db_old' -d 'cpu,host=server01,region=useast load=4 1434055565000000000' curl -XPOST 'http://localhost:8086/write?db=db_old' -d 'cpu,host=server01,region=useast load=23 1434055569000000000' curl -G http://localhost:8086/query?pretty=true --data-urlencode "db=db_old" --data-urlencode "q=SELECT * FROM cpu WHERE region='useast'" curl -G http://localhost:8086/query?pretty=true --data-urlencode "db=db_new" --data-urlencode "q=SELECT * FROM cpu WHERE region='us east'" curl -G http://localhost:8086/query?pretty=true --data-urlencode "q=RENAME DATABASE db_old TO db_new" curl -G http://localhost:8086/query?pretty=true --data-urlencode "db=db_new" --data-urlencode "q=SELECT * FROM cpu WHERE region='useast'" curl -G http://localhost:8086/query?pretty=true --data-urlencode "db=db_old" --data-urlencode "q=SELECT * FROM cpu WHERE region='useast'" |
OK, I guess TSDB layer changes may not be required. We still need that test however. Can you add it? We'll also need to run this command by the team. |
Sure, I can add the test. |
I'm not a fan of the
Which roughly follows other SQL databases' renaming syntax and complements the existing |
+1 for |
Yeah, good call, it should be |
OK - ALTER it is. |
Realized that user privileges also needed updating on db rename. Still unsure how to update CQs correctly, but if that's going to be CHANGELOG.md updated |
@@ -67,17 +67,42 @@ func TestServer_DatabaseCommands(t *testing.T) { | |||
exp: `{"results":[{"series":[{"name":"databases","columns":["name"],"values":[["db0"],["db1"]]}]}]}`, | |||
}, | |||
&Query{ | |||
name: "rename database should succeed", |
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.
Should read alter database
.
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.
Actuall, I don't think it matters, now that I look at the tests.
@@ -105,6 +105,7 @@ message Command { | |||
SetDataCommand = 17; | |||
SetAdminPrivilegeCommand = 18; | |||
UpdateNodeCommand = 19; | |||
RenameDatabaseCommand = 20; |
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.
Indentation looks slightly off here.
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.
ok - will fix.
Great test coverage, +1. |
// Check for required TO token. | ||
if tok != TO { | ||
return nil, newParseError(tokstr(tok, lit), []string{"TO"}, pos) | ||
} |
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.
Parsing RENAME TO
tokens can be condensed to...
// Parse required RENAME TO tokens.
if err := p.parseTokens([]Token{RENAME, TO}); err != nil {
return nil, 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.
good point - will change.
@otoolep Suggested changes made. |
Thanks, I'll review now. Can you rebase against master to remove the "merge" commits? |
+1 |
Thanks @linearb -- great work. |
We've decided to revert this change. See #4503 for details. |
Too bad-- guess there was more involved here than any of us realized. |
@linearb sorry we didn't catch this in the initial review. We really appreciate the effort you put in on it! |
Thanks @linearb -- we have not reached consensus on this issue. There are some difficult issues raised, with regards to renaming opening directories. The issue with some nodes crashing before the rename completes may also be difficult. Perhaps some sort of simple aliasing is the best possible solution, which makes crash-recovery issue the simplest, and doesn't require any renaming of files on disk. The aliasing would be kept by Raft, and would exist in RAM only on all nodes. I believe this was suggested by @corylanou. The mapping from alias to actual name would be referenced each time during queries and during writes. This would mean the change would touch much more of the code however. |
Actually, after some further discussions here, if instead the system used the database IDs as the filenames on disk, then it would be reasonably easy to support renames. |
As long as there is a way for users to discover the mapping between database name and database ID that's a reasonable solution. I don't think it would be okay to obscure which database owned which files on disk. |
No reason why |
That absolutely works for me. The only bad spot would be a case where the |
Sounds good. I'll put something together. |
@otoolep Unless there is an internal database ID that I'm not seeing, I'll just add one like node id, or cluster id? Also, as changing the filenames is a breaking change, let me know if you have infrastructure for upgrades/downgrades to be aware of. |
No, it appears we don't have IDs for databases yet. You may need to add something to the We also don't have any explicit code for upgrades and downgrades right now. We are open to suggestions, but I realise it can be a complex topic. |
Support for RENAME DATABASE as in #4154
Comments welcome.
CQs not dealt with yet-- advice appreciated,
and not sure if correct proto version generated from meta.proto.