Skip to content

Commit

Permalink
Using Ingester Id as a tiebreaker for MinimizeSpreadTokenGenerator (c…
Browse files Browse the repository at this point in the history
…ortexproject#6044)

Signed-off-by: alanprot <[email protected]>
  • Loading branch information
alanprot authored Jun 28, 2024
1 parent 79ef088 commit 9014823
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/ring/token_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ func (g *MinimizeSpreadTokenGenerator) GenerateTokens(ring *Desc, id, zone strin
tokensPerInstanceWithDistance[i] = &totalTokenPerInstance{id: i, zone: instance.Zone}

if len(instance.Tokens) == 0 {
// If there is more than one instance with no tokens, lets only use
// MinimizeSpread token algorithm on the last one
if instance.RegisteredTimestamp < ring.Ingesters[id].RegisteredTimestamp {
// If there is more than one ingester with no tokens, use MinimizeSpread only for the first registered ingester.
// In case of a tie, use the ingester ID as a tiebreaker.
if instance.RegisteredTimestamp < ring.Ingesters[id].RegisteredTimestamp ||
(instance.RegisteredTimestamp == ring.Ingesters[id].RegisteredTimestamp && i < id) {
if force {
return g.innerGenerator.GenerateTokens(ring, id, zone, numTokens, true)
} else {
Expand Down
10 changes: 10 additions & 0 deletions pkg/ring/token_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ func TestMinimizeSpreadTokenGenerator(t *testing.T) {
require.Len(t, tokens, 0)
tokens = minimizeTokenGenerator.GenerateTokens(rindDesc, "pendingIngester-2", zones[0], 512, false)
require.Len(t, tokens, 512)

// Should generate tokens only for the ingesters with the smaller Id when multiples ingesters does not have tokens
// and have the same registered time
now := time.Now()
rindDesc.AddIngester("pendingIngester-1", "pendingIngester-1", zones[0], []uint32{}, PENDING, now)
rindDesc.AddIngester("pendingIngester-2", "pendingIngester-2", zones[0], []uint32{}, PENDING, now)
tokens = minimizeTokenGenerator.GenerateTokens(rindDesc, "pendingIngester-1", zones[0], 512, false)
require.Len(t, tokens, 512)
tokens = minimizeTokenGenerator.GenerateTokens(rindDesc, "pendingIngester-2", zones[0], 512, false)
require.Len(t, tokens, 0)
}

func generateTokensForIngesters(t *testing.T, rindDesc *Desc, prefix string, zones []string, minimizeTokenGenerator *MinimizeSpreadTokenGenerator, dups map[uint32]bool) {
Expand Down

0 comments on commit 9014823

Please sign in to comment.