Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DROP DATABASE should remove entry from TSDB index #3090

Merged
merged 3 commits into from
Jun 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- [#3030](https://github.com/influxdb/influxdb/pull/3030): Fix excessive logging of shard creation.
- [#3038](https://github.com/influxdb/influxdb/pull/3038): Don't check deleted shards for precreation. Thanks @vladlopes.
- [#3033](https://github.com/influxdb/influxdb/pull/3033): Add support for marshaling `uint64` in client.
- [#3090](https://github.com/influxdb/influxdb/pull/3090): Remove database from TSDB index on DROP DATABASE.

## v0.9.0 [2015-06-11]

Expand Down
67 changes: 67 additions & 0 deletions cmd/influxd/run/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,73 @@ func TestServer_DatabaseCommands(t *testing.T) {
}
}

func TestServer_Query_DropAndRecreateDatabase(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: "Drop database after data write",
command: `DROP DATABASE db0`,
exp: `{"results":[{}]}`,
},
&Query{
name: "Recreate database",
command: `CREATE DATABASE db0`,
exp: `{"results":[{}]}`,
},
&Query{
name: "Recreate retention policy",
command: `CREATE RETENTION POLICY rp0 ON db0 DURATION 365d REPLICATION 1 DEFAULT`,
exp: `{"results":[{}]}`,
},
&Query{
name: "Show measurements after recreate",
command: `SHOW MEASUREMENTS`,
exp: `{"results":[{}]}`,
params: url.Values{"db": []string{"db0"}},
},
&Query{
name: "Query data after recreate",
command: `SELECT * FROM cpu`,
exp: `{"results":[{"error":"measurement not found: \"db0\"..cpu"}]}`,
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()
Expand Down
5 changes: 3 additions & 2 deletions tsdb/query_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,11 @@ func (q *QueryExecutor) expandWildcards(stmt *influxql.SelectStatement) (*influx
// Iterate measurements in the FROM clause getting the fields & dimensions for each.
for _, src := range stmt.Sources {
if m, ok := src.(*influxql.Measurement); ok {
// Lookup the database.
// Lookup the database. The database may not exist if no data for this database
// was ever written to the shard.
db := q.store.DatabaseIndex(m.Database)
if db == nil {
return nil, nil
return stmt, nil
}

// Lookup the measurement in the database.
Expand Down
6 changes: 5 additions & 1 deletion tsdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ func (s *Store) DeleteDatabase(name string, shardIDs []uint64) error {
shard.Close()
}
}
return os.RemoveAll(s.path)
if err := os.RemoveAll(s.path); err != nil {
return err
}
delete(s.databaseIndexes, name)
return nil
}

func (s *Store) Shard(shardID uint64) *Shard {
Expand Down