Skip to content

Commit 3ea1e36

Browse files
committed
rename ownUser function for better readability
Signed-off-by: Roy Chiang <[email protected]>
1 parent dd9681b commit 3ea1e36

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

pkg/compactor/compactor.go

Lines changed: 9 additions & 8 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.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

pkg/compactor/compactor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ func findCompactorByUserID(compactors []*Compactor, logs []*concurrency.SyncBuff
13941394
var log *concurrency.SyncBuffer
13951395

13961396
for i, c := range compactors {
1397-
owned, err := c.ownUser(userID)
1397+
owned, err := c.ownUserForCompaction(userID)
13981398
if err != nil {
13991399
return nil, nil, err
14001400
}

0 commit comments

Comments
 (0)