From 09d7dfbaaee1e8a270f4c52a4e6ceb559e9025a1 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Wed, 15 Jul 2015 11:11:02 -0700 Subject: [PATCH 1/2] Form database path correctly on DROP DATABASE Fixes #3330 --- CHANGELOG.md | 1 + tsdb/store.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f2495b2b33..c46e9fd1aa4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - [#3307](https://github.com/influxdb/influxdb/pull/3307): Fix regression parsing boolean values True/False - [#3304](https://github.com/influxdb/influxdb/pull/3304): Fixed httpd logger to log user from query params. Thanks @jhorwit2 - [#3332](https://github.com/influxdb/influxdb/pull/3332): Add SLIMIT and SOFFSET to string version of AST. +- [#3335](https://github.com/influxdb/influxdb/pull/3335): Don't drop all data on DROP DATABASE. ## v0.9.1 [2015-07-02] diff --git a/tsdb/store.go b/tsdb/store.go index 7693bfbb133..27d68b38a2c 100644 --- a/tsdb/store.go +++ b/tsdb/store.go @@ -120,7 +120,7 @@ func (s *Store) DeleteDatabase(name string, shardIDs []uint64) error { shard.Close() } } - if err := os.RemoveAll(s.path); err != nil { + if err := os.RemoveAll(filepath.Join(s.path, name)); err != nil { return err } delete(s.databaseIndexes, name) From 21ea87432c7e7b714e99fb816f492db981b70d64 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Wed, 15 Jul 2015 11:20:25 -0700 Subject: [PATCH 2/2] Test that DROP DATABASE is isolated --- cmd/influxd/run/server_test.go | 60 ++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/cmd/influxd/run/server_test.go b/cmd/influxd/run/server_test.go index 94340760993..9634073d20d 100644 --- a/cmd/influxd/run/server_test.go +++ b/cmd/influxd/run/server_test.go @@ -149,6 +149,66 @@ func TestServer_Query_DropAndRecreateDatabase(t *testing.T) { } } +func TestServer_Query_DropDatabaseIsolated(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) + } + if err := s.CreateDatabaseAndRetentionPolicy("db1", newRetentionPolicyInfo("rp1", 1, 0)); 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 1st database", + command: `SELECT * FROM cpu`, + 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: "Drop other database", + command: `DROP DATABASE db1`, + exp: `{"results":[{}]}`, + }, + &Query{ + name: "Query data from 1st database and ensure it's still there", + command: `SELECT * FROM cpu`, + 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"}}, + }, + }...) + + 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()) + } + } +} + // Ensure retention policy commands work. func TestServer_RetentionPolicyCommands(t *testing.T) { t.Parallel()