Skip to content

Commit 6092356

Browse files
committed
Address comments
Signed-off-by: Alan Protasio <[email protected]>
1 parent 50402e0 commit 6092356

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
* [BUGFIX] HA Tracker: when cleaning up obsolete elected replicas from KV store, tracker didn't update number of cluster per user correctly. #4336
3131
* [BUGFIX] Ruler: fixed counting of PromQL evaluation errors as user-errors when updating `cortex_ruler_queries_failed_total`. #4335
3232
* [BUGFIX] Ingester: When using block storage, prevent any reads or writes while the ingester is stopping. This will prevent accessing TSDB blocks once they have been already closed. #4304
33-
* [BUGFIX] Ingester: Ingester stuck on start up (LEAVING ring state) when `-ingester.heartbeat-period=0` and `unregister_on_shutdown=false`. #4366
3433
* [BUGFIX] Ingester: fixed ingester stuck on start up (LEAVING ring state) when `-ingester.heartbeat-period=0` and `-ingester.unregister-on-shutdown=false`. #4366
3534

3635
## 1.10.0-rc.0 / 2021-06-28

pkg/ring/lifecycler_test.go

+17-16
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
330330
require.NoError(t, err)
331331
require.NoError(t, services.StartAndAwaitRunning(context.Background(), r))
332332

333+
// We are going to create 2 fake ingester with disabled heart beat and `unregister_on_shutdown=false` then
334+
// test if the ingester 2 became active after:
335+
// * Clean Shutdown (LEAVING after shutdown)
336+
// * Crashes while in the PENDING or JOINING state
333337
lifecyclerConfig := testLifecyclerConfig(ringConfig, "ing1")
334338
lifecyclerConfig.UnregisterOnShutdown = false
335339
lifecyclerConfig.HeartbeatPeriod = 0
@@ -345,7 +349,8 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
345349
require.NoError(t, err)
346350
require.NoError(t, services.StartAndAwaitRunning(context.Background(), l2))
347351

348-
pool := func(condition func(*Desc) bool) map[string]InstanceDesc {
352+
// poll function waits for a condition and returning actual state of the ingesters after the condition succeed.
353+
poll := func(condition func(*Desc) bool) map[string]InstanceDesc {
349354
var ingesters map[string]InstanceDesc
350355
test.Poll(t, 5*time.Second, true, func() interface{} {
351356
d, err := r.KVClient.Get(context.Background(), IngesterRingKey)
@@ -362,22 +367,18 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
362367
return ingesters
363368
}
364369

365-
startIngesterAndWaitActive := func(lcConfig LifecyclerConfig) *Lifecycler {
370+
// Starts Ingester2 and wait it to became active
371+
startIngester2AndWaitActive := func(lcConfig LifecyclerConfig) *Lifecycler {
366372
ingester, err := NewLifecycler(lcConfig, &noopFlushTransferer{}, "ingester", IngesterRingKey, true, nil)
367373
require.NoError(t, err)
368374
require.NoError(t, services.StartAndAwaitRunning(context.Background(), ingester))
369-
370-
ingesters := pool(func(desc *Desc) bool {
371-
return len(desc.Ingesters) == 2 && desc.Ingesters["ing1"].State == ACTIVE && desc.Ingesters["ing2"].State == ACTIVE
375+
poll(func(desc *Desc) bool {
376+
return len(desc.Ingesters) == 2 && desc.Ingesters["ing2"].State == ACTIVE
372377
})
373-
374-
assert.Equal(t, ACTIVE, ingesters["ing1"].State)
375-
assert.Equal(t, ACTIVE, ingesters["ing2"].State)
376-
377378
return ingester
378379
}
379380

380-
ingesters := pool(func(desc *Desc) bool {
381+
ingesters := poll(func(desc *Desc) bool {
381382
return len(desc.Ingesters) == 2 && desc.Ingesters["ing1"].State == ACTIVE && desc.Ingesters["ing2"].State == ACTIVE
382383
})
383384

@@ -388,16 +389,16 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
388389
// Stop One ingester gracefully should leave it on LEAVING STATE on the ring
389390
require.NoError(t, services.StopAndAwaitTerminated(context.Background(), l2))
390391

391-
ingesters = pool(func(desc *Desc) bool {
392+
ingesters = poll(func(desc *Desc) bool {
392393
return len(desc.Ingesters) == 2 && desc.Ingesters["ing2"].State == LEAVING
393394
})
394395
assert.Equal(t, LEAVING, ingesters["ing2"].State)
395396

396397
// Start Ingester2 again - Should flip back to ACTIVE in the ring
397-
l2 = startIngesterAndWaitActive(lifecyclerConfig)
398+
l2 = startIngester2AndWaitActive(lifecyclerConfig)
398399
require.NoError(t, services.StopAndAwaitTerminated(context.Background(), l2))
399400

400-
//Simulate ingester2 crash on startup and left the ring with JOINING state
401+
// Simulate ingester2 crash on startup and left the ring with JOINING state
401402
err = r.KVClient.CAS(context.Background(), IngesterRingKey, func(in interface{}) (out interface{}, retry bool, err error) {
402403
desc, ok := in.(*Desc)
403404
require.Equal(t, true, ok)
@@ -408,10 +409,10 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
408409
})
409410
require.NoError(t, err)
410411

411-
l2 = startIngesterAndWaitActive(lifecyclerConfig)
412+
l2 = startIngester2AndWaitActive(lifecyclerConfig)
412413
require.NoError(t, services.StopAndAwaitTerminated(context.Background(), l2))
413414

414-
//Simulate ingester2 crash on startup and left the ring with PENDING state
415+
// Simulate ingester2 crash on startup and left the ring with PENDING state
415416
err = r.KVClient.CAS(context.Background(), IngesterRingKey, func(in interface{}) (out interface{}, retry bool, err error) {
416417
desc, ok := in.(*Desc)
417418
require.Equal(t, true, ok)
@@ -422,7 +423,7 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
422423
})
423424
require.NoError(t, err)
424425

425-
l2 = startIngesterAndWaitActive(lifecyclerConfig)
426+
l2 = startIngester2AndWaitActive(lifecyclerConfig)
426427
require.NoError(t, services.StopAndAwaitTerminated(context.Background(), l2))
427428
}
428429

0 commit comments

Comments
 (0)