Skip to content

Commit

Permalink
Shuffle User Order in UsersScanner (#10513)
Browse files Browse the repository at this point in the history
If there is a rollout, or any kind of graceful shutdown of compactors, they terminate ongoing block cleanup and bucket index update jobs. This can lead to the bucket index not being updated for an extended period if jobs are terminated back-to-back.

This PR addresses the above by shuffling the order of users submitted to BlocksCleaner by UsersScanner. When users are always processed in lexicographic order, successive restarts can cause read path failures for tenants with stale indexes. By randomizing this order, we reduce the probability that these indexes become stale.
  • Loading branch information
dmwilson-grafana authored Jan 27, 2025
1 parent 5090dfd commit 6ac5d6d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* `cortex_ingester_tsdb_block_postings_for_matchers_cache_misses_total`
* `cortex_ingester_tsdb_block_postings_for_matchers_cache_requests_total`
* `cortex_ingester_tsdb_block_postings_for_matchers_cache_skips_total`
* [ENHANCEMENT] Compactor: Shuffle users' order in `BlocksCleaner`. Prevents bucket indexes from going an extended period without cleanup during compactor restarts. #10513
* [BUGFIX] Distributor: Use a boolean to track changes while merging the ReplicaDesc components, rather than comparing the objects directly. #10185
* [BUGFIX] Querier: fix timeout responding to query-frontend when response size is very close to `-querier.frontend-client.grpc-max-send-msg-size`. #10154
* [BUGFIX] Query-frontend and querier: show warning/info annotations in some cases where they were missing (if a lazy querier was used). #10277
Expand Down
5 changes: 5 additions & 0 deletions pkg/compactor/blocks_cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package compactor
import (
"context"
"fmt"
"math/rand"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -232,6 +233,10 @@ func (c *BlocksCleaner) refreshOwnedUsers(ctx context.Context) ([]string, map[st
return nil, nil, errors.Wrap(err, "failed to discover users from bucket")
}

rand.Shuffle(len(users), func(i, j int) {
users[i], users[j] = users[j], users[i]
})

isActive := util.StringsMap(users)
isDeleted := util.StringsMap(deleted)
allUsers := append(users, deleted...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/bucket/client_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (m *ClientMock) MockGetAndLastModified(name, content string, lastModified t
} else {
m.On("Exists", mock.Anything, name).Return(false, err)
m.On("Get", mock.Anything, name).Return(nil, ErrObjectDoesNotExist)
m.On("Attributes", mock.Anything, name).Return(nil, ErrObjectDoesNotExist)
m.On("Attributes", mock.Anything, name).Return(objstore.ObjectAttributes{}, ErrObjectDoesNotExist)
}
}

Expand Down

0 comments on commit 6ac5d6d

Please sign in to comment.