Skip to content

Commit

Permalink
Wire up DROP retention policy to TSDB store.
Browse files Browse the repository at this point in the history
Fixes #5653 and #5394.

Previously dropping retention policies did not propogate to local TSDB
shards. Instead, the retention policiess would just be removed from the
Meta Store.

This PR adds ensures that data associated with retention policies is
removed, when the retention policy is dropped.

Also, it cleans up a couple of other methods in `tsdb`, including the
requirement to provide (redundant) shardIDs when deleting databases.
  • Loading branch information
e-dard committed Feb 19, 2016
1 parent 645eb44 commit 99a7341
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 76 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
- [#5666](https://github.com/influxdata/influxdb/pull/5666): Manage dependencies with gdm
- [#5512](https://github.com/influxdata/influxdb/pull/5512): HTTP: Add config option to enable HTTP JSON write path which is now disabled by default.
- [#5336](https://github.com/influxdata/influxdb/pull/5366): Enabled golint for influxql. @gabelev
- [#5706](https://github.com/influxdata/influxdb/pull/5706): Cluster setup
cleanup
- [#5706](https://github.com/influxdata/influxdb/pull/5706): Cluster setup cleanup
- [#5691](https://github.com/influxdata/influxdb/pull/5691): Remove associated shard data when retention policies are dropped.

### Bugfixes

Expand Down
27 changes: 16 additions & 11 deletions cluster/query_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,24 +293,29 @@ func (e *QueryExecutor) executeDropDatabaseStatement(stmt *influxql.DropDatabase
return err
}

// Retrieve a list of all shard ids.
var shardIDs []uint64
for _, rp := range dbi.RetentionPolicies {
for _, sg := range rp.ShardGroups {
for _, s := range sg.Shards {
shardIDs = append(shardIDs, s.ID)
}
}
}

// Remove the database from the local store
if err := e.TSDBStore.DeleteDatabase(stmt.Name, shardIDs); err != nil {
if err := e.TSDBStore.DeleteDatabase(stmt.Name); err != nil {
return err
}

return nil
}

// executeDropRetentionPolicy closes all local shards for the retention
// policy and removes the directory.
func (q *QueryExecutor) executeDropRetentionPolicy(stmt *influxql.DropRetentionPolicyStatement) error {
// Check if the database and retention policy exist.
if _, err := q.MetaClient.RetentionPolicy(stmt.Database, stmt.Name); err != nil {
return err
}

// Remove the retention policy from the local store.
if err := q.TSDBStore.DeleteRetentionPolicy(stmt.Database, stmt.Name); err != nil {
return err
}
return q.MetaClient.DropRetentionPolicy(stmt.Database, stmt.Name)
}

func (e *QueryExecutor) executeDropMeasurementStatement(stmt *influxql.DropMeasurementStatement, database string) error {
return e.TSDBStore.DeleteMeasurement(database, stmt.Name)
}
Expand Down
2 changes: 1 addition & 1 deletion services/meta/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func (c *Client) RetentionPolicy(database, name string) (rpi *RetentionPolicyInf

// TODO: This should not be handled here
if db == nil {
return nil, ErrDatabaseNotExists
return nil, influxdb.ErrDatabaseNotFound(database)
}

return db.RetentionPolicy(name), nil
Expand Down
Loading

0 comments on commit 99a7341

Please sign in to comment.