Skip to content

Commit 5e7f104

Browse files
committed
Use most recent time to remove from ring
Signed-off-by: Daniel Blando <[email protected]>
1 parent d3f46c5 commit 5e7f104

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
* [BUGFIX] Querier: fixed panic when querying exemplars and using `-distributor.shard-by-all-labels=false`. #4473
6161
* [BUGFIX] Querier: honor querier minT,maxT if `nil` SelectHints are passed to Select(). #4413
6262
* [BUGFIX] Compactor: fixed panic while collecting Prometheus metrics. #4483
63+
* [BUGFIX] Memberlist: Remove entry from the ring even if the timestamp is in the future #4501
6364

6465

6566
## 1.10.0 / 2021-08-03

pkg/ring/merge_test.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,27 @@ func TestMergeRemoveMissing(t *testing.T) {
356356
Ingesters: map[string]InstanceDesc{
357357
"Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}},
358358
"Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}},
359-
"Ing 3": {Addr: "addr3", Timestamp: now + 3, State: LEFT}, // When deleting, time depends on value passed to merge function.
359+
"Ing 3": {Addr: "addr3", Timestamp: now + 3, State: LEFT},
360+
},
361+
}
362+
}
363+
364+
thirdRing := func() *Desc {
365+
return &Desc{
366+
Ingesters: map[string]InstanceDesc{
367+
"Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}},
368+
"Ing 2": {Addr: "addr2", Timestamp: now, State: JOINING, Tokens: []uint32{5, 10, 20, 100, 200}},
369+
"Ing 3": {Addr: "addr3", Timestamp: now + 50, State: LEAVING, Tokens: []uint32{5, 10, 20, 100, 200}},
370+
},
371+
}
372+
}
373+
374+
expectedThirdSecondMerge := func() *Desc {
375+
return &Desc{
376+
Ingesters: map[string]InstanceDesc{
377+
"Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}},
378+
"Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}},
379+
"Ing 3": {Addr: "addr3", Timestamp: now + 50, State: LEFT},
360380
},
361381
}
362382
}
@@ -367,7 +387,18 @@ func TestMergeRemoveMissing(t *testing.T) {
367387
assert.Equal(t, &Desc{
368388
Ingesters: map[string]InstanceDesc{
369389
"Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}},
370-
"Ing 3": {Addr: "addr3", Timestamp: now + 3, State: LEFT}, // When deleting, time depends on value passed to merge function.
390+
"Ing 3": {Addr: "addr3", Timestamp: now + 3, State: LEFT}, // When deleting, time is recent between now and current timestamp
391+
},
392+
}, ch) // entire second ring is new
393+
}
394+
395+
{
396+
our, ch := mergeLocalCAS(thirdRing(), secondRing(), now+10)
397+
assert.Equal(t, expectedThirdSecondMerge(), our)
398+
assert.Equal(t, &Desc{
399+
Ingesters: map[string]InstanceDesc{
400+
"Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}},
401+
"Ing 3": {Addr: "addr3", Timestamp: now + 50, State: LEFT}, // When deleting, time is recent between now and current timestamp
371402
},
372403
}, ch) // entire second ring is new
373404
}

pkg/ring/model.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,12 @@ func (d *Desc) mergeWithTime(mergeable memberlist.Mergeable, localCAS bool, now
210210
// We are deleting entry "now", and should not keep old timestamp, because there may already be pending
211211
// message in the gossip network with newer timestamp (but still older than "now").
212212
// Such message would "resurrect" this deleted entry.
213-
ting.Timestamp = now.Unix()
213+
// If timestamp on the ring is in "the future" we need to use the timestamp of the ring
214+
// otherwise the gossip message will be ignored by the peers.
215+
// see https://github.com/cortexproject/cortex/blob/d3f46c53616dcdf5c670f3e3a4d371e44b10683e/pkg/ring/model.go#L192-L200
216+
if ting.Timestamp < now.Unix() {
217+
ting.Timestamp = now.Unix()
218+
}
214219
thisIngesterMap[name] = ting
215220

216221
updated = append(updated, name)

0 commit comments

Comments
 (0)