Skip to content

Commit 3cb44ee

Browse files
committed
fix bug where multiple compactors are trying to cleanup the same tenant at once, which results in dangling bucket index
Signed-off-by: Roy Chiang <[email protected]>
1 parent ccbf001 commit 3cb44ee

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pkg/compactor/compactor.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func (c *Compactor) starting(ctx context.Context) error {
457457
c.bucketClient = bucketindex.BucketWithGlobalMarkers(c.bucketClient)
458458

459459
// Create the users scanner.
460-
c.usersScanner = cortex_tsdb.NewUsersScanner(c.bucketClient, c.ownUser, c.parentLogger)
460+
c.usersScanner = cortex_tsdb.NewUsersScanner(c.bucketClient, c.cleanUser, c.parentLogger)
461461

462462
// Create the blocks cleaner (service).
463463
c.blocksCleaner = NewBlocksCleaner(BlocksCleanerConfig{
@@ -814,6 +814,14 @@ func (c *Compactor) discoverUsers(ctx context.Context) ([]string, error) {
814814
}
815815

816816
func (c *Compactor) ownUser(userID string) (bool, error) {
817+
return c.ownUserHelper(userID, false)
818+
}
819+
820+
func (c *Compactor) cleanUser(userID string) (bool, error) {
821+
return c.ownUserHelper(userID, true)
822+
}
823+
824+
func (c *Compactor) ownUserHelper(userID string, isCleanUp bool) (bool, error) {
817825
if !c.allowedTenants.IsAllowed(userID) {
818826
return false, nil
819827
}
@@ -823,8 +831,8 @@ func (c *Compactor) ownUser(userID string) (bool, error) {
823831
return true, nil
824832
}
825833

826-
// If using shuffle-sharding, ownership is determined by the ring
827-
if c.compactorCfg.ShardingStrategy == util.ShardingStrategyShuffle {
834+
// If we aren't cleaning up user blocks, and we are using shuffle-sharding, ownership is determined by the ring
835+
if !isCleanUp && c.compactorCfg.ShardingStrategy == util.ShardingStrategyShuffle {
828836
subRing := c.ring.ShuffleShard(userID, c.limits.CompactorTenantShardSize(userID))
829837

830838
rs, err := subRing.GetAllHealthy(RingOp)

0 commit comments

Comments
 (0)