You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Blueprint suggester doesn't distribute shards across nodes #344
Go to data explorer, create a table, and insert a bunch of documents (I magically inserted 512).
Go to the table view, set the number of replicas to 2. When the replication completes, set the number of shards to 2.
Expected behavior: RethinkDB should put the two primaries on different machines.
Observed behavior: RethinkDB puts the two primaries on the same machines.
I don't know if this is a client bug (if it doesn't send the "dangerous" flag to the server) or a server bug. We've seen this regression come up over and over again, so I really think we need a proper regression test before we can close this issue.
You actually explicitly said to me: "JD don't worry about distinguishing between masters and replicas, it's too complicated and doesn't actually make a difference." This behavior was fine for 1.2 because it made things simpler and clumped up masters was very far from being a bottle neck at that point. These are both still true so I'm not sure if it's really worth reconsidering.
I would never say that. The whole purpose of sharding is to split the table's shards across multiple machines, otherwise the feature has no point. I ran into this bug while doing a demo, and it immediately confused both me, and the people I was demoing the product to. This is also why we added the prefer_distribution flag, to tell the server we value spreading out the shards over availability.
There are at least three separate issues in the deprecated branch where the observed behavior is that the shard primaries are placed on the same machine and the expected behavior is stated to be that the primaries should be on different machines (all three submitted by me):
So actually I now remember the conversation very well (remembered it in my dream, no less -- it was torturing me all day yesterday and my subconscience delivered).
We were talking about availability and I said don't worry about trying to place masters in a way that co-locates them with existing replicas to maximize availability during sharding -- it's too hard (and we're gonna solve that eventually in a different way -- the one later proposed to address automatic failover -- anyway).
But we still have to place shards on separate machines whenever possible.
Just talked to @jdoliner -- there are a couple of points on blueprint generation:
It's a pretty complex constraint satisfaction problem
No matter what we do, we'll run into cases that confuse people
Oftentimes the question of what's optimal has very blurry (if any) answer
Oftentimes what "looks right" and what's optimal can be different things
Since we can't "solve" this problem for all cases, we should lay out heuristics in order of priority here, implement them in the blueprint compiler, and encode them in tests. Here are the constraints we need (from highest to lowest priority -- a higher priority cannot be compromised to satisfy the lower one) because that's what a reasonable observer would expect:
Primary datacenter and replica constraints need to be respected (if a table T has a primary datacenter, masters only can go there, and replica counts need to go to other datacenters as specified) -- we already do this.
For a given table T (regardless of other tables present in the system), no masters for that table can be on the same machine (as long as there is enough hardware), and no replicas for that table can be on the same machine -- we already do this for replicas and sometimes do this for masters. We need to always do this for both.
We shouldn't move existing shards, and we should prefer machines with lowest number of responsibilities for new shards.
This system is a) simple enough to do, b) won't raise eyebrows from early adopters, and c) will do a reasonably good job in production. Any optimizations beyond this we can deal with later.
Another heuristic that can be added is based on stats about the various machines in the cluster and their overall activity. Basically this would account for situations which would lead to creating masters on machines that are already taking heavy load over time.
this is still a problem for me. particularly because its currently easier to start with multiple replicas and insert data for a while before sharding so that i get a better sense of where balance points should be.
@mlucy -- I don't think hash sharding is related to this. The blueprint compiler would still need to figure out where to place the hash shards. To answer your question though, I'm not quite sure yet, but I think it's a post-LTS feature.
I wonder if it would be enough to assign primaries a higher "usage" value than secondaries.
This could be changed in suggest_blueprint_for_shard() in the file src/clustering/suggester/suggester.cc (not src/clustering/administration/suggester.cc).
Currently, we have lines like this:
So that definitely works for the original test case. I will try some more complicated scenarios.
Of course it will not guarantee that primaries for a given table are distributed across machines, if the machines already have different usage values due to other tables being unevenly distributed between them. For example if one machine already is a primary for a second table, while the other machine has no roles, both primaries of the test table would still be allocated on the same machine (the one that had no role before).
The ordering in which the pre-existing tables are handled by the suggester might also make a difference.
The reason for why this works, which might not be completely obvious, is that we assign one shard at a time in the suggester. Furthermore, we assign the primary first for a given shard, and only afterwards assign the secondaries. Because after the first shard is assigned usage will now be higher for whatever machine its primary was given to, the next shard will have its primary assigned to a different machine and so on.
This appears to work fine. Basically it still tries primarily to balance the number of replica roles over machines. However it assigns slightly higher costs to primaries. So if the number of replicas (secondaries+primaries) on two machines is the same and it can assign primaries/secondaries to either of those, it assign the primary to the one that currently has fewer primary roles.
I think it is important that we have the suggester explicitly distribute a table's primaries across candidate nodes as well as try to minimize backfilling as much as possible (by keeping some shards on the same machines). These are the constraints that make the problem less trivial. We can merge this in for now, but I don't think it satisfies this issue.
Well that is what it's doing now. With prioritize_distribution (which we use for resharding) it primarily tries to distribute primaries and secondaries across nodes. If that doesn't suffice for making a decision between two nodes because they are equal in that respect, the next criteria is to minimize backfilling.
@Tryneus: What it does not do - in case that's what you mean - is to weight those two criteria against each other.
The one always has a "hard" priority over the other. Weighting them against each other would make it much more complicated though. It is also difficult to do if we don't know how much a backfilling or an assignment actually costs. To do that properly, we would have to take things like available disk space on a node, speed of backfilling (which varies heavily based on the storage system used, network bandwidth, cache size etc.) etc. into account.
Another limitation of our current solution is that it is greedy. So it does not necessarily find the global optimum. In general this is a combinatorial problem with exponential complexity. We might implement a better approximation some time than we get from the greedy approach, but that's definitely outside of the scope of this issue.
Which would require twice as much backfilling as when one of the shards is allocated to Node A. I believe we prefer this behavior at the moment, I was just saying we can't forget about it.
@danielmewes, you said yourself that "it will not guarantee that primaries for a given table are distributed across machines", and on this front I think our blueprint suggester can do much better. For certain combinations of pinnings and datacenter affinities, I am fairly certain our suggester will result in very lopsided clusters, when a more balanced solution exists.
@danielmewes, I was planning on implementing a better approximation in the suggester for those scenarios, and seeing as this is my last issue for 1.12, you can assign it back to me if you prefer. Otherwise, we should open a new issue if we close this one.
@Tryneus: Your example is not what's going to happen. One of the master shard's should definitely remain on node A. Note that the assignment is always done from scratch for all tables. So what the suggester is going to do is the following:
Assign shard-1: The current usage is the same everywhere, so it looks at the second criteria, the backfill costs (actually there are a few other criteria which have even higher priority than usage, such as explicit shard pinnings. But let's leave those aside for now). It compares those costs between the nodes, and finds that Node A is cheaper than all others. So it assigns:
@danielmewes, again, I wasn't saying that was a constraint we needed to implement, I'm saying it's a constraint we need to keep in mind if we make any changes.
Also, what I meant by "it will not guarantee that primaries for a given table are distributed across machines" is the following:
Say we have two nodes A and B. Node A currently has 3 primaries for table 1 (e.g. because they were manually pinned to node A). Node B has no roles.
Now if we create a second table and shard it into 2, both primaries can end up on node B. I think this is a desired property though. We primarily want the suggester to distribute load. Distributing primaries for a single table across different nodes is just an aspect of that goal which makes sense in some scenarios but not in others.
I feel that if we are specifying prioritize_distribution = true, the expected behavior in that case is that Node A should have 2 primaries for table 1, and 1 primary for table 2, and Node B has the remainder. Otherwise, I do not understand the point of that flag.
Activity
jdoliner commentedon Feb 15, 2013
You actually explicitly said to me: "JD don't worry about distinguishing between masters and replicas, it's too complicated and doesn't actually make a difference." This behavior was fine for 1.2 because it made things simpler and clumped up masters was very far from being a bottle neck at that point. These are both still true so I'm not sure if it's really worth reconsidering.
coffeemug commentedon Feb 15, 2013
I would never say that. The whole purpose of sharding is to split the table's shards across multiple machines, otherwise the feature has no point. I ran into this bug while doing a demo, and it immediately confused both me, and the people I was demoing the product to. This is also why we added the
prefer_distributionflag, to tell the server we value spreading out the shards over availability.There are at least three separate issues in the deprecated branch where the observed behavior is that the shard primaries are placed on the same machine and the expected behavior is stated to be that the primaries should be on different machines (all three submitted by me):
https://github.com/rethinkdb/rethinkdb-deprecated/issues/1232
https://github.com/rethinkdb/rethinkdb-deprecated/issues/617
https://github.com/rethinkdb/rethinkdb-deprecated/issues/1378
This definitely needs to be fixed.
EDIT: found another issue to the same affect -- https://github.com/rethinkdb/rethinkdb-deprecated/issues/1383
coffeemug commentedon Feb 15, 2013
So actually I now remember the conversation very well (remembered it in my dream, no less -- it was torturing me all day yesterday and my subconscience delivered).
We were talking about availability and I said don't worry about trying to place masters in a way that co-locates them with existing replicas to maximize availability during sharding -- it's too hard (and we're gonna solve that eventually in a different way -- the one later proposed to address automatic failover -- anyway).
But we still have to place shards on separate machines whenever possible.
coffeemug commentedon Feb 15, 2013
Just talked to @jdoliner -- there are a couple of points on blueprint generation:
Since we can't "solve" this problem for all cases, we should lay out heuristics in order of priority here, implement them in the blueprint compiler, and encode them in tests. Here are the constraints we need (from highest to lowest priority -- a higher priority cannot be compromised to satisfy the lower one) because that's what a reasonable observer would expect:
This system is a) simple enough to do, b) won't raise eyebrows from early adopters, and c) will do a reasonably good job in production. Any optimizations beyond this we can deal with later.
al3xandru commentedon Feb 25, 2013
Another heuristic that can be added is based on stats about the various machines in the cluster and their overall activity. Basically this would account for situations which would lead to creating masters on machines that are already taking heavy load over time.
coffeemug commentedon Feb 25, 2013
Moving to 1.5. We should also think about this in context of #364.
coffeemug commentedon Mar 20, 2013
Moving to backlog because we'll probably end up doing #364 first.
underrun commentedon Dec 16, 2013
this is still a problem for me. particularly because its currently easier to start with multiple replicas and insert data for a while before sharding so that i get a better sense of where balance points should be.
mlucy commentedon Dec 16, 2013
@coffeemug -- where is top-level hash sharding on the roadmap these days?
coffeemug commentedon Dec 17, 2013
@mlucy -- I don't think hash sharding is related to this. The blueprint compiler would still need to figure out where to place the hash shards. To answer your question though, I'm not quite sure yet, but I think it's a post-LTS feature.
jdoliner commentedon Dec 17, 2013
@coffeemug you're right.
coffeemug commentedon Jan 14, 2014
Moving to 1.12, assigning to @Tryneus (sorry I didn't mention this one today).
danielmewes commentedon Jan 23, 2014
I wonder if it would be enough to assign primaries a higher "usage" value than secondaries.
This could be changed in
suggest_blueprint_for_shard()in the file src/clustering/suggester/suggester.cc (not src/clustering/administration/suggester.cc).Currently, we have lines like this:
What if we just made the first one something like
(*usage)[primary] += 10and the second one for example(*usage)[*jt] += 7or something like that?Everything else being equal between nodes, I think this might be enough to have primaries distributed between machines.
danielmewes commentedon Jan 23, 2014
@Tryneus would you mind if I took this? Waiting for #1084 to reproduce anyway...
2 remaining items
danielmewes commentedon Jan 23, 2014
So that definitely works for the original test case. I will try some more complicated scenarios.
Of course it will not guarantee that primaries for a given table are distributed across machines, if the machines already have different usage values due to other tables being unevenly distributed between them. For example if one machine already is a primary for a second table, while the other machine has no roles, both primaries of the test table would still be allocated on the same machine (the one that had no role before).
The ordering in which the pre-existing tables are handled by the suggester might also make a difference.
The reason for why this works, which might not be completely obvious, is that we assign one shard at a time in the suggester. Furthermore, we assign the primary first for a given shard, and only afterwards assign the secondaries. Because after the first shard is assigned usage will now be higher for whatever machine its primary was given to, the next shard will have its primary assigned to a different machine and so on.
danielmewes commentedon Jan 23, 2014
This appears to work fine. Basically it still tries primarily to balance the number of replica roles over machines. However it assigns slightly higher costs to primaries. So if the number of replicas (secondaries+primaries) on two machines is the same and it can assign primaries/secondaries to either of those, it assign the primary to the one that currently has fewer primary roles.
danielmewes commentedon Jan 23, 2014
Code review 1148.
Tryneus commentedon Jan 23, 2014
I think it is important that we have the suggester explicitly distribute a table's primaries across candidate nodes as well as try to minimize backfilling as much as possible (by keeping some shards on the same machines). These are the constraints that make the problem less trivial. We can merge this in for now, but I don't think it satisfies this issue.
coffeemug commentedon Jan 23, 2014
Could you explain what you mean? When would you ever want to keep shards on the same machines to minimize backfilling?
danielmewes commentedon Jan 23, 2014
Well that is what it's doing now. With prioritize_distribution (which we use for resharding) it primarily tries to distribute primaries and secondaries across nodes. If that doesn't suffice for making a decision between two nodes because they are equal in that respect, the next criteria is to minimize backfilling.
danielmewes commentedon Jan 23, 2014
@Tryneus: What it does not do - in case that's what you mean - is to weight those two criteria against each other.
The one always has a "hard" priority over the other. Weighting them against each other would make it much more complicated though. It is also difficult to do if we don't know how much a backfilling or an assignment actually costs. To do that properly, we would have to take things like available disk space on a node, speed of backfilling (which varies heavily based on the storage system used, network bandwidth, cache size etc.) etc. into account.
Another limitation of our current solution is that it is greedy. So it does not necessarily find the global optimum. In general this is a combinatorial problem with exponential complexity. We might implement a better approximation some time than we get from the greedy approach, but that's definitely outside of the scope of this issue.
Tryneus commentedon Jan 23, 2014
@coffeemug, Imagine a cluster of three nodes with one table (one shard):
Node A: master
Node B: nothing
Node C: nothing
Then we reshard the table into two shards. If we don't have something to prevent it, we could end up with:
Node A: nothing
Node B: master-shard-1
Node C: master-shard-2
Which would require twice as much backfilling as when one of the shards is allocated to Node A. I believe we prefer this behavior at the moment, I was just saying we can't forget about it.
@danielmewes, you said yourself that "it will not guarantee that primaries for a given table are distributed across machines", and on this front I think our blueprint suggester can do much better. For certain combinations of pinnings and datacenter affinities, I am fairly certain our suggester will result in very lopsided clusters, when a more balanced solution exists.
Tryneus commentedon Jan 23, 2014
@danielmewes, I was planning on implementing a better approximation in the suggester for those scenarios, and seeing as this is my last issue for 1.12, you can assign it back to me if you prefer. Otherwise, we should open a new issue if we close this one.
danielmewes commentedon Jan 24, 2014
@Tryneus: Your example is not what's going to happen. One of the master shard's should definitely remain on node A. Note that the assignment is always done from scratch for all tables. So what the suggester is going to do is the following:
Tryneus commentedon Jan 24, 2014
@danielmewes, again, I wasn't saying that was a constraint we needed to implement, I'm saying it's a constraint we need to keep in mind if we make any changes.
danielmewes commentedon Jan 24, 2014
Also, what I meant by "it will not guarantee that primaries for a given table are distributed across machines" is the following:
Say we have two nodes A and B. Node A currently has 3 primaries for table 1 (e.g. because they were manually pinned to node A). Node B has no roles.
Now if we create a second table and shard it into 2, both primaries can end up on node B. I think this is a desired property though. We primarily want the suggester to distribute load. Distributing primaries for a single table across different nodes is just an aspect of that goal which makes sense in some scenarios but not in others.
danielmewes commentedon Jan 24, 2014
Merged into next 1920cf1 .
Tryneus commentedon Jan 24, 2014
I feel that if we are specifying
prioritize_distribution = true, the expected behavior in that case is thatNode Ashould have 2 primaries for table 1, and 1 primary for table 2, andNode Bhas the remainder. Otherwise, I do not understand the point of that flag.