commit
ddca29a87b
|
@ -16,7 +16,6 @@
|
|||
- [#4310](https://github.com/influxdb/influxdb/pull/4310): Support dropping non-Raft nodes. Work mostly by @corylanou
|
||||
- [#4348](https://github.com/influxdb/influxdb/pull/4348): Public ApplyTemplate function for graphite parser.
|
||||
- [#4178](https://github.com/influxdb/influxdb/pull/4178): Support fields in graphite parser. Thanks @roobert!
|
||||
- [#4291](https://github.com/influxdb/influxdb/pull/4291): Added ALTER DATABASE RENAME. Thanks @linearb
|
||||
- [#4409](https://github.com/influxdb/influxdb/pull/4409): wire up INTO queries.
|
||||
- [#4379](https://github.com/influxdb/influxdb/pull/4379): Auto-create database for UDP input.
|
||||
- [#4375](https://github.com/influxdb/influxdb/pull/4375): Add Subscriptions so data can be 'forked' out of InfluxDB to another third party.
|
||||
|
|
|
@ -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: `ALTER DATABASE db1 RENAME 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: `ALTER DATABASE db4 RENAME TO db5`,
|
||||
exp: `{"results":[{"error":"database not found"}]}`,
|
||||
},
|
||||
&Query{
|
||||
name: "rename database to illegal name should fail",
|
||||
command: `ALTER DATABASE db2 RENAME TO 0xdb0`,
|
||||
exp: `{"error":"error parsing query: found 0, expected identifier at line 1, char 30"}`,
|
||||
},
|
||||
&Query{
|
||||
name: "rename database to already existing datbase should fail",
|
||||
command: `ALTER DATABASE db2 RENAME 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"]}]}]}`,
|
||||
},
|
||||
|
@ -266,96 +241,6 @@ func TestServer_Query_DropDatabaseIsolated(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestServer_Query_RenameDatabase(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := OpenServer(NewConfig(), "")
|
||||
defer s.Close()
|
||||
|
||||
if err := s.CreateDatabaseAndRetentionPolicy("db0", newRetentionPolicyInfo("rp0", 1, 0)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.MetaStore.SetDefaultRetentionPolicy("db0", "rp0"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
writes := []string{
|
||||
fmt.Sprintf(`cpu,host=serverA,region=uswest val=23.2 %d`, mustParseTime(time.RFC3339Nano, "2000-01-01T00:00:00Z").UnixNano()),
|
||||
}
|
||||
|
||||
test := NewTest("db0", "rp0")
|
||||
test.write = strings.Join(writes, "\n")
|
||||
|
||||
test.addQueries([]*Query{
|
||||
&Query{
|
||||
name: "Query data from db0 database",
|
||||
command: `SELECT * FROM cpu`,
|
||||
exp: `{"results":[{"series":[{"name":"cpu","columns":["time","host","region","val"],"values":[["2000-01-01T00:00:00Z","serverA","uswest",23.2]]}]}]}`,
|
||||
params: url.Values{"db": []string{"db0"}},
|
||||
},
|
||||
&Query{
|
||||
name: "Query data from db0 database with GROUP BY *",
|
||||
command: `SELECT * FROM cpu GROUP BY *`,
|
||||
exp: `{"results":[{"series":[{"name":"cpu","tags":{"host":"serverA","region":"uswest"},"columns":["time","val"],"values":[["2000-01-01T00:00:00Z",23.2]]}]}]}`,
|
||||
params: url.Values{"db": []string{"db0"}},
|
||||
},
|
||||
&Query{
|
||||
name: "Create continuous query using db0",
|
||||
command: `CREATE CONTINUOUS QUERY "cq1" ON db0 BEGIN SELECT count(value) INTO "rp1".:MEASUREMENT FROM cpu GROUP BY time(5s) END`,
|
||||
exp: `{"results":[{}]}`,
|
||||
},
|
||||
&Query{
|
||||
name: "Rename database should fail because of conflicting CQ",
|
||||
command: `ALTER DATABASE db0 RENAME TO db1`,
|
||||
exp: `{"results":[{"error":"database rename conflict with existing continuous query"}]}`,
|
||||
},
|
||||
&Query{
|
||||
name: "Drop conflicting CQ",
|
||||
command: `DROP CONTINUOUS QUERY "cq1" on db0`,
|
||||
exp: `{"results":[{}]}`,
|
||||
},
|
||||
&Query{
|
||||
name: "Rename database should succeed now",
|
||||
command: `ALTER DATABASE db0 RENAME TO db1`,
|
||||
exp: `{"results":[{}]}`,
|
||||
},
|
||||
&Query{
|
||||
name: "Query data from db0 database and ensure it's gone",
|
||||
command: `SELECT * FROM cpu`,
|
||||
exp: `{"results":[{"error":"database not found: db0"}]}`,
|
||||
params: url.Values{"db": []string{"db0"}},
|
||||
},
|
||||
&Query{
|
||||
name: "Query data from now renamed database db1 and ensure that's there",
|
||||
command: `SELECT * FROM cpu`,
|
||||
exp: `{"results":[{"series":[{"name":"cpu","columns":["time","host","region","val"],"values":[["2000-01-01T00:00:00Z","serverA","uswest",23.2]]}]}]}`,
|
||||
params: url.Values{"db": []string{"db1"}},
|
||||
},
|
||||
&Query{
|
||||
name: "Query data from now renamed database db1 and ensure it's still there with GROUP BY *",
|
||||
command: `SELECT * FROM cpu GROUP BY *`,
|
||||
exp: `{"results":[{"series":[{"name":"cpu","tags":{"host":"serverA","region":"uswest"},"columns":["time","val"],"values":[["2000-01-01T00:00:00Z",23.2]]}]}]}`,
|
||||
params: url.Values{"db": []string{"db1"}},
|
||||
},
|
||||
}...)
|
||||
|
||||
for i, query := range test.queries {
|
||||
if i == 0 {
|
||||
if err := test.init(s); err != nil {
|
||||
t.Fatalf("test init failed: %s", err)
|
||||
}
|
||||
}
|
||||
if query.skip {
|
||||
t.Logf("SKIP:: %s", query.name)
|
||||
continue
|
||||
}
|
||||
if err := query.Execute(s); err != nil {
|
||||
t.Error(query.Error(err))
|
||||
} else if !query.success() {
|
||||
t.Error(query.failureMessage())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_Query_DropAndRecreateSeries(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := OpenServer(NewConfig(), "")
|
||||
|
|
|
@ -80,7 +80,6 @@ type Node interface {
|
|||
func (*Query) node() {}
|
||||
func (Statements) node() {}
|
||||
|
||||
func (*AlterDatabaseRenameStatement) node() {}
|
||||
func (*AlterRetentionPolicyStatement) node() {}
|
||||
func (*CreateContinuousQueryStatement) node() {}
|
||||
func (*CreateDatabaseStatement) node() {}
|
||||
|
@ -192,7 +191,6 @@ type ExecutionPrivilege struct {
|
|||
// ExecutionPrivileges is a list of privileges required to execute a statement.
|
||||
type ExecutionPrivileges []ExecutionPrivilege
|
||||
|
||||
func (*AlterDatabaseRenameStatement) stmt() {}
|
||||
func (*AlterRetentionPolicyStatement) stmt() {}
|
||||
func (*CreateContinuousQueryStatement) stmt() {}
|
||||
func (*CreateDatabaseStatement) stmt() {}
|
||||
|
@ -510,30 +508,6 @@ func (s *GrantAdminStatement) RequiredPrivileges() ExecutionPrivileges {
|
|||
return ExecutionPrivileges{{Admin: true, Name: "", Privilege: AllPrivileges}}
|
||||
}
|
||||
|
||||
// AlterDatabaseRenameStatement represents a command for renaming a database.
|
||||
type AlterDatabaseRenameStatement 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 *AlterDatabaseRenameStatement) String() string {
|
||||
var buf bytes.Buffer
|
||||
_, _ = buf.WriteString("ALTER DATABASE ")
|
||||
_, _ = buf.WriteString(s.OldName)
|
||||
_, _ = buf.WriteString(" RENAME ")
|
||||
_, _ = buf.WriteString(" TO ")
|
||||
_, _ = buf.WriteString(s.NewName)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// RequiredPrivileges returns the privilege required to execute an AlterDatabaseRenameStatement.
|
||||
func (s *AlterDatabaseRenameStatement) RequiredPrivileges() ExecutionPrivileges {
|
||||
return ExecutionPrivileges{{Admin: true, Name: "", Privilege: AllPrivileges}}
|
||||
}
|
||||
|
||||
// SetPasswordUserStatement represents a command for changing user password.
|
||||
type SetPasswordUserStatement struct {
|
||||
// Plain Password
|
||||
|
|
|
@ -226,18 +226,14 @@ func (p *Parser) parseDropStatement() (Statement, error) {
|
|||
// This function assumes the ALTER token has already been consumed.
|
||||
func (p *Parser) parseAlterStatement() (Statement, error) {
|
||||
tok, pos, lit := p.scanIgnoreWhitespace()
|
||||
|
||||
switch tok {
|
||||
case RETENTION:
|
||||
if tok == RETENTION {
|
||||
if tok, pos, lit = p.scanIgnoreWhitespace(); tok != POLICY {
|
||||
return nil, newParseError(tokstr(tok, lit), []string{"POLICY"}, pos)
|
||||
}
|
||||
return p.parseAlterRetentionPolicyStatement()
|
||||
case DATABASE:
|
||||
return p.parseAlterDatabaseRenameStatement()
|
||||
}
|
||||
|
||||
return nil, newParseError(tokstr(tok, lit), []string{"RETENTION", "DATABASE"}, pos)
|
||||
return nil, newParseError(tokstr(tok, lit), []string{"RETENTION"}, pos)
|
||||
}
|
||||
|
||||
// parseSetPasswordUserStatement parses a string and returns a set statement.
|
||||
|
@ -1472,33 +1468,6 @@ func (p *Parser) parseDropDatabaseStatement() (*DropDatabaseStatement, error) {
|
|||
return stmt, nil
|
||||
}
|
||||
|
||||
// parseAlterDatabaseRenameStatement parses a string and returns an AlterDatabaseRenameStatement.
|
||||
// This function assumes the "ALTER DATABASE" tokens have already been consumed.
|
||||
func (p *Parser) parseAlterDatabaseRenameStatement() (*AlterDatabaseRenameStatement, error) {
|
||||
stmt := &AlterDatabaseRenameStatement{}
|
||||
|
||||
// Parse the name of the database to be renamed.
|
||||
lit, err := p.parseIdent()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
stmt.OldName = lit
|
||||
|
||||
// Parse required RENAME TO tokens.
|
||||
if err := p.parseTokens([]Token{RENAME, TO}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
|
|
@ -1436,12 +1436,6 @@ func TestParser_ParseStatement(t *testing.T) {
|
|||
stmt: newAlterRetentionPolicyStatement("default", "testdb", -1, 4, false),
|
||||
},
|
||||
|
||||
// ALTER DATABASE RENAME
|
||||
{
|
||||
s: `ALTER DATABASE db0 RENAME TO db1`,
|
||||
stmt: newAlterDatabaseRenameStatement("db0", "db1"),
|
||||
},
|
||||
|
||||
// SHOW STATS
|
||||
{
|
||||
s: `SHOW STATS`,
|
||||
|
@ -1705,15 +1699,11 @@ func TestParser_ParseStatement(t *testing.T) {
|
|||
{s: `CREATE RETENTION POLICY policy1 ON testdb DURATION 1h REPLICATION 0`, err: `invalid value 0: must be 1 <= n <= 2147483647 at line 1, char 67`},
|
||||
{s: `CREATE RETENTION POLICY policy1 ON testdb DURATION 1h REPLICATION bad`, err: `found bad, expected number at line 1, char 67`},
|
||||
{s: `CREATE RETENTION POLICY policy1 ON testdb DURATION 1h REPLICATION 1 foo`, err: `found foo, expected DEFAULT at line 1, char 69`},
|
||||
{s: `ALTER`, err: `found EOF, expected RETENTION, DATABASE at line 1, char 7`},
|
||||
{s: `ALTER`, err: `found EOF, expected RETENTION at line 1, char 7`},
|
||||
{s: `ALTER RETENTION`, err: `found EOF, expected POLICY at line 1, char 17`},
|
||||
{s: `ALTER RETENTION POLICY`, err: `found EOF, expected identifier at line 1, char 24`},
|
||||
{s: `ALTER RETENTION POLICY policy1`, err: `found EOF, expected ON at line 1, char 32`}, {s: `ALTER RETENTION POLICY policy1 ON`, err: `found EOF, expected identifier at line 1, char 35`},
|
||||
{s: `ALTER RETENTION POLICY policy1 ON testdb`, err: `found EOF, expected DURATION, RETENTION, DEFAULT at line 1, char 42`},
|
||||
{s: `ALTER DATABASE`, err: `found EOF, expected identifier at line 1, char 16`},
|
||||
{s: `ALTER DATABASE db0`, err: `found EOF, expected RENAME at line 1, char 20`},
|
||||
{s: `ALTER DATABASE db0 RENAME`, err: `found EOF, expected TO at line 1, char 27`},
|
||||
{s: `ALTER DATABASE db0 RENAME TO`, err: `found EOF, expected identifier at line 1, char 30`},
|
||||
{s: `SET`, err: `found EOF, expected PASSWORD at line 1, char 5`},
|
||||
{s: `SET PASSWORD`, err: `found EOF, expected FOR at line 1, char 14`},
|
||||
{s: `SET PASSWORD something`, err: `found something, expected FOR at line 1, char 14`},
|
||||
|
@ -2147,14 +2137,6 @@ func newAlterRetentionPolicyStatement(name string, DB string, d time.Duration, r
|
|||
return stmt
|
||||
}
|
||||
|
||||
// newAlterDatabaseRenameStatement creates an initialized AlterDatabaseRenameStatement.
|
||||
func newAlterDatabaseRenameStatement(oldName, newName string) *influxql.AlterDatabaseRenameStatement {
|
||||
return &influxql.AlterDatabaseRenameStatement{
|
||||
OldName: oldName,
|
||||
NewName: newName,
|
||||
}
|
||||
}
|
||||
|
||||
// mustMarshalJSON encodes a value to JSON.
|
||||
func mustMarshalJSON(v interface{}) []byte {
|
||||
b, err := json.Marshal(v)
|
||||
|
|
|
@ -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},
|
||||
|
|
|
@ -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",
|
||||
|
|
65
meta/data.go
65
meta/data.go
|
@ -1,9 +1,7 @@
|
|||
package meta
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
|
@ -179,69 +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
|
||||
}
|
||||
// TODO should rename database in continuous queries also
|
||||
// for now, just return an error if there is a possible conflict
|
||||
if data.isDatabaseNameUsedInCQ(oldName) {
|
||||
return ErrDatabaseRenameCQConflict
|
||||
}
|
||||
// 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
|
||||
data.switchDatabaseUserPrivileges(oldName, newName)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return ErrDatabaseNotFound
|
||||
}
|
||||
|
||||
// isDatabaseNameUsedInCQ returns true if a database name is used in any continuous query
|
||||
func (data *Data) isDatabaseNameUsedInCQ(dbName string) bool {
|
||||
CQOnDb := fmt.Sprintf(" ON %s ", dbName)
|
||||
CQIntoDb := fmt.Sprintf(" INTO \"%s\".", dbName)
|
||||
CQFromDb := fmt.Sprintf(" FROM \"%s\".", dbName)
|
||||
for i := range data.Databases {
|
||||
for j := range data.Databases[i].ContinuousQueries {
|
||||
query := data.Databases[i].ContinuousQueries[j].Query
|
||||
if strings.Contains(query, CQOnDb) {
|
||||
return true
|
||||
}
|
||||
if strings.Contains(query, CQIntoDb) {
|
||||
return true
|
||||
}
|
||||
if strings.Contains(query, CQFromDb) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// switchDatabaseUserPrivileges changes the database associated with user privileges
|
||||
func (data *Data) switchDatabaseUserPrivileges(oldDatabase, newDatabase string) error {
|
||||
for i := range data.Users {
|
||||
if p, ok := data.Users[i].Privileges[oldDatabase]; ok {
|
||||
data.Users[i].Privileges[newDatabase] = p
|
||||
delete(data.Users[i].Privileges, oldDatabase)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RetentionPolicy returns a retention policy for a database by name.
|
||||
func (data *Data) RetentionPolicy(database, name string) (*RetentionPolicyInfo, error) {
|
||||
di := data.Database(database)
|
||||
|
|
|
@ -135,97 +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 user privileges are updated correctly when database is renamed.
|
||||
func TestData_RenameDatabaseUpdatesPrivileges(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)
|
||||
}
|
||||
}
|
||||
|
||||
data.Users = []meta.UserInfo{{
|
||||
Name: "susy",
|
||||
Hash: "ABC123",
|
||||
Admin: true,
|
||||
Privileges: map[string]influxql.Privilege{
|
||||
"db1": influxql.AllPrivileges, "db0": influxql.ReadPrivilege}}}
|
||||
|
||||
if err := data.RenameDatabase("db1", "db2"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !reflect.DeepEqual(data.Users,
|
||||
[]meta.UserInfo{{
|
||||
Name: "susy",
|
||||
Hash: "ABC123",
|
||||
Admin: true,
|
||||
Privileges: map[string]influxql.Privilege{
|
||||
"db2": influxql.AllPrivileges, "db0": influxql.ReadPrivilege}}}) {
|
||||
t.Fatalf("unexpected user privileges: %#v", data.Users)
|
||||
}
|
||||
}
|
||||
|
||||
// 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 that renaming a database returns an error if there is a possibly conflicting CQ
|
||||
func TestData_RenameDatabase_ErrDatabaseCQConflict(t *testing.T) {
|
||||
var data meta.Data
|
||||
if err := data.CreateDatabase("db0"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if err := data.CreateDatabase("db1"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if err := data.CreateContinuousQuery("db0", "cq0", `CREATE CONTINUOUS QUERY cq0 ON db0 BEGIN SELECT count() INTO "foo"."default"."bar" FROM "foo"."foobar" END`); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if err := data.CreateContinuousQuery("db1", "cq1", `CREATE CONTINUOUS QUERY cq1 ON db1 BEGIN SELECT count() INTO "db1"."default"."bar" FROM "db0"."foobar" END`); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if err := data.CreateContinuousQuery("db1", "cq2", `CREATE CONTINUOUS QUERY cq2 ON db1 BEGIN SELECT count() INTO "db0"."default"."bar" FROM "db1"."foobar" END`); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if err := data.CreateContinuousQuery("db1", "noconflict", `CREATE CONTINUOUS QUERY noconflict ON db1 BEGIN SELECT count() INTO "db1"."default"."bar" FROM "db1"."foobar" END`); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if err := data.RenameDatabase("db0", "db2"); err == nil {
|
||||
t.Fatalf("unexpected rename database success despite cq conflict")
|
||||
} else if err := data.DropContinuousQuery("db0", "cq0"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if err := data.RenameDatabase("db0", "db2"); err == nil {
|
||||
t.Fatalf("unexpected rename database success despite cq conflict")
|
||||
} else if err := data.DropContinuousQuery("db1", "cq1"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if err := data.RenameDatabase("db0", "db2"); err == nil {
|
||||
t.Fatalf("unexpected rename database success despite cq conflict")
|
||||
} else if err := data.DropContinuousQuery("db1", "cq2"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if err := data.RenameDatabase("db0", "db2"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure a retention policy can be created.
|
||||
func TestData_CreateRetentionPolicy(t *testing.T) {
|
||||
data := meta.Data{Nodes: []meta.NodeInfo{{ID: 1}, {ID: 2}}}
|
||||
|
|
|
@ -47,9 +47,6 @@ var (
|
|||
|
||||
// ErrDatabaseNameRequired is returned when creating a database without a name.
|
||||
ErrDatabaseNameRequired = newError("database name required")
|
||||
|
||||
// ErrDatabaseRenameCQConflict is returned when attempting to rename a database in use by a CQ.
|
||||
ErrDatabaseRenameCQConflict = newError("database rename conflict with existing continuous query")
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -112,7 +112,6 @@ message Command {
|
|||
SetDataCommand = 17;
|
||||
SetAdminPrivilegeCommand = 18;
|
||||
UpdateNodeCommand = 19;
|
||||
RenameDatabaseCommand = 20;
|
||||
CreateSubscriptionCommand = 21;
|
||||
DropSubscriptionCommand = 22;
|
||||
}
|
||||
|
@ -276,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;
|
||||
|
|
|
@ -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.AlterDatabaseRenameStatement:
|
||||
return e.executeAlterDatabaseRenameStatement(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) executeAlterDatabaseRenameStatement(q *influxql.AlterDatabaseRenameStatement) *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
|
||||
|
||||
|
|
|
@ -46,26 +46,6 @@ func TestStatementExecutor_ExecuteStatement_DropDatabase(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// Ensure an ALTER DATABASE ... RENAME TO ... statement can be executed.
|
||||
func TestStatementExecutor_ExecuteStatement_AlterDatabaseRename(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(`ALTER DATABASE old_foo RENAME 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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue