Ensure orphaned series removed from inmem index
This commit ensures that any orphaned series (series that are to be removed and no longer are referenced anywhere in the database) are removed from the `inmem` index when a shard is dropped.pull/10212/head
parent
dece5b847f
commit
f52de2d1e7
|
@ -678,9 +678,6 @@ func (s *Store) DeleteShard(shardID uint64) error {
|
|||
ss := index.SeriesIDSet()
|
||||
|
||||
db := sh.Database()
|
||||
if err := sh.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Determine if the shard contained any series that are not present in any
|
||||
// other shards in the database.
|
||||
|
@ -701,10 +698,42 @@ func (s *Store) DeleteShard(shardID uint64) error {
|
|||
if ss.Cardinality() > 0 {
|
||||
sfile := s.seriesFile(db)
|
||||
if sfile != nil {
|
||||
// If the inmem index is in use, then the series being removed from the
|
||||
// series file will also need to be removed from the index.
|
||||
if index.Type() == InmemIndexName {
|
||||
var keyBuf []byte // Series key buffer.
|
||||
var name []byte
|
||||
var tagsBuf models.Tags // Buffer for tags container.
|
||||
var err error
|
||||
|
||||
ss.ForEach(func(id uint64) {
|
||||
skey := sfile.SeriesKey(id) // Series File series key
|
||||
if skey == nil {
|
||||
return
|
||||
}
|
||||
|
||||
name, tagsBuf = ParseSeriesKeyInto(skey, tagsBuf)
|
||||
keyBuf = models.AppendMakeKey(keyBuf, name, tagsBuf)
|
||||
if err = index.DropSeriesGlobal(keyBuf); err != nil {
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
ss.ForEach(func(id uint64) {
|
||||
sfile.DeleteSeriesID(id)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Close the shard.
|
||||
if err := sh.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Remove the on-disk shard data.
|
||||
|
|
Loading…
Reference in New Issue