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 DATABASE #4291

Merged
merged 7 commits into from
Oct 9, 2015
Merged

add RENAME DATABASE #4291

merged 7 commits into from
Oct 9, 2015

Conversation

linearb
Copy link
Contributor

@linearb linearb commented Oct 1, 2015

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.

@otoolep
Copy link
Contributor

otoolep commented Oct 1, 2015

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?

@linearb
Copy link
Contributor Author

linearb commented Oct 2, 2015

Thanks @otoolep . Adding that test is a good suggestion.
I'll have a harder look at the TSDB layer when I have a chance.

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"
{"results":[{}]}

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'"
{ "results": [ { "series": [ { "name": "cpu", "columns": [ "time", "host", "load", "region" ], "values": [ [ "2015-06-11T20:46:05Z", "server01", 4, "useast" ], [ "2015-06-11T20:46:09Z", "server01", 23, "useast" ] ] } ] } ] }

curl -G http://localhost:8086/query?pretty=true --data-urlencode "db=db_new" --data-urlencode "q=SELECT * FROM cpu WHERE region='us east'"
{"results":[{"error": "database not found: db_new"}]}

curl -G http://localhost:8086/query?pretty=true --data-urlencode "q=RENAME DATABASE db_old TO db_new"
{"results": [{}]}

curl -G http://localhost:8086/query?pretty=true --data-urlencode "db=db_new" --data-urlencode "q=SELECT * FROM cpu WHERE region='useast'"
{ "results": [ { "series": [ { "name": "cpu", "columns": [ "time", "host", "load", "region" ], "values": [ [ "2015-06-11T20:46:05Z", "server01", 4, "useast" ], [ "2015-06-11T20:46:09Z", "server01", 23, "useast" ] ] } ] } ] }

curl -G http://localhost:8086/query?pretty=true --data-urlencode "db=db_old" --data-urlencode "q=SELECT * FROM cpu WHERE region='useast'"
{ "results": [ { "error": "database not found: db_old" } ] }

@otoolep
Copy link
Contributor

otoolep commented Oct 2, 2015

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.

@linearb
Copy link
Contributor Author

linearb commented Oct 2, 2015

Sure, I can add the test.

@gunnaraasen
Copy link
Member

I'm not a fan of the RENAME DATABASE syntax. ALTER DATABASE feels more SQL-like. The full syntax would be something like:

ALTER DATABASE <old_db_name> RENAME TO <new_db_name>

Which roughly follows other SQL databases' renaming syntax and complements the existing ALTER RETENTION POLICY statement. Just my two cents.

@beckettsean
Copy link
Contributor

+1 for ALTER DATABASE. That fits in with our other ALTER USER and ALTER RETENTION POLICY queries.

@otoolep
Copy link
Contributor

otoolep commented Oct 2, 2015

Yeah, good call, it should be ALTER.

@linearb
Copy link
Contributor Author

linearb commented Oct 2, 2015

OK - ALTER it is.
Interestingly, mysql once had a RENAME DATABASE that was considered dangerous:
https://dev.mysql.com/doc/refman/5.1/en/rename-database.html

@linearb
Copy link
Contributor Author

linearb commented Oct 7, 2015

Realized that user privileges also needed updating on db rename.
So added something for that also.

Still unsure how to update CQs correctly, but if that's going to be
complicated perhaps better to split that off as a separate issue.

CHANGELOG.md updated
mergeable
Tests pass
Signed CLA

@@ -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",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should read alter database.

Copy link
Contributor

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.

@otoolep
Copy link
Contributor

otoolep commented Oct 7, 2015

@linearb -- this looks really great, just some minor feedback. All community-contributions require 2 reviews by core developers, so we just need to wait for that too.

@dgnorton -- can you also review?

@@ -105,6 +105,7 @@ message Command {
SetDataCommand = 17;
SetAdminPrivilegeCommand = 18;
UpdateNodeCommand = 19;
RenameDatabaseCommand = 20;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok - will fix.

@otoolep
Copy link
Contributor

otoolep commented Oct 7, 2015

Great test coverage, +1.

// Check for required TO token.
if tok != TO {
return nil, newParseError(tokstr(tok, lit), []string{"TO"}, pos)
}
Copy link
Contributor

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
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point - will change.

@linearb
Copy link
Contributor Author

linearb commented Oct 9, 2015

@otoolep Suggested changes made.

@otoolep
Copy link
Contributor

otoolep commented Oct 9, 2015

Thanks, I'll review now.

Can you rebase against master to remove the "merge" commits?

@dgnorton
Copy link
Contributor

dgnorton commented Oct 9, 2015

+1

@otoolep
Copy link
Contributor

otoolep commented Oct 9, 2015

Thanks @linearb -- great work.

otoolep added a commit that referenced this pull request Oct 9, 2015
@otoolep otoolep merged commit e00b822 into influxdata:master Oct 9, 2015
@dgnorton
Copy link
Contributor

We've decided to revert this change. See #4503 for details.

@linearb
Copy link
Contributor Author

linearb commented Oct 20, 2015

Too bad-- guess there was more involved here than any of us realized.

@dgnorton
Copy link
Contributor

@linearb sorry we didn't catch this in the initial review. We really appreciate the effort you put in on it!

@linearb
Copy link
Contributor Author

linearb commented Oct 22, 2015

@dgnorton @otoolep Since I think this would be a good feature to get in, I'm willing to add
something to deal with problems raised in #4503 . Before going ahead, perhaps there
might be some consensus about which approach to take (or at least which to avoid)?

@otoolep
Copy link
Contributor

otoolep commented Oct 22, 2015

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.

@otoolep
Copy link
Contributor

otoolep commented Oct 22, 2015

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.

@beckettsean
Copy link
Contributor

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.

@otoolep
Copy link
Contributor

otoolep commented Oct 22, 2015

No reason why SHOW DATABASES wouldn't show this information, it would be easy enough.

@beckettsean
Copy link
Contributor

That absolutely works for me. The only bad spot would be a case where the influxd process won't launch but we still want to know which database owns which shards. I can live with that in favor of supporting ALTER DATABASE, which will affect many more users than the corner case I described.

@linearb
Copy link
Contributor Author

linearb commented Oct 22, 2015

Sounds good. I'll put something together.

@linearb
Copy link
Contributor Author

linearb commented Oct 27, 2015

@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.

@otoolep
Copy link
Contributor

otoolep commented Oct 27, 2015

No, it appears we don't have IDs for databases yet. You may need to add something to the DatabaseInfo type.

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.

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.

None yet

5 participants