-
Notifications
You must be signed in to change notification settings - Fork 75
feat(ring): support for owning multiple partitions #725
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(ring): support for owning multiple partitions #725
Conversation
578c87f to
f922d4b
Compare
Co-authored-by: Marco Pracucci <[email protected]> Signed-off-by: Oleg Zaytsev <[email protected]>
f922d4b to
e312311
Compare
pracucci
left a comment
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.
Good job! I only left nits.
| func (r *MultiPartitionInstanceRing) PartitionRing() *PartitionRing { | ||
| return r.partitionsRingReader.PartitionRing() | ||
| } | ||
|
|
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.
[nit] I suggest to add InstanceRing() like PartitionInstanceRing. It's legit to get the instances ring from MultiPartitionInstanceRing.
| func (r * MultiPartitionInstanceRing) InstanceRing() InstanceRingReader { | |
| return r.instancesRing | |
| } | |
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 explicitly left it unimplemented because we don't use it in the implementation, and if I add it, I'd feel to be forced to use it, but I think that could make unit-testing harder.
I'd rather leave it like this for now.
|
|
||
| // this method expects instanceIDs to be in the same order as instances. | ||
| // instanceIDs should hold the parsed multi-partition owner IDs. | ||
| func highestPreferrablyNonReadOnlyFromEachZone(instances []InstanceDesc, instanceIDs []string, instanceZones []string) []InstanceDesc { |
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.
[nit] Typo
| func highestPreferrablyNonReadOnlyFromEachZone(instances []InstanceDesc, instanceIDs []string, instanceZones []string) []InstanceDesc { | |
| func highestPreferablyNonReadOnlyFromEachZone(instances []InstanceDesc, instanceIDs []string, instanceZones []string) []InstanceDesc { |
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.
Done in d2b489d
| }, nil | ||
| } | ||
|
|
||
| // this method expects instanceIDs to be in the same order as instances. |
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.
[nit] Please also comment that instances is updated in-place and then returned.
ring/partition_ring.go
Outdated
| } | ||
|
|
||
| for i, ownerID := range ids { | ||
| if p := strings.IndexByte(ownerID, '/'); p != -1 { |
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.
This search for the 1st / occurrence, but so far I don't a reason why / couldn't also be part of the instance ID. I think using strings.LastIndexByte() would more correct.
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.
Right, that's also more efficient. Fixed and added a test with an instance ID with a slash. 1c09d6b
Co-authored-by: Marco Pracucci <[email protected]>
Co-authored-by: Marco Pracucci <[email protected]>
Signed-off-by: Oleg Zaytsev <[email protected]>
Signed-off-by: Oleg Zaytsev <[email protected]>
Signed-off-by: Oleg Zaytsev <[email protected]>
… arch compatibility (#730) Loki is failing to build for the linux/arm platform with ([see][1]): ``` 59.88 # github.com/grafana/dskit/ring 59.88 vendor/github.com/grafana/dskit/ring/multi_partition_instance_ring.go:151:10: cannot use math.MaxInt64 (untyped int constant 9223372036854775807) as int value in return statement (overflows) 59.88 vendor/github.com/grafana/dskit/ring/multi_partition_instance_ring.go:155:10: cannot use math.MaxInt64 (untyped int constant 9223372036854775807) as int value in return statement (overflows) ``` linux/arm is a 32bits platform so int is 32 bits, but `indexFromInstanceSuffix` returns `math.MaxInt64` instead of `math.MaxInt`. **What this PR does**: **Which issue(s) this PR fixes**: Fixes PR - #725 **Checklist** - [ ] Tests updated [1]: https://github.com/grafana/loki/actions/runs/16723281173/job/47333518579#step:9:486
What this PR does:
This adds a new
MultiPartitionInstanceRingas an alternative toPartitionInstanceRingin which the instances can own more than one partition. It uses the same instance PartitionRing desc, so we leverage that by setting a different instance ID as owner of each partition.The convention is enclosed in this implementation and consists of adding a suffix
/<partition>to the instance ID when it ownspartition. We initially added this as an option toPartitionInstanceRing, however most of the code actually differs, and the fact that you could instantiate aPartitionInstanceRingand use it in a multi-partition context introduced subtle bugs in the code. By adding a specific type to this we enforce that each implementation will consistently use one or another.We do add this as an option to
PartitionInstanceLifecycler, because there most of the code is shared.PartitionRingexposes a new methodMultiPartitionOwnerIDsthat will list the real (non-suffixed) instance IDs of partition owners ready to be used by any code.Finally, we also add a method to
PartitionRingEditorto remove an instance ID as an owner of a partition, required to perform the periodic cleanup of the stale instances in the ring by users of this library.Checklist