-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
WIP: allocator: support per-replica constraints & improve locality handling #22412
Conversation
I'll take a look. Comments from Reviewable |
Review status: 0 of 5 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. pkg/config/zone.proto, line 66 at r1 (raw file):
This isn't taking the pkg/config/zone.proto, line 84 at r1 (raw file):
Does this comment belong here? There is no Comments from Reviewable |
Review status: 0 of 5 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. pkg/config/zone.proto, line 66 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
I tried this approach because I thought it would be simpler all-around, but ended up finding that something like the pkg/config/zone.proto, line 84 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
Does not belong here. I'll move it in my next round of cleanups. Comments from Reviewable |
I like the analyzedConstraints struct and that part of the scorer seems quite clear. I'm getting a little lost in the rebalanceCandidates part. Even with the numbered sections. A lot is going on there and trying to see how the different scenarios play out is a little tough. Reviewed 5 of 5 files at r1. pkg/config/zone.proto, line 44 at r1 (raw file):
Can we deprecate positive yet? pkg/config/zone.proto, line 66 at r1 (raw file):
So how will this work if this is > the number of replicas? Only the first [:n] match? pkg/storage/allocator_scorer.go, line 909 at r1 (raw file):
Instead of using the valid variable, perhaps just use a loop label and continue to the next outer loop? Might be more readable. pkg/storage/allocator_scorer.go, line 945 at r1 (raw file):
Instead of using the valid variable, perhaps just use a loop label and continue to the next outer loop? Might be more readable. Comments from Reviewable |
Review status: all files reviewed at latest revision, 6 unresolved discussions, some commit checks failed. pkg/config/zone.proto, line 66 at r1 (raw file): Previously, a-robinson (Alex Robinson) wrote…
Although, to be clear, it has to be Comments from Reviewable |
Review status: all files reviewed at latest revision, 6 unresolved discussions, some commit checks failed. pkg/config/zone.proto, line 66 at r1 (raw file): Previously, a-robinson (Alex Robinson) wrote…
Got it. Will you also have to change Comments from Reviewable |
5547bf0
to
aaf07e8
Compare
Thanks for the feedback, I'll clean that long block of code up and knock out some TODOs today. No need to look at the code again until I re-ping the PR. Review status: all files reviewed at latest revision, 6 unresolved discussions, some commit checks failed. pkg/config/zone.proto, line 44 at r1 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
I'd be fine with doing so since it was never truly supported in the first place. No need to add more to this PR, though. I'll do that separately. pkg/config/zone.proto, line 66 at r1 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
We should validate zone configs to not allow that. As written, the new code will just satisfy as many of them as it can, not favoring any in particular. pkg/config/zone.proto, line 66 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
Yup, that's the plan. pkg/storage/allocator_scorer.go, line 909 at r1 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
The amount of nesting here is certainly ugly, but I find resorting to loop labels to be less readable. Maybe it's just me? Do we prefer using labels elsewhere? pkg/storage/allocator_scorer.go, line 945 at r1 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
Ditto Comments from Reviewable |
There's no reason to conflate this logic into rebalanceCandidates -- just separate it out. This helps simplify cockroachdb#22412 Release note: None
e1a9cc6
to
13d6641
Compare
Alright, mostly done tweaking. Only a couple very small tweaks left. Review status: 1 of 6 files reviewed at latest revision, 6 unresolved discussions. pkg/config/zone.proto, line 66 at r1 (raw file): Previously, a-robinson (Alex Robinson) wrote…
Done. pkg/config/zone.proto, line 84 at r1 (raw file): Previously, a-robinson (Alex Robinson) wrote…
Done. Comments from Reviewable |
1f207c5
to
609aeea
Compare
As of the start of the week, there's really just one thing left to do here -- integrate store/node attributes in alongside localities -- and I probably won't be getting to it tonight or tomorrow. Mind reviewing everything other than that in the next day or two? I also need to would like to add even more unit tests, but that's easier to justify squeezing in on Friday. Review status: 0 of 9 files reviewed at latest revision, 6 unresolved discussions, some commit checks failed. Comments from Reviewable |
Ok, did a pass through everything. But I'm going to have to spend some serious time thinking through some of the situations. I'll try to do that tonight. Reviewed 4 of 4 files at r2, 1 of 1 files at r3, 2 of 2 files at r4, 7 of 8 files at r5, 8 of 8 files at r6, 4 of 4 files at r7, 4 of 4 files at r8. pkg/config/zone.proto, line 66 at r5 (raw file):
Is this reusing number 1? Shouldn't it be 7? pkg/storage/allocator_scorer.go, line 909 at r1 (raw file): Previously, a-robinson (Alex Robinson) wrote…
I've used a mix of both. Depending on readability. Up to you. I find not having to track an extra variable useful. pkg/storage/allocator_scorer.go, line 188 at r4 (raw file):
positive for both? pkg/storage/allocator_scorer.go, line 1079 at r5 (raw file):
This positive is going away right? Which changes this function entirely. And it was fixed in the next commit. Nevermind. pkg/storage/allocator_scorer.go, line 1049 at r8 (raw file):
Maybe move this to be the description for the function itself. pkg/storage/allocator_scorer_test.go, line 438 at r8 (raw file):
The naming of this is just terrible now. constraints -> []Constraints -> Constraints -> []Constraint then Type Constraint_X.... Ugh. Comments from Reviewable |
Ok, overall approach seems sound to me. Code looks good. But it's going to need a good amount of testing. And I'm worried about how easily we will be able to back it out if things start going wrong. What's your approach to this going to be? Also, this is a huge PR, probably a good idea to get someone else's eyes on it just in case. Comments from Reviewable |
d659c51
to
a7f6db2
Compare
Thanks for the reviews! Now that I have some free time again, my plan is to finish handling the node/store attributes than write some higher-level unit tests (that test at the AllocateTarget/RemoveTarget/RebalanceTarget level). I don't expect many issues to come up, though -- in my opinion the most likely places to hit problems were in the constraint checking logic themselves and in the new grouping of rebalance targets by rebalance diversity score (i.e. in the fix to #20751), both of which I've already added tests / test cases for. Review status: 0 of 9 files reviewed at latest revision, 8 unresolved discussions. pkg/config/zone.proto, line 66 at r5 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
Honestly I'm not quite sure why this is already on field 6. I'll switch the new one to 7. pkg/storage/allocator_scorer.go, line 909 at r1 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
It's not relevant anymore anyways :) pkg/storage/allocator_scorer.go, line 188 at r4 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
Fixed, thanks. pkg/storage/allocator_scorer.go, line 1079 at r5 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
Yeah, sorry! pkg/storage/allocator_scorer.go, line 1049 at r8 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
Done. pkg/storage/allocator_scorer_test.go, line 438 at r8 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
Yeah, it's certainly not good. I'm not sure what to change at this point, though. Comments from Reviewable |
a7f6db2
to
9fe4372
Compare
Alright, I've finished off the final TODO about handling node/store attributes. I'll add some additional tests tonight before my flight, but I'm already about half asleep, so no promises about how many. Review status: 0 of 9 files reviewed at latest revision, 8 unresolved discussions, some commit checks pending. Comments from Reviewable |
9fe4372
to
fb51a37
Compare
Sure, I'll give this a thorough review later today (or tonight). |
fb51a37
to
357c5f5
Compare
Apologies for the delay. There were a lot more changes here than I was expecting. Most of my comments are minor. The major question which I wasn't able to answer: if you don't specify a non-zero As noted below, some of the allocator functions have become beasts. Similarly, some of the testing, while rigorous, is hard to verify for correctness. I think utilizing Lastly, the additional logic has me worried about the performance of this code. We've generally not paid much attention to allocation performance, but as clusters grow it will become an increasing concern. Review status: 0 of 10 files reviewed at latest revision, 19 unresolved discussions, some commit checks failed. pkg/config/zone.proto, line 89 at r17 (raw file):
Why do we require the sum of the pkg/roachpb/metadata.go, line 63 at r17 (raw file):
Perhaps mention in this sentence at the attribute lists are treated as sets and duplicates are ignored. That is, pkg/storage/allocator_scorer.go, line 517 at r17 (raw file):
This method has certainly bloated over time. We need to take a look at breaking it into more digestible/testable pieces, though not for this PR. pkg/storage/allocator_scorer.go, line 519 at r17 (raw file):
The term pkg/storage/allocator_scorer.go, line 569 at r17 (raw file):
Nit: unusual indentation on this line. pkg/storage/allocator_scorer.go, line 654 at r17 (raw file):
pkg/storage/allocator_scorer.go, line 678 at r17 (raw file):
Nit: excessive indentation on these lines. pkg/storage/allocator_scorer.go, line 968 at r17 (raw file):
Not necessary for this PR, but we should really be caching this info. The set of constraints and stores in a cluster change slowly, there isn't any need to be calculating this on every allocation decision. pkg/storage/allocator_scorer.go, line 1006 at r17 (raw file):
This function looks unused. pkg/storage/allocator_scorer.go, line 1044 at r17 (raw file):
This function deserves a doc comment as well. I'm also a bit confused about the naming. What is being "removed"? pkg/storage/allocator_scorer_test.go, line 608 at r17 (raw file):
These tests cases are difficult to parse and I imagine they are difficult to write. It would be better to use the Comments from Reviewable |
This is the core work required for cockroachdb#19985 (but without exposing it to users yet), and fixes cockroachdb#20751 along the way. Release note: None
Release note: None
Release note: None
Release note: None
357c5f5
to
62c64ff
Compare
Not in all cases. See below.
Fixing #20751 is a change in behavior in cases where some localities are more full than others for reasons outside the system's control -- e.g. if one has more nodes than the others or if some constraints have required more ranges to be in one. In such cases, this does a better job of balancing ranges amongst the nodes that are more or less full because we compare them amongst each other now rather than comparing them to the Fixing #20751 is the only change of existing behavior, though.
Well that's nifty looking. To be honest, I don't understand at first glance what about it will make the tests currently there much clearer, but can see that it'd help with expanding them to cover more sets of stores and localities.
Yeah, that's one of my concerns as well. I tried to stay conscious of allocations, but had to back out some of my premature optimizations that broke due to the need to handle store/node attributes. I still haven't seen this stuff show up in benchmarks, but I haven't looked for it on a cluster that was using localities and constraints in a meaningful way that was larger than 8 nodes. It didn't show up as meaningful in an 8-node repro of #20751 with about 1300 ranges, for example. Caching things between runs would certainly be a win, but it'll be enough of a step up in code complexity that I don't at all regret doing a more direct version first. We can make things more modular in the process, with everything pulled out of the storage package once refactorings are allowed again. Review status: 0 of 10 files reviewed at latest revision, 19 unresolved discussions. pkg/config/zone.proto, line 89 at r17 (raw file): Previously, petermattis (Peter Mattis) wrote…
I imposed that to simplify things for myself, but I think at this point it would work fine if we added some extra state to That also opens the door to allowing constraints that apply to the entire range alongside per-replica constraints, which feel kind of awkward to specify using the format in #22819, but maybe that's just me. Also, to be honest, I may be misinterpreting it but I don't believe the implementation as originally proposed in #19985 (comment) works for removing/rebalancing, just for adding replicas. pkg/roachpb/metadata.go, line 63 at r17 (raw file): Previously, petermattis (Peter Mattis) wrote…
Done. pkg/storage/allocator_scorer.go, line 517 at r17 (raw file): Previously, petermattis (Peter Mattis) wrote…
Ack. pkg/storage/allocator_scorer.go, line 519 at r17 (raw file): Previously, petermattis (Peter Mattis) wrote…
Done. pkg/storage/allocator_scorer.go, line 569 at r17 (raw file): Previously, petermattis (Peter Mattis) wrote…
Done. pkg/storage/allocator_scorer.go, line 654 at r17 (raw file): Previously, petermattis (Peter Mattis) wrote…
Yeah. I've changed it to just pkg/storage/allocator_scorer.go, line 678 at r17 (raw file): Previously, petermattis (Peter Mattis) wrote…
Done. pkg/storage/allocator_scorer.go, line 1006 at r17 (raw file): Previously, petermattis (Peter Mattis) wrote…
Indeed, thanks. pkg/storage/allocator_scorer.go, line 1044 at r17 (raw file): Previously, petermattis (Peter Mattis) wrote…
The function is determining whether Sorry about not adding comments to these methods, they aren't obvious. pkg/storage/allocator_scorer_test.go, line 608 at r17 (raw file): Previously, petermattis (Peter Mattis) wrote…
Writing them was easy while the state of which stores have which localities/attributes was in my head, but I understand that interpreting them will pretty much require loading that state back in. Luckily these tests are almost totally deterministic, so you should only need to page them in when seriously modifying the allocator logic. Comments from Reviewable |
Ack. Thanks for the explanation.
The current tests require keeping a lot of state in your head, understanding the localities and attributes and what not. Data driven tests would also need some initialization like that, but I think we could a) make that clearer and b) have different files covering different setups. I'm 90% confident it will expand the test coverage and make this code better and more maintainable.
Agreed on the step up in complexity and the decision to not pile that work into this PR. My concern about allocator performance is an observation that we'll probably have to address soon, but not today. Review status: 0 of 10 files reviewed at latest revision, 9 unresolved discussions, some commit checks failed. pkg/config/zone.proto, line 89 at r17 (raw file): Previously, a-robinson (Alex Robinson) wrote…
Ack. Seems reasonable for now and we can relax this restriction later. pkg/storage/allocator_scorer_test.go, line 608 at r17 (raw file): Previously, a-robinson (Alex Robinson) wrote…
The major benefit of Comments from Reviewable |
Release note (backwards-incompatible change): Positive constraints in replication zone configs no longer work. They have never been documented or officially supported, but will no longer be allowed at all.
Release note: None
This makes comparisons of existing replicas' `necessary` candidate field to potential rebalance targets' `necessary` field fair, as we do for diversity scores with diversityRebalanceFromScore. Release note: None
Release note: None
Release note: None
62c64ff
to
6dca22a
Compare
Release note: None
6dca22a
to
7194fa9
Compare
Merged as part of #22819 |
Also add testing of rebalancing in clusters with differently sized localities as a follow-up to cockroachdb#22412. Release note (bug fix): Fix the occasional selection of sub-optimal rebalance targets.
Also add testing of rebalancing in clusters with differently sized localities as a follow-up to cockroachdb#22412. Release note (bug fix): Fix the occasional selection of sub-optimal rebalance targets.
Also add testing of rebalancing in clusters with differently sized localities as a follow-up to cockroachdb#22412. Release note (bug fix): Fix the occasional selection of sub-optimal rebalance targets.
This is the core work required for #19985 (but without exposing it to
users yet), and fixes #20751 along the way.
Release note: None
It still needs some more love -- the code's a bit rough, there are a couple meaningful TODOs left, and I haven't written the tests yet -- but the most important stuff is here.
@BramGruneir, would you be willing to review this? Or should I find someone else?