Skip to content

Fix ingesters with less tokens stuck in LEAVING #5061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* [BUGFIX] Updated `golang.org/x/net` dependency to fix CVE-2022-27664. #5008
* [BUGFIX] Fix panic when otel and xray tracing is enabled. #5044
* [BUGFIX] Fixed no compact block got grouped in shuffle sharding grouper. #5055
* [BUGFIX] Fixed ingesters with less tokens stuck in LEAVING. #5061
* [BUGFIX] Tracing: Fix missing object storage span instrumentation. #5074

## 1.14.0 2022-12-02
Expand Down
2 changes: 1 addition & 1 deletion pkg/ring/lifecycler.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ func (i *Lifecycler) initRing(ctx context.Context) error {
// OR unregister_on_shutdown=false
// if autoJoinOnStartup, move it into ACTIVE to ensure the ingester joins the ring.
// else set to PENDING
if instanceDesc.State == LEAVING && len(instanceDesc.Tokens) == i.cfg.NumTokens {
if instanceDesc.State == LEAVING && len(instanceDesc.Tokens) != 0 {
if i.autoJoinOnStartup {
instanceDesc.State = ACTIVE
} else {
Expand Down
53 changes: 53 additions & 0 deletions pkg/ring/lifecycler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,59 @@ func TestJoinInLeavingState(t *testing.T) {
})
}

func TestJoinInLeavingStateAndLessTokens(t *testing.T) {
ringStore, closer := consul.NewInMemoryClient(GetCodec(), log.NewNopLogger(), nil)
t.Cleanup(func() { assert.NoError(t, closer.Close()) })

var ringConfig Config
flagext.DefaultValues(&ringConfig)
ringConfig.KVStore.Mock = ringStore

r, err := New(ringConfig, "ingester", ringKey, log.NewNopLogger(), nil)
require.NoError(t, err)
require.NoError(t, services.StartAndAwaitRunning(context.Background(), r))
defer services.StopAndAwaitTerminated(context.Background(), r) //nolint:errcheck

cfg := testLifecyclerConfig(ringConfig, "ing1")
cfg.NumTokens = 3
cfg.MinReadyDuration = 1 * time.Nanosecond

// Set state as LEAVING and 1 less token because of conflict resolution
err = r.KVClient.CAS(context.Background(), ringKey, func(in interface{}) (interface{}, bool, error) {
r := &Desc{
Ingesters: map[string]InstanceDesc{
"ing1": {
State: LEAVING,
Tokens: []uint32{1, 4},
},
"ing2": {
Tokens: []uint32{2, 3, 5},
},
},
}

return r, true, nil
})
require.NoError(t, err)

l1, err := NewLifecycler(cfg, &nopFlushTransferer{}, "ingester", ringKey, true, true, log.NewNopLogger(), nil)
require.NoError(t, err)
require.NoError(t, services.StartAndAwaitRunning(context.Background(), l1))

// Check that the lifecycler was able to join after coming up in LEAVING
test.Poll(t, 1000*time.Millisecond, true, func() interface{} {
d, err := r.KVClient.Get(context.Background(), ringKey)
require.NoError(t, err)

desc, ok := d.(*Desc)
return ok &&
len(desc.Ingesters) == 2 &&
desc.Ingesters["ing1"].State == ACTIVE &&
len(desc.Ingesters["ing1"].Tokens) == 2 &&
len(desc.Ingesters["ing2"].Tokens) == cfg.NumTokens
})
}

// JoinInJoiningState ensures that if the lifecycler starts up and the ring already has it in a JOINING state that it still is able to auto join
func TestJoinInJoiningState(t *testing.T) {
ringStore, closer := consul.NewInMemoryClient(GetCodec(), log.NewNopLogger(), nil)
Expand Down