Skip to content

Commit

Permalink
Merge pull request #5691 from influxdata/er-retention-policies
Browse files Browse the repository at this point in the history
Clean up shard data when dropping retention policies
  • Loading branch information
e-dard committed Feb 19, 2016
2 parents 645eb44 + 99a7341 commit 2da8321
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 2da8321

Please sign in to comment.