Skip to content

Commit

Permalink
Unload index before closing shard
Browse files Browse the repository at this point in the history
When deleting a shard, the shard is locked and then removed from the
index.  Removal from the index can be slow if there are a lot of
series.  During this time, the shard is still expected to exist by
the meta store and tsdb store so stats collections, queries and writes
could all be run on this shard while it's locked.  This can cause everything
to lock up until the unindexing completes and the shard can be unlocked.

Fixes #7226
  • Loading branch information
jwilder committed Sep 16, 2016
1 parent cd7c399 commit d06b289
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- [#7231](https://github.com/influxdata/influxdb/issues/7231): Duplicate parsing bug in ALTER RETENTION POLICY.
- [#7285](https://github.com/influxdata/influxdb/issues/7285): Correctly use password-type field in Admin UI. Thanks @dandv!
- [#2792](https://github.com/influxdata/influxdb/issues/2792): Exceeding max retention policy duration gives incorrect error message
- [#7226](https://github.com/influxdata/influxdb/issues/7226): Fix database locked up when deleting shards

## v1.0.0 [2016-09-08]

Expand Down
8 changes: 7 additions & 1 deletion tsdb/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ func (s *Shard) Open() error {
return nil
}

// UnloadIndex removes all references to this shard from the DatabaseIndex
func (s *Shard) UnloadIndex() {
// Don't leak our shard ID and series keys in the index
s.index.RemoveShard(s.id)
}

// Close shuts down the shard's store.
func (s *Shard) Close() error {
s.mu.Lock()
Expand All @@ -283,7 +289,7 @@ func (s *Shard) close() error {
}

// Don't leak our shard ID and series keys in the index
s.index.RemoveShard(s.id)
s.UnloadIndex()

err := s.engine.Close()
if err == nil {
Expand Down
5 changes: 5 additions & 0 deletions tsdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ func (s *Store) DeleteShard(shardID uint64) error {
return nil
}

// Remove the shard from the database indexes before closing the shard.
// Closing the shard will do this as well, but it will unload it while
// the shard is locked which can block stats collection and other calls.
sh.UnloadIndex()

if err := sh.Close(); err != nil {
return err
}
Expand Down

0 comments on commit d06b289

Please sign in to comment.