@@ -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 .cleanUser , c .parentLogger )
460+ c .usersScanner = cortex_tsdb .NewUsersScanner (c .bucketClient , c .ownUserForCleanUp , c .parentLogger )
461461
462462 // Create the blocks cleaner (service).
463463 c .blocksCleaner = NewBlocksCleaner (BlocksCleanerConfig {
@@ -611,7 +611,7 @@ func (c *Compactor) compactUsers(ctx context.Context) {
611611 }
612612
613613 // Ensure the user ID belongs to our shard.
614- if owned , err := c .ownUser (userID ); err != nil {
614+ if owned , err := c .ownUserForCompaction (userID ); err != nil {
615615 c .compactionRunSkippedTenants .Inc ()
616616 level .Warn (c .logger ).Log ("msg" , "unable to check if user is owned by this shard" , "user" , userID , "err" , err )
617617 continue
@@ -813,15 +813,15 @@ func (c *Compactor) discoverUsers(ctx context.Context) ([]string, error) {
813813 return users , err
814814}
815815
816- func (c * Compactor ) ownUser (userID string ) (bool , error ) {
817- return c .ownUserHelper (userID , false )
816+ func (c * Compactor ) ownUserForCompaction (userID string ) (bool , error ) {
817+ return c .ownUser (userID , false )
818818}
819819
820- func (c * Compactor ) cleanUser (userID string ) (bool , error ) {
821- return c .ownUserHelper (userID , true )
820+ func (c * Compactor ) ownUserForCleanUp (userID string ) (bool , error ) {
821+ return c .ownUser (userID , true )
822822}
823823
824- func (c * Compactor ) ownUserHelper (userID string , isCleanUp bool ) (bool , error ) {
824+ func (c * Compactor ) ownUser (userID string , isCleanUp bool ) (bool , error ) {
825825 if ! c .allowedTenants .IsAllowed (userID ) {
826826 return false , nil
827827 }
@@ -831,7 +831,8 @@ func (c *Compactor) ownUserHelper(userID string, isCleanUp bool) (bool, error) {
831831 return true , nil
832832 }
833833
834- // If we aren't cleaning up user blocks, and we are using shuffle-sharding, ownership is determined by the ring
834+ // If we aren't cleaning up user blocks, and we are using shuffle-sharding, ownership is determined by a subring
835+ // Cleanup should only be owned by a single compactor, as there could be race conditions during block deletion
835836 if ! isCleanUp && c .compactorCfg .ShardingStrategy == util .ShardingStrategyShuffle {
836837 subRing := c .ring .ShuffleShard (userID , c .limits .CompactorTenantShardSize (userID ))
837838
0 commit comments