diff --git a/cmd/influxd/run/server_test.go b/cmd/influxd/run/server_test.go index 4679882080..987b196370 100644 --- a/cmd/influxd/run/server_test.go +++ b/cmd/influxd/run/server_test.go @@ -66,43 +66,18 @@ func TestServer_DatabaseCommands(t *testing.T) { command: `SHOW DATABASES`, exp: `{"results":[{"series":[{"name":"databases","columns":["name"],"values":[["db0"],["db1"]]}]}]}`, }, - &Query{ - name: "rename database should succeed", - command: `RENAME DATABASE db1 TO db2`, - exp: `{"results":[{}]}`, - }, - &Query{ - name: "show databases should reflect change of name", - command: `SHOW DATABASES`, - exp: `{"results":[{"series":[{"name":"databases","columns":["name"],"values":[["db0"],["db2"]]}]}]}`, - }, - &Query{ - name: "rename non-existent database should fail", - command: `RENAME DATABASE db4 TO db5`, - exp: `{"results":[{"error":"database not found"}]}`, - }, - &Query{ - name: "rename database to illegal name should fail", - command: `RENAME DATABASE db2 TO 0xdb0`, - exp: `{"error":"error parsing query: found 0, expected identifier at line 1, char 24"}`, - }, - &Query{ - name: "rename database to already existing datbase should fail", - command: `RENAME DATABASE db2 TO db0`, - exp: `{"results":[{"error":"database already exists"}]}`, - }, &Query{ name: "drop database db0 should succeed", command: `DROP DATABASE db0`, exp: `{"results":[{}]}`, }, &Query{ - name: "drop database db2 should succeed", - command: `DROP DATABASE db2`, + name: "drop database db1 should succeed", + command: `DROP DATABASE db1`, exp: `{"results":[{}]}`, }, &Query{ - name: "show databases should have no results after dropping all databases", + name: "show database should have no results", command: `SHOW DATABASES`, exp: `{"results":[{"series":[{"name":"databases","columns":["name"]}]}]}`, }, diff --git a/influxql/ast.go b/influxql/ast.go index 044e7b97c1..d269b0204f 100644 --- a/influxql/ast.go +++ b/influxql/ast.go @@ -98,7 +98,6 @@ func (*DropSubscriptionStatement) node() {} func (*DropUserStatement) node() {} func (*GrantStatement) node() {} func (*GrantAdminStatement) node() {} -func (*RenameDatabaseStatement) node() {} func (*RevokeStatement) node() {} func (*RevokeAdminStatement) node() {} func (*SelectStatement) node() {} @@ -209,7 +208,6 @@ func (*DropSubscriptionStatement) stmt() {} func (*DropUserStatement) stmt() {} func (*GrantStatement) stmt() {} func (*GrantAdminStatement) stmt() {} -func (*RenameDatabaseStatement) stmt() {} func (*ShowContinuousQueriesStatement) stmt() {} func (*ShowGrantsForUserStatement) stmt() {} func (*ShowServersStatement) stmt() {} @@ -510,29 +508,6 @@ func (s *GrantAdminStatement) RequiredPrivileges() ExecutionPrivileges { return ExecutionPrivileges{{Admin: true, Name: "", Privilege: AllPrivileges}} } -// RenameDatabaseStatement represents a command for renaming a database. -type RenameDatabaseStatement struct { - // Current name of the database - OldName string - // New name of the database - NewName string -} - -// String returns a string representation of the rename database statement. -func (s *RenameDatabaseStatement) String() string { - var buf bytes.Buffer - _, _ = buf.WriteString("RENAME DATABASE ") - _, _ = buf.WriteString(s.OldName) - _, _ = buf.WriteString(" TO ") - _, _ = buf.WriteString(s.NewName) - return buf.String() -} - -// RequiredPrivileges returns the privilege required to execute a RenameDatabaseStatement. -func (s *RenameDatabaseStatement) RequiredPrivileges() ExecutionPrivileges { - return ExecutionPrivileges{{Admin: true, Name: "", Privilege: AllPrivileges}} -} - // SetPasswordUserStatement represents a command for changing user password. type SetPasswordUserStatement struct { // Plain Password diff --git a/influxql/parser.go b/influxql/parser.go index f74b73ad5c..87570d223f 100644 --- a/influxql/parser.go +++ b/influxql/parser.go @@ -90,8 +90,6 @@ func (p *Parser) ParseStatement() (Statement, error) { return p.parseDropStatement() case GRANT: return p.parseGrantStatement() - case RENAME: - return p.parseRenameStatement() case REVOKE: return p.parseRevokeStatement() case ALTER: @@ -99,7 +97,7 @@ func (p *Parser) ParseStatement() (Statement, error) { case SET: return p.parseSetPasswordUserStatement() default: - return nil, newParseError(tokstr(tok, lit), []string{"SELECT", "DELETE", "SHOW", "CREATE", "DROP", "GRANT", "RENAME", "REVOKE", "ALTER", "SET"}, pos) + return nil, newParseError(tokstr(tok, lit), []string{"SELECT", "DELETE", "SHOW", "CREATE", "DROP", "GRANT", "REVOKE", "ALTER", "SET"}, pos) } } @@ -238,19 +236,6 @@ func (p *Parser) parseAlterStatement() (Statement, error) { return nil, newParseError(tokstr(tok, lit), []string{"RETENTION"}, pos) } -// parseRenameStatement parses a string and returns a rename statement. -// This function assumes the RENAME token has already been consumed. -func (p *Parser) parseRenameStatement() (Statement, error) { - tok, pos, lit := p.scanIgnoreWhitespace() - if tok == DATABASE { - return p.parseRenameDatabaseStatement() - } - - return nil, newParseError(tokstr(tok, lit), []string{"DATABASE"}, pos) -} - -// parseDropStatement parses a string and returns a drop statement. - // parseSetPasswordUserStatement parses a string and returns a set statement. // This function assumes the SET token has already been consumed. func (p *Parser) parseSetPasswordUserStatement() (*SetPasswordUserStatement, error) { @@ -1483,36 +1468,6 @@ func (p *Parser) parseDropDatabaseStatement() (*DropDatabaseStatement, error) { return stmt, nil } -// parseRenameDatabaseStatement parses a string and returns a RenameDatabaseStatement. -// This function assumes the "RENAME DATABASE" tokens have already been consumed. -func (p *Parser) parseRenameDatabaseStatement() (*RenameDatabaseStatement, error) { - stmt := &RenameDatabaseStatement{} - - // Parse the name of the database to be renamed. - lit, err := p.parseIdent() - if err != nil { - return nil, err - } - stmt.OldName = lit - - // Parse TO clause. - tok, pos, lit := p.scanIgnoreWhitespace() - - // Check for required TO token. - if tok != TO { - return nil, newParseError(tokstr(tok, lit), []string{"TO"}, pos) - } - - // Parse the new name of the database. - lit, err = p.parseIdent() - if err != nil { - return nil, err - } - stmt.NewName = lit - - return stmt, nil -} - // parseDropSubscriptionStatement parses a string and returns a DropSubscriptionStatement. // This function assumes the "DROP SUBSCRIPTION" tokens have already been consumed. func (p *Parser) parseDropSubscriptionStatement() (*DropSubscriptionStatement, error) { diff --git a/influxql/parser_test.go b/influxql/parser_test.go index 24e64cae83..138881234e 100644 --- a/influxql/parser_test.go +++ b/influxql/parser_test.go @@ -1497,10 +1497,10 @@ func TestParser_ParseStatement(t *testing.T) { }, // Errors - {s: ``, err: `found EOF, expected SELECT, DELETE, SHOW, CREATE, DROP, GRANT, RENAME, REVOKE, ALTER, SET at line 1, char 1`}, + {s: ``, err: `found EOF, expected SELECT, DELETE, SHOW, CREATE, DROP, GRANT, REVOKE, ALTER, SET at line 1, char 1`}, {s: `SELECT`, err: `found EOF, expected identifier, string, number, bool at line 1, char 8`}, {s: `SELECT time FROM myseries`, err: `at least 1 non-time field must be queried`}, - {s: `blah blah`, err: `found blah, expected SELECT, DELETE, SHOW, CREATE, DROP, GRANT, RENAME, REVOKE, ALTER, SET at line 1, char 1`}, + {s: `blah blah`, err: `found blah, expected SELECT, DELETE, SHOW, CREATE, DROP, GRANT, REVOKE, ALTER, SET at line 1, char 1`}, {s: `SELECT field1 X`, err: `found X, expected FROM at line 1, char 15`}, {s: `SELECT field1 FROM "series" WHERE X +;`, err: `found ;, expected identifier, string, number, bool at line 1, char 38`}, {s: `SELECT field1 FROM myseries GROUP`, err: `found EOF, expected BY at line 1, char 35`}, diff --git a/influxql/scanner_test.go b/influxql/scanner_test.go index 1c41ae9bc4..7778fc4383 100644 --- a/influxql/scanner_test.go +++ b/influxql/scanner_test.go @@ -150,7 +150,6 @@ func TestScanner_Scan(t *testing.T) { {s: `QUERIES`, tok: influxql.QUERIES}, {s: `QUERY`, tok: influxql.QUERY}, {s: `READ`, tok: influxql.READ}, - {s: `RENAME`, tok: influxql.RENAME}, {s: `RETENTION`, tok: influxql.RETENTION}, {s: `REVOKE`, tok: influxql.REVOKE}, {s: `SELECT`, tok: influxql.SELECT}, diff --git a/influxql/token.go b/influxql/token.go index 23cc36b6d9..08205b3265 100644 --- a/influxql/token.go +++ b/influxql/token.go @@ -107,7 +107,6 @@ const ( QUERIES QUERY READ - RENAME REPLICATION RETENTION REVOKE @@ -224,7 +223,6 @@ var tokens = [...]string{ QUERIES: "QUERIES", QUERY: "QUERY", READ: "READ", - RENAME: "RENAME", REPLICATION: "REPLICATION", RETENTION: "RETENTION", REVOKE: "REVOKE", diff --git a/meta/data.go b/meta/data.go index e2a64b17bd..ba7a4975af 100644 --- a/meta/data.go +++ b/meta/data.go @@ -177,31 +177,6 @@ func (data *Data) DropDatabase(name string) error { return ErrDatabaseNotFound } -// RenameDatabase renames a database. -// Returns an error if oldName or newName is blank -// or if a database with the newName already exists -// or if a database with oldName does not exist -func (data *Data) RenameDatabase(oldName, newName string) error { - if newName == "" || oldName == "" { - return ErrDatabaseNameRequired - } - if data.Database(newName) != nil { - return ErrDatabaseExists - } - if data.Database(oldName) == nil { - return ErrDatabaseNotFound - } - // find database named oldName and rename it to newName - for i := range data.Databases { - if data.Databases[i].Name == oldName { - data.Databases[i].Name = newName - //TODO CQs - return nil - } - } - return ErrDatabaseNotFound -} - // RetentionPolicy returns a retention policy for a database by name. func (data *Data) RetentionPolicy(database, name string) (*RetentionPolicyInfo, error) { di := data.Database(database) diff --git a/meta/data_test.go b/meta/data_test.go index dab2abfeb7..ed994bbb6c 100644 --- a/meta/data_test.go +++ b/meta/data_test.go @@ -135,36 +135,6 @@ func TestData_DropDatabase(t *testing.T) { } } -// Ensure a database can be renamed. -func TestData_RenameDatabase(t *testing.T) { - var data meta.Data - for i := 0; i < 2; i++ { - if err := data.CreateDatabase(fmt.Sprintf("db%d", i)); err != nil { - t.Fatal(err) - } - } - - if err := data.RenameDatabase("db1", "db2"); err != nil { - t.Fatal(err) - } else if !reflect.DeepEqual(data.Databases, []meta.DatabaseInfo{{Name: "db0"}, {Name: "db2"}}) { - t.Fatalf("unexpected databases: %#v", data.Databases) - } -} - -// Ensure that renaming a database without both old and new names returns an error. -func TestData_RenameDatabase_ErrNameRequired(t *testing.T) { - var data meta.Data - if err := data.RenameDatabase("", ""); err != meta.ErrDatabaseNameRequired { - t.Fatalf("unexpected error: %s", err) - } - if err := data.RenameDatabase("from_foo", ""); err != meta.ErrDatabaseNameRequired { - t.Fatalf("unexpected error: %s", err) - } - if err := data.RenameDatabase("", "to_foo"); err != meta.ErrDatabaseNameRequired { - t.Fatalf("unexpected error: %s", err) - } -} - // Ensure a retention policy can be created. func TestData_CreateRetentionPolicy(t *testing.T) { data := meta.Data{Nodes: []meta.NodeInfo{{ID: 1}, {ID: 2}}} diff --git a/meta/internal/meta.pb.go b/meta/internal/meta.pb.go index 5f63faab32..3289eb24f1 100644 --- a/meta/internal/meta.pb.go +++ b/meta/internal/meta.pb.go @@ -40,7 +40,6 @@ It has these top-level messages: SetDataCommand SetAdminPrivilegeCommand UpdateNodeCommand - RenameDatabaseCommand CreateSubscriptionCommand DropSubscriptionCommand Response @@ -54,12 +53,10 @@ It has these top-level messages: package internal import proto "github.com/gogo/protobuf/proto" -import fmt "fmt" import math "math" // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal -var _ = fmt.Errorf var _ = math.Inf type RPCType int32 @@ -120,7 +117,6 @@ const ( Command_SetDataCommand Command_Type = 17 Command_SetAdminPrivilegeCommand Command_Type = 18 Command_UpdateNodeCommand Command_Type = 19 - Command_RenameDatabaseCommand Command_Type = 20 Command_CreateSubscriptionCommand Command_Type = 21 Command_DropSubscriptionCommand Command_Type = 22 ) @@ -145,7 +141,6 @@ var Command_Type_name = map[int32]string{ 17: "SetDataCommand", 18: "SetAdminPrivilegeCommand", 19: "UpdateNodeCommand", - 20: "RenameDatabaseCommand", 21: "CreateSubscriptionCommand", 22: "DropSubscriptionCommand", } @@ -169,7 +164,6 @@ var Command_Type_value = map[string]int32{ "SetDataCommand": 17, "SetAdminPrivilegeCommand": 18, "UpdateNodeCommand": 19, - "RenameDatabaseCommand": 20, "CreateSubscriptionCommand": 21, "DropSubscriptionCommand": 22, } @@ -192,15 +186,15 @@ func (x *Command_Type) UnmarshalJSON(data []byte) error { } type Data struct { - Term *uint64 `protobuf:"varint,1,req,name=Term" json:"Term,omitempty"` - Index *uint64 `protobuf:"varint,2,req,name=Index" json:"Index,omitempty"` - ClusterID *uint64 `protobuf:"varint,3,req,name=ClusterID" json:"ClusterID,omitempty"` - Nodes []*NodeInfo `protobuf:"bytes,4,rep,name=Nodes" json:"Nodes,omitempty"` - Databases []*DatabaseInfo `protobuf:"bytes,5,rep,name=Databases" json:"Databases,omitempty"` - Users []*UserInfo `protobuf:"bytes,6,rep,name=Users" json:"Users,omitempty"` - MaxNodeID *uint64 `protobuf:"varint,7,req,name=MaxNodeID" json:"MaxNodeID,omitempty"` - MaxShardGroupID *uint64 `protobuf:"varint,8,req,name=MaxShardGroupID" json:"MaxShardGroupID,omitempty"` - MaxShardID *uint64 `protobuf:"varint,9,req,name=MaxShardID" json:"MaxShardID,omitempty"` + Term *uint64 `protobuf:"varint,1,req" json:"Term,omitempty"` + Index *uint64 `protobuf:"varint,2,req" json:"Index,omitempty"` + ClusterID *uint64 `protobuf:"varint,3,req" json:"ClusterID,omitempty"` + Nodes []*NodeInfo `protobuf:"bytes,4,rep" json:"Nodes,omitempty"` + Databases []*DatabaseInfo `protobuf:"bytes,5,rep" json:"Databases,omitempty"` + Users []*UserInfo `protobuf:"bytes,6,rep" json:"Users,omitempty"` + MaxNodeID *uint64 `protobuf:"varint,7,req" json:"MaxNodeID,omitempty"` + MaxShardGroupID *uint64 `protobuf:"varint,8,req" json:"MaxShardGroupID,omitempty"` + MaxShardID *uint64 `protobuf:"varint,9,req" json:"MaxShardID,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -272,8 +266,8 @@ func (m *Data) GetMaxShardID() uint64 { } type NodeInfo struct { - ID *uint64 `protobuf:"varint,1,req,name=ID" json:"ID,omitempty"` - Host *string `protobuf:"bytes,2,req,name=Host" json:"Host,omitempty"` + ID *uint64 `protobuf:"varint,1,req" json:"ID,omitempty"` + Host *string `protobuf:"bytes,2,req" json:"Host,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -296,10 +290,10 @@ func (m *NodeInfo) GetHost() string { } type DatabaseInfo struct { - Name *string `protobuf:"bytes,1,req,name=Name" json:"Name,omitempty"` - DefaultRetentionPolicy *string `protobuf:"bytes,2,req,name=DefaultRetentionPolicy" json:"DefaultRetentionPolicy,omitempty"` - RetentionPolicies []*RetentionPolicyInfo `protobuf:"bytes,3,rep,name=RetentionPolicies" json:"RetentionPolicies,omitempty"` - ContinuousQueries []*ContinuousQueryInfo `protobuf:"bytes,4,rep,name=ContinuousQueries" json:"ContinuousQueries,omitempty"` + Name *string `protobuf:"bytes,1,req" json:"Name,omitempty"` + DefaultRetentionPolicy *string `protobuf:"bytes,2,req" json:"DefaultRetentionPolicy,omitempty"` + RetentionPolicies []*RetentionPolicyInfo `protobuf:"bytes,3,rep" json:"RetentionPolicies,omitempty"` + ContinuousQueries []*ContinuousQueryInfo `protobuf:"bytes,4,rep" json:"ContinuousQueries,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -336,12 +330,12 @@ func (m *DatabaseInfo) GetContinuousQueries() []*ContinuousQueryInfo { } type RetentionPolicyInfo struct { - Name *string `protobuf:"bytes,1,req,name=Name" json:"Name,omitempty"` - Duration *int64 `protobuf:"varint,2,req,name=Duration" json:"Duration,omitempty"` - ShardGroupDuration *int64 `protobuf:"varint,3,req,name=ShardGroupDuration" json:"ShardGroupDuration,omitempty"` - ReplicaN *uint32 `protobuf:"varint,4,req,name=ReplicaN" json:"ReplicaN,omitempty"` - ShardGroups []*ShardGroupInfo `protobuf:"bytes,5,rep,name=ShardGroups" json:"ShardGroups,omitempty"` - Subscriptions []*SubscriptionInfo `protobuf:"bytes,6,rep,name=Subscriptions" json:"Subscriptions,omitempty"` + Name *string `protobuf:"bytes,1,req" json:"Name,omitempty"` + Duration *int64 `protobuf:"varint,2,req" json:"Duration,omitempty"` + ShardGroupDuration *int64 `protobuf:"varint,3,req" json:"ShardGroupDuration,omitempty"` + ReplicaN *uint32 `protobuf:"varint,4,req" json:"ReplicaN,omitempty"` + ShardGroups []*ShardGroupInfo `protobuf:"bytes,5,rep" json:"ShardGroups,omitempty"` + Subscriptions []*SubscriptionInfo `protobuf:"bytes,6,rep" json:"Subscriptions,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -392,11 +386,11 @@ func (m *RetentionPolicyInfo) GetSubscriptions() []*SubscriptionInfo { } type ShardGroupInfo struct { - ID *uint64 `protobuf:"varint,1,req,name=ID" json:"ID,omitempty"` - StartTime *int64 `protobuf:"varint,2,req,name=StartTime" json:"StartTime,omitempty"` - EndTime *int64 `protobuf:"varint,3,req,name=EndTime" json:"EndTime,omitempty"` - DeletedAt *int64 `protobuf:"varint,4,req,name=DeletedAt" json:"DeletedAt,omitempty"` - Shards []*ShardInfo `protobuf:"bytes,5,rep,name=Shards" json:"Shards,omitempty"` + ID *uint64 `protobuf:"varint,1,req" json:"ID,omitempty"` + StartTime *int64 `protobuf:"varint,2,req" json:"StartTime,omitempty"` + EndTime *int64 `protobuf:"varint,3,req" json:"EndTime,omitempty"` + DeletedAt *int64 `protobuf:"varint,4,req" json:"DeletedAt,omitempty"` + Shards []*ShardInfo `protobuf:"bytes,5,rep" json:"Shards,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -440,9 +434,9 @@ func (m *ShardGroupInfo) GetShards() []*ShardInfo { } type ShardInfo struct { - ID *uint64 `protobuf:"varint,1,req,name=ID" json:"ID,omitempty"` - OwnerIDs []uint64 `protobuf:"varint,2,rep,name=OwnerIDs" json:"OwnerIDs,omitempty"` - Owners []*ShardOwner `protobuf:"bytes,3,rep,name=Owners" json:"Owners,omitempty"` + ID *uint64 `protobuf:"varint,1,req" json:"ID,omitempty"` + OwnerIDs []uint64 `protobuf:"varint,2,rep" json:"OwnerIDs,omitempty"` + Owners []*ShardOwner `protobuf:"bytes,3,rep" json:"Owners,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -472,9 +466,9 @@ func (m *ShardInfo) GetOwners() []*ShardOwner { } type SubscriptionInfo struct { - Name *string `protobuf:"bytes,1,req,name=Name" json:"Name,omitempty"` - Mode *string `protobuf:"bytes,2,req,name=Mode" json:"Mode,omitempty"` - Destinations []string `protobuf:"bytes,3,rep,name=Destinations" json:"Destinations,omitempty"` + Name *string `protobuf:"bytes,1,req" json:"Name,omitempty"` + Mode *string `protobuf:"bytes,2,req" json:"Mode,omitempty"` + Destinations []string `protobuf:"bytes,3,rep" json:"Destinations,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -504,7 +498,7 @@ func (m *SubscriptionInfo) GetDestinations() []string { } type ShardOwner struct { - NodeID *uint64 `protobuf:"varint,1,req,name=NodeID" json:"NodeID,omitempty"` + NodeID *uint64 `protobuf:"varint,1,req" json:"NodeID,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -520,8 +514,8 @@ func (m *ShardOwner) GetNodeID() uint64 { } type ContinuousQueryInfo struct { - Name *string `protobuf:"bytes,1,req,name=Name" json:"Name,omitempty"` - Query *string `protobuf:"bytes,2,req,name=Query" json:"Query,omitempty"` + Name *string `protobuf:"bytes,1,req" json:"Name,omitempty"` + Query *string `protobuf:"bytes,2,req" json:"Query,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -544,10 +538,10 @@ func (m *ContinuousQueryInfo) GetQuery() string { } type UserInfo struct { - Name *string `protobuf:"bytes,1,req,name=Name" json:"Name,omitempty"` - Hash *string `protobuf:"bytes,2,req,name=Hash" json:"Hash,omitempty"` - Admin *bool `protobuf:"varint,3,req,name=Admin" json:"Admin,omitempty"` - Privileges []*UserPrivilege `protobuf:"bytes,4,rep,name=Privileges" json:"Privileges,omitempty"` + Name *string `protobuf:"bytes,1,req" json:"Name,omitempty"` + Hash *string `protobuf:"bytes,2,req" json:"Hash,omitempty"` + Admin *bool `protobuf:"varint,3,req" json:"Admin,omitempty"` + Privileges []*UserPrivilege `protobuf:"bytes,4,rep" json:"Privileges,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -584,8 +578,8 @@ func (m *UserInfo) GetPrivileges() []*UserPrivilege { } type UserPrivilege struct { - Database *string `protobuf:"bytes,1,req,name=Database" json:"Database,omitempty"` - Privilege *int32 `protobuf:"varint,2,req,name=Privilege" json:"Privilege,omitempty"` + Database *string `protobuf:"bytes,1,req" json:"Database,omitempty"` + Privilege *int32 `protobuf:"varint,2,req" json:"Privilege,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -639,8 +633,8 @@ func (m *Command) GetType() Command_Type { } type CreateNodeCommand struct { - Host *string `protobuf:"bytes,1,req,name=Host" json:"Host,omitempty"` - Rand *uint64 `protobuf:"varint,2,req,name=Rand" json:"Rand,omitempty"` + Host *string `protobuf:"bytes,1,req" json:"Host,omitempty"` + Rand *uint64 `protobuf:"varint,2,req" json:"Rand,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -671,8 +665,8 @@ var E_CreateNodeCommand_Command = &proto.ExtensionDesc{ } type DeleteNodeCommand struct { - ID *uint64 `protobuf:"varint,1,req,name=ID" json:"ID,omitempty"` - Force *bool `protobuf:"varint,2,req,name=Force" json:"Force,omitempty"` + ID *uint64 `protobuf:"varint,1,req" json:"ID,omitempty"` + Force *bool `protobuf:"varint,2,req" json:"Force,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -703,7 +697,7 @@ var E_DeleteNodeCommand_Command = &proto.ExtensionDesc{ } type CreateDatabaseCommand struct { - Name *string `protobuf:"bytes,1,req,name=Name" json:"Name,omitempty"` + Name *string `protobuf:"bytes,1,req" json:"Name,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -727,7 +721,7 @@ var E_CreateDatabaseCommand_Command = &proto.ExtensionDesc{ } type DropDatabaseCommand struct { - Name *string `protobuf:"bytes,1,req,name=Name" json:"Name,omitempty"` + Name *string `protobuf:"bytes,1,req" json:"Name,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -751,8 +745,8 @@ var E_DropDatabaseCommand_Command = &proto.ExtensionDesc{ } type CreateRetentionPolicyCommand struct { - Database *string `protobuf:"bytes,1,req,name=Database" json:"Database,omitempty"` - RetentionPolicy *RetentionPolicyInfo `protobuf:"bytes,2,req,name=RetentionPolicy" json:"RetentionPolicy,omitempty"` + Database *string `protobuf:"bytes,1,req" json:"Database,omitempty"` + RetentionPolicy *RetentionPolicyInfo `protobuf:"bytes,2,req" json:"RetentionPolicy,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -783,8 +777,8 @@ var E_CreateRetentionPolicyCommand_Command = &proto.ExtensionDesc{ } type DropRetentionPolicyCommand struct { - Database *string `protobuf:"bytes,1,req,name=Database" json:"Database,omitempty"` - Name *string `protobuf:"bytes,2,req,name=Name" json:"Name,omitempty"` + Database *string `protobuf:"bytes,1,req" json:"Database,omitempty"` + Name *string `protobuf:"bytes,2,req" json:"Name,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -815,8 +809,8 @@ var E_DropRetentionPolicyCommand_Command = &proto.ExtensionDesc{ } type SetDefaultRetentionPolicyCommand struct { - Database *string `protobuf:"bytes,1,req,name=Database" json:"Database,omitempty"` - Name *string `protobuf:"bytes,2,req,name=Name" json:"Name,omitempty"` + Database *string `protobuf:"bytes,1,req" json:"Database,omitempty"` + Name *string `protobuf:"bytes,2,req" json:"Name,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -847,11 +841,11 @@ var E_SetDefaultRetentionPolicyCommand_Command = &proto.ExtensionDesc{ } type UpdateRetentionPolicyCommand struct { - Database *string `protobuf:"bytes,1,req,name=Database" json:"Database,omitempty"` - Name *string `protobuf:"bytes,2,req,name=Name" json:"Name,omitempty"` - NewName *string `protobuf:"bytes,3,opt,name=NewName" json:"NewName,omitempty"` - Duration *int64 `protobuf:"varint,4,opt,name=Duration" json:"Duration,omitempty"` - ReplicaN *uint32 `protobuf:"varint,5,opt,name=ReplicaN" json:"ReplicaN,omitempty"` + Database *string `protobuf:"bytes,1,req" json:"Database,omitempty"` + Name *string `protobuf:"bytes,2,req" json:"Name,omitempty"` + NewName *string `protobuf:"bytes,3,opt" json:"NewName,omitempty"` + Duration *int64 `protobuf:"varint,4,opt" json:"Duration,omitempty"` + ReplicaN *uint32 `protobuf:"varint,5,opt" json:"ReplicaN,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -903,9 +897,9 @@ var E_UpdateRetentionPolicyCommand_Command = &proto.ExtensionDesc{ } type CreateShardGroupCommand struct { - Database *string `protobuf:"bytes,1,req,name=Database" json:"Database,omitempty"` - Policy *string `protobuf:"bytes,2,req,name=Policy" json:"Policy,omitempty"` - Timestamp *int64 `protobuf:"varint,3,req,name=Timestamp" json:"Timestamp,omitempty"` + Database *string `protobuf:"bytes,1,req" json:"Database,omitempty"` + Policy *string `protobuf:"bytes,2,req" json:"Policy,omitempty"` + Timestamp *int64 `protobuf:"varint,3,req" json:"Timestamp,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -943,9 +937,9 @@ var E_CreateShardGroupCommand_Command = &proto.ExtensionDesc{ } type DeleteShardGroupCommand struct { - Database *string `protobuf:"bytes,1,req,name=Database" json:"Database,omitempty"` - Policy *string `protobuf:"bytes,2,req,name=Policy" json:"Policy,omitempty"` - ShardGroupID *uint64 `protobuf:"varint,3,req,name=ShardGroupID" json:"ShardGroupID,omitempty"` + Database *string `protobuf:"bytes,1,req" json:"Database,omitempty"` + Policy *string `protobuf:"bytes,2,req" json:"Policy,omitempty"` + ShardGroupID *uint64 `protobuf:"varint,3,req" json:"ShardGroupID,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -983,9 +977,9 @@ var E_DeleteShardGroupCommand_Command = &proto.ExtensionDesc{ } type CreateContinuousQueryCommand struct { - Database *string `protobuf:"bytes,1,req,name=Database" json:"Database,omitempty"` - Name *string `protobuf:"bytes,2,req,name=Name" json:"Name,omitempty"` - Query *string `protobuf:"bytes,3,req,name=Query" json:"Query,omitempty"` + Database *string `protobuf:"bytes,1,req" json:"Database,omitempty"` + Name *string `protobuf:"bytes,2,req" json:"Name,omitempty"` + Query *string `protobuf:"bytes,3,req" json:"Query,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1023,8 +1017,8 @@ var E_CreateContinuousQueryCommand_Command = &proto.ExtensionDesc{ } type DropContinuousQueryCommand struct { - Database *string `protobuf:"bytes,1,req,name=Database" json:"Database,omitempty"` - Name *string `protobuf:"bytes,2,req,name=Name" json:"Name,omitempty"` + Database *string `protobuf:"bytes,1,req" json:"Database,omitempty"` + Name *string `protobuf:"bytes,2,req" json:"Name,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1055,9 +1049,9 @@ var E_DropContinuousQueryCommand_Command = &proto.ExtensionDesc{ } type CreateUserCommand struct { - Name *string `protobuf:"bytes,1,req,name=Name" json:"Name,omitempty"` - Hash *string `protobuf:"bytes,2,req,name=Hash" json:"Hash,omitempty"` - Admin *bool `protobuf:"varint,3,req,name=Admin" json:"Admin,omitempty"` + Name *string `protobuf:"bytes,1,req" json:"Name,omitempty"` + Hash *string `protobuf:"bytes,2,req" json:"Hash,omitempty"` + Admin *bool `protobuf:"varint,3,req" json:"Admin,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1095,7 +1089,7 @@ var E_CreateUserCommand_Command = &proto.ExtensionDesc{ } type DropUserCommand struct { - Name *string `protobuf:"bytes,1,req,name=Name" json:"Name,omitempty"` + Name *string `protobuf:"bytes,1,req" json:"Name,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1119,8 +1113,8 @@ var E_DropUserCommand_Command = &proto.ExtensionDesc{ } type UpdateUserCommand struct { - Name *string `protobuf:"bytes,1,req,name=Name" json:"Name,omitempty"` - Hash *string `protobuf:"bytes,2,req,name=Hash" json:"Hash,omitempty"` + Name *string `protobuf:"bytes,1,req" json:"Name,omitempty"` + Hash *string `protobuf:"bytes,2,req" json:"Hash,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1151,9 +1145,9 @@ var E_UpdateUserCommand_Command = &proto.ExtensionDesc{ } type SetPrivilegeCommand struct { - Username *string `protobuf:"bytes,1,req,name=Username" json:"Username,omitempty"` - Database *string `protobuf:"bytes,2,req,name=Database" json:"Database,omitempty"` - Privilege *int32 `protobuf:"varint,3,req,name=Privilege" json:"Privilege,omitempty"` + Username *string `protobuf:"bytes,1,req" json:"Username,omitempty"` + Database *string `protobuf:"bytes,2,req" json:"Database,omitempty"` + Privilege *int32 `protobuf:"varint,3,req" json:"Privilege,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1191,7 +1185,7 @@ var E_SetPrivilegeCommand_Command = &proto.ExtensionDesc{ } type SetDataCommand struct { - Data *Data `protobuf:"bytes,1,req,name=Data" json:"Data,omitempty"` + Data *Data `protobuf:"bytes,1,req" json:"Data,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1215,8 +1209,8 @@ var E_SetDataCommand_Command = &proto.ExtensionDesc{ } type SetAdminPrivilegeCommand struct { - Username *string `protobuf:"bytes,1,req,name=Username" json:"Username,omitempty"` - Admin *bool `protobuf:"varint,2,req,name=Admin" json:"Admin,omitempty"` + Username *string `protobuf:"bytes,1,req" json:"Username,omitempty"` + Admin *bool `protobuf:"varint,2,req" json:"Admin,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1247,8 +1241,8 @@ var E_SetAdminPrivilegeCommand_Command = &proto.ExtensionDesc{ } type UpdateNodeCommand struct { - ID *uint64 `protobuf:"varint,1,req,name=ID" json:"ID,omitempty"` - Host *string `protobuf:"bytes,2,req,name=Host" json:"Host,omitempty"` + ID *uint64 `protobuf:"varint,1,req" json:"ID,omitempty"` + Host *string `protobuf:"bytes,2,req" json:"Host,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1278,44 +1272,12 @@ var E_UpdateNodeCommand_Command = &proto.ExtensionDesc{ Tag: "bytes,119,opt,name=command", } -type RenameDatabaseCommand struct { - OldName *string `protobuf:"bytes,1,req,name=oldName" json:"oldName,omitempty"` - NewName *string `protobuf:"bytes,2,req,name=newName" json:"newName,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *RenameDatabaseCommand) Reset() { *m = RenameDatabaseCommand{} } -func (m *RenameDatabaseCommand) String() string { return proto.CompactTextString(m) } -func (*RenameDatabaseCommand) ProtoMessage() {} - -func (m *RenameDatabaseCommand) GetOldName() string { - if m != nil && m.OldName != nil { - return *m.OldName - } - return "" -} - -func (m *RenameDatabaseCommand) GetNewName() string { - if m != nil && m.NewName != nil { - return *m.NewName - } - return "" -} - -var E_RenameDatabaseCommand_Command = &proto.ExtensionDesc{ - ExtendedType: (*Command)(nil), - ExtensionType: (*RenameDatabaseCommand)(nil), - Field: 120, - Name: "internal.RenameDatabaseCommand.command", - Tag: "bytes,120,opt,name=command", -} - type CreateSubscriptionCommand struct { - Name *string `protobuf:"bytes,1,req,name=Name" json:"Name,omitempty"` - Database *string `protobuf:"bytes,2,req,name=Database" json:"Database,omitempty"` - RetentionPolicy *string `protobuf:"bytes,3,req,name=RetentionPolicy" json:"RetentionPolicy,omitempty"` - Mode *string `protobuf:"bytes,4,req,name=Mode" json:"Mode,omitempty"` - Destinations []string `protobuf:"bytes,5,rep,name=Destinations" json:"Destinations,omitempty"` + Name *string `protobuf:"bytes,1,req" json:"Name,omitempty"` + Database *string `protobuf:"bytes,2,req" json:"Database,omitempty"` + RetentionPolicy *string `protobuf:"bytes,3,req" json:"RetentionPolicy,omitempty"` + Mode *string `protobuf:"bytes,4,req" json:"Mode,omitempty"` + Destinations []string `protobuf:"bytes,5,rep" json:"Destinations,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1367,9 +1329,9 @@ var E_CreateSubscriptionCommand_Command = &proto.ExtensionDesc{ } type DropSubscriptionCommand struct { - Name *string `protobuf:"bytes,1,req,name=Name" json:"Name,omitempty"` - Database *string `protobuf:"bytes,2,req,name=Database" json:"Database,omitempty"` - RetentionPolicy *string `protobuf:"bytes,3,req,name=RetentionPolicy" json:"RetentionPolicy,omitempty"` + Name *string `protobuf:"bytes,1,req" json:"Name,omitempty"` + Database *string `protobuf:"bytes,2,req" json:"Database,omitempty"` + RetentionPolicy *string `protobuf:"bytes,3,req" json:"RetentionPolicy,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1407,9 +1369,9 @@ var E_DropSubscriptionCommand_Command = &proto.ExtensionDesc{ } type Response struct { - OK *bool `protobuf:"varint,1,req,name=OK" json:"OK,omitempty"` - Error *string `protobuf:"bytes,2,opt,name=Error" json:"Error,omitempty"` - Index *uint64 `protobuf:"varint,3,opt,name=Index" json:"Index,omitempty"` + OK *bool `protobuf:"varint,1,req" json:"OK,omitempty"` + Error *string `protobuf:"bytes,2,opt" json:"Error,omitempty"` + Index *uint64 `protobuf:"varint,3,opt" json:"Index,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1439,8 +1401,8 @@ func (m *Response) GetIndex() uint64 { } type ResponseHeader struct { - OK *bool `protobuf:"varint,1,req,name=OK" json:"OK,omitempty"` - Error *string `protobuf:"bytes,2,opt,name=Error" json:"Error,omitempty"` + OK *bool `protobuf:"varint,1,req" json:"OK,omitempty"` + Error *string `protobuf:"bytes,2,opt" json:"Error,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1463,7 +1425,7 @@ func (m *ResponseHeader) GetError() string { } type ErrorResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,req,name=Header" json:"Header,omitempty"` + Header *ResponseHeader `protobuf:"bytes,1,req" json:"Header,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1479,9 +1441,9 @@ func (m *ErrorResponse) GetHeader() *ResponseHeader { } type FetchDataRequest struct { - Index *uint64 `protobuf:"varint,1,req,name=Index" json:"Index,omitempty"` - Term *uint64 `protobuf:"varint,2,req,name=Term" json:"Term,omitempty"` - Blocking *bool `protobuf:"varint,3,opt,name=Blocking,def=0" json:"Blocking,omitempty"` + Index *uint64 `protobuf:"varint,1,req" json:"Index,omitempty"` + Term *uint64 `protobuf:"varint,2,req" json:"Term,omitempty"` + Blocking *bool `protobuf:"varint,3,opt,def=0" json:"Blocking,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1513,10 +1475,10 @@ func (m *FetchDataRequest) GetBlocking() bool { } type FetchDataResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,req,name=Header" json:"Header,omitempty"` - Index *uint64 `protobuf:"varint,2,req,name=Index" json:"Index,omitempty"` - Term *uint64 `protobuf:"varint,3,req,name=Term" json:"Term,omitempty"` - Data []byte `protobuf:"bytes,4,opt,name=Data" json:"Data,omitempty"` + Header *ResponseHeader `protobuf:"bytes,1,req" json:"Header,omitempty"` + Index *uint64 `protobuf:"varint,2,req" json:"Index,omitempty"` + Term *uint64 `protobuf:"varint,3,req" json:"Term,omitempty"` + Data []byte `protobuf:"bytes,4,opt" json:"Data,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1553,7 +1515,7 @@ func (m *FetchDataResponse) GetData() []byte { } type JoinRequest struct { - Addr *string `protobuf:"bytes,1,req,name=Addr" json:"Addr,omitempty"` + Addr *string `protobuf:"bytes,1,req" json:"Addr,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -1569,11 +1531,15 @@ func (m *JoinRequest) GetAddr() string { } type JoinResponse struct { - Header *ResponseHeader `protobuf:"bytes,1,req,name=Header" json:"Header,omitempty"` - EnableRaft *bool `protobuf:"varint,2,opt,name=EnableRaft" json:"EnableRaft,omitempty"` - RaftNodes []string `protobuf:"bytes,3,rep,name=RaftNodes" json:"RaftNodes,omitempty"` - NodeID *uint64 `protobuf:"varint,4,opt,name=NodeID" json:"NodeID,omitempty"` - XXX_unrecognized []byte `json:"-"` + Header *ResponseHeader `protobuf:"bytes,1,req" json:"Header,omitempty"` + // Indicates that this node should take part in the raft cluster. + EnableRaft *bool `protobuf:"varint,2,opt" json:"EnableRaft,omitempty"` + // The addresses of raft peers to use if joining as a raft member. If not joining + // as a raft member, these are the nodes running raft. + RaftNodes []string `protobuf:"bytes,3,rep" json:"RaftNodes,omitempty"` + // The node ID assigned to the requesting node. + NodeID *uint64 `protobuf:"varint,4,opt" json:"NodeID,omitempty"` + XXX_unrecognized []byte `json:"-"` } func (m *JoinResponse) Reset() { *m = JoinResponse{} } @@ -1630,7 +1596,6 @@ func init() { proto.RegisterExtension(E_SetDataCommand_Command) proto.RegisterExtension(E_SetAdminPrivilegeCommand_Command) proto.RegisterExtension(E_UpdateNodeCommand_Command) - proto.RegisterExtension(E_RenameDatabaseCommand_Command) proto.RegisterExtension(E_CreateSubscriptionCommand_Command) proto.RegisterExtension(E_DropSubscriptionCommand_Command) } diff --git a/meta/internal/meta.proto b/meta/internal/meta.proto index 25a05fadde..cddcb57dfb 100644 --- a/meta/internal/meta.proto +++ b/meta/internal/meta.proto @@ -275,14 +275,6 @@ message UpdateNodeCommand { required string Host = 2; } -message RenameDatabaseCommand { - extend Command { - optional RenameDatabaseCommand command = 120; - } - required string oldName = 1; - required string newName = 2; -} - message CreateSubscriptionCommand { extend Command { optional CreateSubscriptionCommand command = 121; diff --git a/meta/statement_executor.go b/meta/statement_executor.go index 573a803416..5a6fa4690b 100644 --- a/meta/statement_executor.go +++ b/meta/statement_executor.go @@ -23,7 +23,6 @@ type StatementExecutor struct { Databases() ([]DatabaseInfo, error) CreateDatabase(name string) (*DatabaseInfo, error) DropDatabase(name string) error - RenameDatabase(oldName, newName string) error DefaultRetentionPolicy(database string) (*RetentionPolicyInfo, error) CreateRetentionPolicy(database string, rpi *RetentionPolicyInfo) (*RetentionPolicyInfo, error) @@ -73,8 +72,6 @@ func (e *StatementExecutor) ExecuteStatement(stmt influxql.Statement) *influxql. return e.executeGrantStatement(stmt) case *influxql.GrantAdminStatement: return e.executeGrantAdminStatement(stmt) - case *influxql.RenameDatabaseStatement: - return e.executeRenameDatabaseStatement(stmt) case *influxql.RevokeStatement: return e.executeRevokeStatement(stmt) case *influxql.RevokeAdminStatement: @@ -224,10 +221,6 @@ func (e *StatementExecutor) executeGrantAdminStatement(stmt *influxql.GrantAdmin return &influxql.Result{Err: e.Store.SetAdminPrivilege(stmt.User, true)} } -func (e *StatementExecutor) executeRenameDatabaseStatement(q *influxql.RenameDatabaseStatement) *influxql.Result { - return &influxql.Result{Err: e.Store.RenameDatabase(q.OldName, q.NewName)} -} - func (e *StatementExecutor) executeRevokeStatement(stmt *influxql.RevokeStatement) *influxql.Result { priv := influxql.NoPrivileges diff --git a/meta/statement_executor_test.go b/meta/statement_executor_test.go index bc5fbab1ab..6c3e223475 100644 --- a/meta/statement_executor_test.go +++ b/meta/statement_executor_test.go @@ -46,26 +46,6 @@ func TestStatementExecutor_ExecuteStatement_DropDatabase(t *testing.T) { } } -// Ensure a RENAME DATABASE statement can be executed. -func TestStatementExecutor_ExecuteStatement_RenameDatabase(t *testing.T) { - e := NewStatementExecutor() - e.Store.RenameDatabaseFn = func(oldName, newName string) error { - if oldName != "old_foo" { - t.Fatalf("unexpected name: %s", oldName) - } - if newName != "new_foo" { - t.Fatalf("unexpected name: %s", newName) - } - return nil - } - - if res := e.ExecuteStatement(influxql.MustParseStatement(`RENAME DATABASE old_foo to new_foo`)); res.Err != nil { - t.Fatal(res.Err) - } else if res.Series != nil { - t.Fatalf("unexpected rows: %#v", res.Series) - } -} - // Ensure a SHOW DATABASES statement can be executed. func TestStatementExecutor_ExecuteStatement_ShowDatabases(t *testing.T) { e := NewStatementExecutor() @@ -1056,7 +1036,6 @@ type StatementExecutorStore struct { CreateDatabaseFn func(name string) (*meta.DatabaseInfo, error) DropDatabaseFn func(name string) error DeleteNodeFn func(nodeID uint64, force bool) error - RenameDatabaseFn func(oldName, newName string) error DefaultRetentionPolicyFn func(database string) (*meta.RetentionPolicyInfo, error) CreateRetentionPolicyFn func(database string, rpi *meta.RetentionPolicyInfo) (*meta.RetentionPolicyInfo, error) UpdateRetentionPolicyFn func(database, name string, rpu *meta.RetentionPolicyUpdate) error @@ -1116,10 +1095,6 @@ func (s *StatementExecutorStore) DropDatabase(name string) error { return s.DropDatabaseFn(name) } -func (s *StatementExecutorStore) RenameDatabase(oldName, newName string) error { - return s.RenameDatabaseFn(oldName, newName) -} - func (s *StatementExecutorStore) DefaultRetentionPolicy(database string) (*meta.RetentionPolicyInfo, error) { return s.DefaultRetentionPolicyFn(database) } diff --git a/meta/store.go b/meta/store.go index 05a5b2e260..d5dfaca42a 100644 --- a/meta/store.go +++ b/meta/store.go @@ -927,16 +927,6 @@ func (s *Store) DropDatabase(name string) error { ) } -// RenameDatabase renames a database in the metastore -func (s *Store) RenameDatabase(oldName, newName string) error { - return s.exec(internal.Command_RenameDatabaseCommand, internal.E_RenameDatabaseCommand_Command, - &internal.RenameDatabaseCommand{ - OldName: proto.String(oldName), - NewName: proto.String(newName), - }, - ) -} - // RetentionPolicy returns a retention policy for a database by name. func (s *Store) RetentionPolicy(database, name string) (rpi *RetentionPolicyInfo, err error) { err = s.read(func(data *Data) error { @@ -1668,8 +1658,6 @@ func (fsm *storeFSM) Apply(l *raft.Log) interface{} { return fsm.applyCreateDatabaseCommand(&cmd) case internal.Command_DropDatabaseCommand: return fsm.applyDropDatabaseCommand(&cmd) - case internal.Command_RenameDatabaseCommand: - return fsm.applyRenameDatabaseCommand(&cmd) case internal.Command_CreateRetentionPolicyCommand: return fsm.applyCreateRetentionPolicyCommand(&cmd) case internal.Command_DropRetentionPolicyCommand: @@ -1798,20 +1786,6 @@ func (fsm *storeFSM) applyDropDatabaseCommand(cmd *internal.Command) interface{} return nil } -func (fsm *storeFSM) applyRenameDatabaseCommand(cmd *internal.Command) interface{} { - ext, _ := proto.GetExtension(cmd, internal.E_RenameDatabaseCommand_Command) - v := ext.(*internal.RenameDatabaseCommand) - - // Copy data and update. - other := fsm.data.Clone() - if err := other.RenameDatabase(v.GetOldName(), v.GetNewName()); err != nil { - return err - } - fsm.data = other - - return nil -} - func (fsm *storeFSM) applyCreateRetentionPolicyCommand(cmd *internal.Command) interface{} { ext, _ := proto.GetExtension(cmd, internal.E_CreateRetentionPolicyCommand_Command) v := ext.(*internal.CreateRetentionPolicyCommand) diff --git a/meta/store_test.go b/meta/store_test.go index 730a7e4136..1996f611a8 100644 --- a/meta/store_test.go +++ b/meta/store_test.go @@ -244,76 +244,6 @@ func TestStore_DropDatabase_ErrDatabaseNotFound(t *testing.T) { } } -// Ensure the store can rename an existing database. -func TestStore_RenameDatabase(t *testing.T) { - t.Parallel() - s := MustOpenStore() - defer s.Close() - - // Create three databases. - for i := 0; i < 3; i++ { - if _, err := s.CreateDatabase(fmt.Sprintf("db%d", i)); err != nil { - t.Fatal(err) - } - } - - // Rename database db1, leaving db0 and db2 unchanged. - if err := s.RenameDatabase("db1", "db3"); err != nil { - t.Fatal(err) - } - - // Ensure the nodes are correct. - exp := &meta.DatabaseInfo{Name: "db0"} - if di, _ := s.Database("db0"); !reflect.DeepEqual(di, exp) { - t.Fatalf("unexpected database(0): \ngot: %#v\nexp: %#v", di, exp) - - } - if di, _ := s.Database("db1"); di != nil { - t.Fatalf("unexpected database(1): %#v", di) - } - - exp = &meta.DatabaseInfo{Name: "db2"} - if di, _ := s.Database("db2"); !reflect.DeepEqual(di, exp) { - t.Fatalf("unexpected database(2): \ngot: %#v\nexp: %#v", di, exp) - } - - exp = &meta.DatabaseInfo{Name: "db3"} - if di, _ := s.Database("db3"); !reflect.DeepEqual(di, exp) { - t.Fatalf("unexpected database(2): \ngot: %#v\nexp: %#v", di, exp) - } -} - -// Ensure the store returns an error when renaming a database that doesn't exist. -func TestStore_RenameDatabase_ErrDatabaseNotFound(t *testing.T) { - t.Parallel() - s := MustOpenStore() - defer s.Close() - - if err := s.RenameDatabase("no_such_database", "another_database"); err != meta.ErrDatabaseNotFound { - t.Fatalf("unexpected error: %s", err) - } -} - -// Ensure the store returns an error when renaming a database to a database that already exists. -func TestStore_RenameDatabase_ErrDatabaseExists(t *testing.T) { - t.Parallel() - s := MustOpenStore() - defer s.Close() - - // create two databases - if _, err := s.CreateDatabase("db00"); err != nil { - t.Fatal(err) - } - - if _, err := s.CreateDatabase("db01"); err != nil { - t.Fatal(err) - } - - if err := s.RenameDatabase("db00", "db01"); err != meta.ErrDatabaseExists { - t.Fatalf("unexpected error: %s", err) - } -} - // Ensure the store can create a retention policy on a database. func TestStore_CreateRetentionPolicy(t *testing.T) { t.Parallel()