Skip to content

Commit

Permalink
fix(tsi1): wait deleting epoch before dropping shard
Browse files Browse the repository at this point in the history
  • Loading branch information
dengzhi.ldz committed Mar 13, 2020
1 parent eddae02 commit 90b1d03
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions tsdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ func (s *Store) DeleteShard(shardID uint64) error {
// Determine if the shard contained any series that are not present in any
// other shards in the database.
shards := s.filterShards(byDatabase(db))
epochs := s.epochsForShards(shards)
s.mu.Unlock()

// Ensure the pending deletion flag is cleared on exit.
Expand Down Expand Up @@ -786,6 +787,16 @@ func (s *Store) DeleteShard(shardID uint64) error {

}

epoch := epochs[shardID]
// 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 @@ -807,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

0 comments on commit 90b1d03

Please sign in to comment.