-
Notifications
You must be signed in to change notification settings - Fork 537
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
feat(ha_tracker): Replicadesc implement mergeable interface #10020
base: main
Are you sure you want to change the base?
feat(ha_tracker): Replicadesc implement mergeable interface #10020
Conversation
1bd6fab
to
2789864
Compare
e4ac231
to
116b7aa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pretty solid 🚀 i left a few comments, but can't see anything major
pkg/distributor/ha_tracker_test.go
Outdated
rDesc2: nil, | ||
expectedOurs: func() *ReplicaDesc { | ||
ours2, _ := merge(secondReplica(), thirdReplica()) | ||
ours2, _ = merge(ours2, firstReplica()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ours2, _ = merge(ours2, firstReplica()) | |
ours2, _ = merge(firstReplica(), ours2) |
nit, but that's what the description says
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, I updated it. Thank you 🙌
pkg/distributor/ha_tracker_test.go
Outdated
name: "idempotency: no change after applying same Replica again", | ||
rDesc1: expectedFirstAndFirstHigherReceivedAtMerge(), | ||
rDesc2: firstReplica(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd make this super explicit and call merge twice. Here the first merge is implicit: you've done it by hand in the test setup with expectedFirstAndFirstHigherReceivedAtMerge
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes , you are right. I fixed it here 2ceeadc
return out, nil | ||
} | ||
|
||
// MergeContent noOp currently | ||
// MergeContent describes content of this Mergeable. | ||
// Given that ReplicaDesc can have only one instance at a time, it returns the ReplicaDesc it contains. | ||
func (r *ReplicaDesc) MergeContent() []string { | ||
result := []string(nil) | ||
if len(r.Replica) != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT about using r.IsEmpty()
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot find this function as part of the ReplicaDesc, do you want me to implement it ?
What this PR does
In this PR, we implement the
Mergeable
interface forReplicaDesc
and add tests to verify the implementation. Below, I will describe the high-level algorithm chosen for the Merge function.It’s important to note that the
Mergeable
interface was created with the assumption that the objects implementing it would maintain a "view" (list) of items over which they would iterate. At least based on my understanding after implementing,. In this case, there is only one instance ofReplicaDesc
for each key.Merge
We can have 2 possible cases:
In the first case, the incoming Mergeable has the same Replica name as the one already in the KVStore. In this scenario, we keep the one with the most recent timestamp. If the timestamps are the same, we only update if the incoming one has been marked as deleted, in which case we need to make the KVStore aware of the deletion.
In the second case, the incoming Mergeable has a different Replica name. Here, we use the electedAt timestamp to decide which of the two ReplicaDesc objects should be retained.
Which issue(s) this PR fixes or relates to
Fixes #https://github.com/grafana/mimir-squad/issues/2653
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]
.about-versioning.md
updated with experimental features.