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

fix(tsi1): wait deleting epoch before dropping shard #18694

Merged
merged 1 commit into from
Jun 25, 2020
Merged
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
27 changes: 23 additions & 4 deletions tsdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,19 +714,20 @@ func (s *Store) DeleteShard(shardID uint64) error {
return nil
}
delete(s.shards, shardID)
delete(s.epochs, shardID)
s.pendingShardDeletes[shardID] = struct{}{}

db := sh.Database()
// Determine if the shard contained any series that are not present in any
// other shards in the database.
shards := s.filterShards(byDatabase(db))
epoch := s.epochs[shardID]
s.mu.Unlock()

// Ensure the pending deletion flag is cleared on exit.
defer func() {
s.mu.Lock()
defer s.mu.Unlock()
delete(s.epochs, shardID)
delete(s.pendingShardDeletes, shardID)
s.databases[db].removeIndexType(sh.IndexType())
}()
Expand Down Expand Up @@ -787,6 +788,15 @@ func (s *Store) DeleteShard(shardID uint64) error {

}

// enter the epoch tracker
guards, gen := epoch.StartWrite()
defer epoch.EndWrite(gen)

// wait for any guards before closing the shard
for _, guard := range guards {
guard.Wait()
}

// Close the shard.
if err := sh.Close(); err != nil {
return err
Expand All @@ -808,16 +818,25 @@ func (s *Store) DeleteDatabase(name string) error {
// no files locally, so nothing to do
return nil
}
shards := s.filterShards(func(sh *Shard) bool {
return sh.database == name
})
shards := s.filterShards(byDatabase(name))
epochs := s.epochsForShards(shards)
s.mu.RUnlock()

if err := s.walkShards(shards, func(sh *Shard) error {
if sh.database != name {
return nil
}

epoch := epochs[sh.id]
// enter the epoch tracker
guards, gen := epoch.StartWrite()
defer epoch.EndWrite(gen)

// wait for any guards before closing the shard
for _, guard := range guards {
guard.Wait()
}

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