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

Ring: Add HasReplicationSetChangedWithoutStateOrAddr #464

Merged
merged 5 commits into from
Jan 11, 2024

Conversation

pr00se
Copy link
Contributor

@pr00se pr00se commented Jan 10, 2024

What this PR does:

The existing ring.HasReplicationSetChangedWithoutState function will detect a replication state change if a member was rebooted and rejoins the ring with a different IP address. In Mimir we want to ignore these changes as, in some cases, we only care about the distribution of the tokens in the ring changing.

This PR:

  1. changes the sorting of the replication sets in ring.hasReplicationSetChangedExcluding from ByAddr to ByID, since we want to ignore the Addr field in some situations.
  2. adds ring.HasReplicationSetChangedWithoutStateOrAddr to detect replication set changes ignoring the State and Addr fields.

Which issue(s) this PR fixes:

Fixes N/A

Checklist

  • Tests updated
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@pr00se pr00se changed the title Add ring.HasReplicationSetChangedWithoutStateOrAddr Ring: Add HasReplicationSetChangedWithoutStateOrAddr Jan 10, 2024
@@ -21,6 +21,13 @@ func (ts ByAddr) Len() int { return len(ts) }
func (ts ByAddr) Swap(i, j int) { ts[i], ts[j] = ts[j], ts[i] }
func (ts ByAddr) Less(i, j int) bool { return ts[i].Addr < ts[j].Addr }

// ByID is a sortable list of InstanceDesc.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've left ByAddr because it is used outside of the library

Copy link
Contributor

@56quarters 56quarters left a comment

Choose a reason for hiding this comment

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

LGTM, one non-blocking comment

@@ -468,6 +468,17 @@ func HasReplicationSetChangedWithoutState(before, after ReplicationSet) bool {
})
}

// Has HasReplicationSetChangedWithoutStateOrAddr returns false if two replications sets
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't have to do it as part of this PR but we seem to be accumulating quite a few different methods that all do roughly the same thing. Maybe we could apply the option pattern here.

e.g.

func HasReplicationSetChanged(before, after ReplicationSet, opt... RingOption) bool { /* ... */ }

Called like

if ring.HasReplicationSetChanged(a, b, ring.ExcludeAddress(), ring.ExcludeState()) {
    /* ... */
}

Copy link
Contributor Author

@pr00se pr00se Jan 11, 2024

Choose a reason for hiding this comment

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

I had the same thought, but it would mean breaking changes not only for Mimir. Since dskit doesn't have a formal versioning process we'd need to coordinate changing over (or have two implementations for some time). We also don't have an easy way to signal that breaking change to any external users of dskit (are there any?).

We could add something like

func HasReplicationSetChangedFn(opt... ExcludeOption) func (before, after ReplicationSet) bool { /* ... */ }

and replace the usage of HasReplicationSetChangedWithoutXXXXX, but I don't foresee us needing another flavor of this kind of function in the future (there aren't many other fields left to ignore). If we do end up adding a third implementation, though, we should revisit this.

@pr00se pr00se merged commit 751c314 into main Jan 11, 2024
3 checks passed
@pr00se pr00se deleted the ring-no-addr-changes branch January 11, 2024 14:56
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.

None yet

2 participants