Skip to content

Blueprint suggester doesn't distribute shards across nodes #344

Closed

Description

@coffeemug
  1. Start a cluster of two rethinkdb nodes:
rdb1$ rethinkdb
rdb2$ rethinkdb --port-offset 1 -j localhost:29015
  1. Go to data explorer, create a table, and insert a bunch of documents (I magically inserted 512).
  2. 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.

Activity

  1. jdoliner commented on Feb 15, 2013

    @jdoliner
    Contributor

    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.

  2. coffeemug commented on Feb 15, 2013

    @coffeemug
    ContributorAuthor

    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):

    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

  3. coffeemug commented on Feb 15, 2013

    @coffeemug
    ContributorAuthor

    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.

  4. coffeemug commented on Feb 15, 2013

    @coffeemug
    ContributorAuthor

    Just talked to @jdoliner -- there are a couple of points on blueprint generation:

    1. It's a pretty complex constraint satisfaction problem
    2. No matter what we do, we'll run into cases that confuse people
    3. Oftentimes the question of what's optimal has very blurry (if any) answer
    4. 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:

    1. 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.
    2. 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.
    3. 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.

  5. al3xandru commented on Feb 25, 2013

    @al3xandru
    Contributor

    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.

  6. coffeemug commented on Feb 25, 2013

    @coffeemug
    ContributorAuthor

    Moving to 1.5. We should also think about this in context of #364.

  7. coffeemug commented on Mar 20, 2013

    @coffeemug
    ContributorAuthor

    Moving to backlog because we'll probably end up doing #364 first.

  8. underrun commented on Dec 16, 2013

    @underrun

    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.

  9. mlucy commented on Dec 16, 2013

    @mlucy
    Member

    @coffeemug -- where is top-level hash sharding on the roadmap these days?

  10. coffeemug commented on Dec 17, 2013

    @coffeemug
    ContributorAuthor

    @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.

  11. jdoliner commented on Dec 17, 2013

    @jdoliner
    Contributor

    @coffeemug you're right.

  12. coffeemug commented on Jan 14, 2014

    @coffeemug
    ContributorAuthor

    Moving to 1.12, assigning to @Tryneus (sorry I didn't mention this one today).

  13. ghost assigned on Jan 14, 2014
  14. danielmewes commented on Jan 23, 2014

    @danielmewes
    Member

    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:

    ...
    //Update primary_usage
    ++(*usage)[primary];
    ...
    //Update secondary usage
    ++(*usage)[*jt];
    ...
    

    What if we just made the first one something like (*usage)[primary] += 10 and the second one for example (*usage)[*jt] += 7 or something like that?

    Everything else being equal between nodes, I think this might be enough to have primaries distributed between machines.

  15. danielmewes commented on Jan 23, 2014

    @danielmewes
    Member

    @Tryneus would you mind if I took this? Waiting for #1084 to reproduce anyway...

  16. 2 remaining items

  17. danielmewes commented on Jan 23, 2014

    @danielmewes
    Member

    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.

  18. danielmewes commented on Jan 23, 2014

    @danielmewes
    Member

    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.

  19. danielmewes commented on Jan 23, 2014

    @danielmewes
    Member

    Code review 1148.

  20. Tryneus commented on Jan 23, 2014

    @Tryneus
    Member

    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.

  21. coffeemug commented on Jan 23, 2014

    @coffeemug
    ContributorAuthor

    as well as try to minimize backfilling as much as possible (by keeping some shards on the same machines)

    Could you explain what you mean? When would you ever want to keep shards on the same machines to minimize backfilling?

  22. danielmewes commented on Jan 23, 2014

    @danielmewes
    Member

    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.

  23. danielmewes commented on Jan 23, 2014

    @danielmewes
    Member

    @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.

  24. Tryneus commented on Jan 23, 2014

    @Tryneus
    Member

    @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.

  25. Tryneus commented on Jan 23, 2014

    @Tryneus
    Member

    @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.

  26. danielmewes commented on Jan 24, 2014

    @danielmewes
    Member

    @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:

    1. Initial state:
    Node A: nothing, usage 0 (but has data)
    Node B: nothing, usage 0
    Node C: nothing, usage 0
    
    1. 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:
    Node A: master-shard-1, usage 10 (but has data)
    Node B: nothing, usage 0
    Node C: nothing, usage 0
    
    1. Assign shard-2: Node B and C have a lower usage than node A. There is no criteria to distinguish between node B and C, so it just picks one of them.
    Node A: master-shard-1, usage 10 (but has data)
    Node B: master-shard-2, usage 10
    Node C: nothing, usage 0
    
  27. Tryneus commented on Jan 24, 2014

    @Tryneus
    Member

    @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.

  28. danielmewes commented on Jan 24, 2014

    @danielmewes
    Member

    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.

  29. danielmewes commented on Jan 24, 2014

    @danielmewes
    Member

    Merged into next 1920cf1 .

  30. Tryneus commented on Jan 24, 2014

    @Tryneus
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions