Skip to content
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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

NickAnge
Copy link
Contributor

@NickAnge NickAnge commented Nov 25, 2024

What this PR does

In this PR, we implement the Mergeable interface for ReplicaDesc 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 of ReplicaDesc 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

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • about-versioning.md updated with experimental features.

@NickAnge NickAnge force-pushed the nickange/ha_tracker/support-replicadesc-mergeable-interface branch from 1bd6fab to 2789864 Compare November 25, 2024 14:19
@NickAnge NickAnge changed the title Nickange/ha tracker/support replicadesc mergeable interface feat(ha_tracker): Replicadesc implement mergeable interface Nov 25, 2024
@NickAnge NickAnge force-pushed the nickange/ha_tracker/support-replicadesc-mergeable-interface branch from e4ac231 to 116b7aa Compare November 27, 2024 14:46
Copy link
Contributor

@dimitarvdimitrov dimitarvdimitrov left a 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.go Outdated Show resolved Hide resolved
pkg/distributor/ha_tracker.go Outdated Show resolved Hide resolved
pkg/distributor/ha_tracker.go Outdated Show resolved Hide resolved
pkg/distributor/ha_tracker_test.go Outdated Show resolved Hide resolved
pkg/distributor/ha_tracker_test.go Outdated Show resolved Hide resolved
pkg/distributor/ha_tracker_test.go Outdated Show resolved Hide resolved
pkg/distributor/ha_tracker_test.go Outdated Show resolved Hide resolved
rDesc2: nil,
expectedOurs: func() *ReplicaDesc {
ours2, _ := merge(secondReplica(), thirdReplica())
ours2, _ = merge(ours2, firstReplica())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ours2, _ = merge(ours2, firstReplica())
ours2, _ = merge(firstReplica(), ours2)

nit, but that's what the description says

Copy link
Contributor Author

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 🙌

Comment on lines 191 to 193
name: "idempotency: no change after applying same Replica again",
rDesc1: expectedFirstAndFirstHigherReceivedAtMerge(),
rDesc2: firstReplica(),
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants