Skip to content

Automatic failover/rebalance and lossless rebalance. #223

Closed

Description

@jdoliner

Details being migrated from our deprecated repo.

Activity

  1. al3xandru commented on Jan 15, 2013

    @al3xandru
    Contributor

    jdoliner:

    So to get the ball rolling on this here's a proposal about how to do it.

    Extending the blueprint:
    We add a role in the blueprint called vice-primary and flag in the blueprint for whether or not we're in failover mode (actually this is a flag per shard but let's just assume one shard for this description).
    The reactor now has a new role vice-primary. Vice primary behaves exactly like a secondary when the failover flag is false. And like a primary when the failover flag is true.

    Flipping the flag:
    So this gives a way to do failover (which we really already had) the question is who flips this flag. There's a very strict rule about who modifies this flag. When a new blueprint is compiled (due to a user change) the flag is always false. Furthermore at the time when we compile the blueprint we select a machine to be the coordinator. Each machine runs a coroutine which checks for the following condition: The master for namespace n is down and I'm the coordinator for n. If this condition is true then it flips the failover flag which causes the vice primary to take over. This change persists and is displayed to the user as an issue. If the old master comes back up it will act like a secondary (which keeps the secondary counts up to date). Notice this is much better than killing the machine because it can continue fulfilling all of its other roles as soon as it comes back up.

    Limitations:
    There are some cases where full blown quorums would be able to come up with an answer where our system wouldn't. For example if both the coordinator and the primary die at the same time. Or if we have a 3 way netsplit between the primary, vice-primary and the coordinator. While it would be nice to solve these problems I think we'll have a much easier task ahead of us if we limit ourselves to the most basic case of single machine failures. I also think this may prove to be enough long term since you can get in to so many nasty corner cases and can get cascading failures and such.

    Bad Behaviors:
    So I've tried thinking about the corner cases in this for a while. Basically it seems to me that the worst thing that can happen is that 2 nodes on opposite sides of a netsplit can both think that they're both the coordinator. I think we can probably prevent this the same way we do with people redrawing blueprints on opposite sides by requiring that machines be killed however there might be one or 2 problems with this. (I think there are some such problems in our current scheme as well). However even if you do have competing coordinators if they both flip the switch the worst you get is a vclock conflict which we can handle. However these things are rife with corner cases so I invite everyone to try to find them.

  2. al3xandru commented on Jan 15, 2013

    @al3xandru
    Contributor

    coffeemug:

    1. I agree with the main jist of of this. If they have cascading multiway long-lasting netsplits somebody better drag their sleepy ass out of bed because the idea that the db will magically failover and continue working in that scenario is a pipe dream. So a 'simple' implementation is a bug, not a feature. Meant to say a feature, not a bug. Duh.
    2. I don't understand why you introduce a separate notion of a coordinator. Why not have a vice-primary for a shard behave as the coordinator for that shard? If the vice-primary can't see the master for some user-specified period of time, it can flip the failover flag and take over until further notice.
    3. I think we need to be a little more clear about what happens when failover bit is turned on (e.g. what issue does the user see? Is it resolvable? How?) and what happens if the master becomes visible again (do we compile a new blue print to make the old primary a vice-primary, the old vice-primary primary, and turn off the failover bit? or does the old master become master again? etc.)

    EDIT: I suppose outside of failover we want a general notion of a coordinator that's not necessarily tied to a shard. For example, in some cases we might want a coordinator per table, a coordinator per datacenter, or a coordinator per entire cluster. Is that the answer to my question 2?

  3. al3xandru commented on Jan 15, 2013

    @al3xandru
    Contributor

    mlucy:

    I think not having the old master try to become master again is a good idea. It might be failing sporadically, and we want to avoid having it repeatedly assume and drop the role of master.

    I don't quite understand what's supposed to happen in the case of a netsplit. Does the original master just keep serving queries, and discard all of the writes that it served when it rejoins the main cluster?

    Alternatively, is that what the coordinator is for? Like if the primary can't contact either the coordinator or the vice-primary, it stops serving writes and up-to-date reads? That seems to have the desirable characteristic that two machines have to fail before we require human intervention, but we don't have two servers handling write queries on opposite sides of a netsplit (or at least not for very long).

  4. al3xandru commented on Jan 15, 2013

    @al3xandru
    Contributor

    jdoliner:

    I don't understand why you introduce a separate notion of a coordinator. Why not have a vice-primary for a shard behave as the coordinator for that shard? If the vice-primary can't see the master for some user-specified period of time, it can flip the failover flag and take over until further notice.

    Hmm no reason the coordinator couldn't always just be the vice-primary actually. A coordinator per table might be nice although we need to make sure it's not on a machine which is acting as master so I think just having vice-primary act as coordinator might be nice.

    I think we need to be a little more clear about what happens when failover bit is turned on (e.g. what issue does the user see? Is it resolvable? How?) and what happens if the master becomes visible again (do we compile a new blue print to make the old primary a vice-primary, the old vice-primary primary, and turn off the failover bit? or does the old master become master again? etc.)

    When the failover bit is turned on the vice-primary begins acting as master and the master begins acting as a secondary. Note that since this flag only gets flipped when the master is disconnected the master will only see this flag flipped if it reconnects. If it does then it's most likely going to have divergent data at which point it goes into a failure recovery mode (I'll discuss this in a separate comment).

    Whenever a failover flag is flipped the user sees the following issue: "Namespace 'foo' is in emergency failover mode due to machine failure, it may become inaccessible if more machines fail." Basically the point is: your namespace is working but you've lost your safety net.

    If the master reconnects it becomes a secondary so long as the flag is flipped or in the case of divergent data (which is likely) goes into a failure recovery mode.

    We do not ever compile a new blueprint automatically. Blueprints are only every compiled as a response to a user changing the semilattices. I think one of the keys to keeping this sane is having every piece of data be modified by one and only entity. Blueprints are only ever modified by the blueprint compiler when a user makes a change. The failover flag I suppose is technically an exception to this but it only ever gets set to false by the compiler and true by the coordinator so we'll at least always know whose will we're enacting. Having a blueprint change automatically seems like it will just be too hard to keep track of.

  5. al3xandru commented on Jan 15, 2013

    @al3xandru
    Contributor

    jdoliner:

    Alternatively, is that what the coordinator is for? Like if the primary can't contact either the coordinator or the vice-primary, it stops serving writes and up-to-date reads? That seems to have the desirable characteristic that two machines have to fail before we require human intervention, but we don't have two servers handling write queries on opposite sides of a netsplit (or at least not for very long).

    The master machine serves queries for better or for worse until it sees that the flag in the blueprint has been flipped. This should only happen if it disconnects and then reconnects. When it reconnects one of 2 things happens: if its data isn't divergent it just falls in line as a secondary (this keeps our replica count where the user set it which is nice).

    If it's data is divergent it goes in to recovery mode.

    This will require an addition to the reactor. Basically there needs to be a separate code path "reactor_be_ousted_primary" or something. Without divergence it just behaves like reactor_be_secondary. But with divergence it just constructs a direct_reader_t and waits for us to blow away the data (we need to decide exactly how we do this but I think we can find a good answer here). Since it's constructed a direct_reader_t we can now do reads from this divergent copy of the data as if it were a normal namespace. This can be exposed to the user as table("name").branch(uuid). On which you can do any read operation so you can get your diverged data out if you need to.

    Edit:

    Actually because we can have a divergent master we can also have a divergent secondary so we'll probably need similar logic in reactor_be_secondary. Or maybe we just won't have reactor_be_ousted_primary role at all.

  6. al3xandru commented on Jan 15, 2013

    @al3xandru
    Contributor

    coffeemug:

    Namespace 'foo' is in emergency failover mode due to machine failure, it may become inaccessible if more machines fail.

    That's great, though we might want to somehow link it with the issue that arises due to the unreachable machine (or merge them somehow). Naturally if the user declared the unreachable machine dead, both of these issues go away. Presumably this is the only way to resolve the issue (unless we allow marking the vice-primary as primary while one of the machines is unreachable, but since we don't compile blueprints while machines are unreachable, I don't know if we want to violate this rule).

    If the master reconnects it becomes a secondary so long as the flag is flipped or in the case of divergent data (which is likely) goes into a failure recovery mode.

    So presumably in this mode we raise an issue and the user has to pick (or we can automatically pick a new one, or let them set the rule in advance -- whatever). While we're in this state, who remains primary? (presumably vice-primary), and what does the original primary do? (presumably nothing -- it can't act as secondary because it diverged, right?)

    So the one problem with making a vice-primary be the coordinator is that we can't just have a table-wide, datacenter-wide, or cluster-wide if we need one (e.g. if we want to automatically rebalance or something). I think there is a really easy way to fix this though. Say, the coordinator for the lowermost range shard (i.e. -inf-...) is designated as coordinator for table, etc.

    Another problem with the whole thing is, what happens if there is a network race and we compile two blueprints that designate different machines as vice-primaries and now we have two machines think they're vice-primaries until they discover there is a blueprint conflict. I think we'd need to think this one through very carefully.

  7. eakova commented on Jun 17, 2013

    @eakova

    +1 for masterless replication

  8. jacog-cqs commented on Dec 15, 2013

    @jacog-cqs

    +1

    Honestly, this is the one missing feature that has me a bit uneasy with RethinkDB. Every other feature blows the competition completely out of the water.

    (We are going through an exact - "should we bite the bullet" phase right at this point since we are not quite as excited with the existing solution we have in place, although it does the failover bits quite well. Code is there, data migration scripts are there, testing has been completed, but the non-automagically swapover fear is quite big... Option are to (a) hobble along until the fear goes away and we can deploy, (b) look at other solutions (nothing with the same feature set) or (c) "just do it".)

  9. mlucy commented on Dec 16, 2013

    @mlucy
    Member

    I think that @jdoliner is working on failover right now. He can say more about where he is, but if it matters for your plans I would tentatively bet that some sort of automatic failover will be in either the 1.12 or 1.13 release.

  10. danielmewes commented on Jan 17, 2014

    @danielmewes
    Member

    @nviennot mentioned https://github.com/ha/doozerd on IRC. Maybe that's something we could use, or at least look at how it works.

  11. josephglanville commented on Jan 22, 2014

    @josephglanville

    Not doozerd, it's effectively dead at this point. https://github.com/coreos/etcd provides much the same sort of consistent storage but is actively maintained.

    With that in mind if you are going to use a cluster coordination engine for master election you may as well implement an abstract interface for master election so that plugins can be developed for Zookeeper, etcd and friends so that people can leverage stuff they already have.

    Alternatively if all you want is the same guarantees then it might make sense to implement Raft in RethinkDB for internal shard master elections.

  12. madflojo commented on Aug 2, 2014

    @madflojo

    Just throwing this out there but being able to recover from masters being unavailable is the one feature that seems to be missing at this point.

    I agree that you should think of this at a machine level but it would also be good to think of this at a Datacenter level as well. As generally if we are talking about a netsplit, the issue would affect connectivity between data centers.

    Ideally I would love to see if one could setup an odd number of datacenters i.e. 3, 5, 7 etc... If DC1 is the source of the network issue DC2 and DC3 could "vote him off the island" and takeover as a master. Subsequently DC1 would need to identify that he can no longer talk to DC2 and DC3 and go into "read only" mode removing the possibility of a split brain scenario.

    It would be nice if this could be duplicated internally to a datacenter as well.

    Not sure how that works out in the code but just throwing it out there as a feature request.

  13. josephglanville commented on Aug 3, 2014

    @josephglanville

    You are actually surprisingly close to how larger systems that depend on consensus work.

    Usually there is some globally distributed consensus service (PAXOS et al) running in all DCs and then smaller cluster level consensus services in each DC.

    The cluster consensus service can be used to evict machines, whereas the global service can be used to evict entire DCs.

    The reasoning behind not using the big global consensus service for all decisions is that it's likely to be very slow and writes incredibly expensive. (think writing to ~100 disks in RAID1 for every operation)

  14. 13 remaining items

  15. removed this from the subsequent milestone on Mar 24, 2015
  16. danielmewes commented on May 6, 2015

    @danielmewes
    Member

    This is done and will ship with the raft release.

  17. c4milo commented on May 6, 2015

    @c4milo

    💃

  18. danielmewes commented on Jul 1, 2015

    @danielmewes
    Member

    For completeness: 2.1 will have automatic failover and semi-lossless rebalance (the time where the table is unavailable during a rebalance will be a lot shorter), but it won't have automatic rebalancing.

  19. shimonmagal commented on Jul 24, 2015

    @shimonmagal

    Specifically for my use of RethinkDB - I have some queries with .changes() opened by nodejs servers (running a rethinkdb driver). Are there currently ways to recover from both RethinkDB failure/planned-shutdown and/or server communication-failure/planned-shutdown - without making the front end having to re-run the query and register for changes all over again?

    By the way, I really like RethinkDB and thinking about using it in multiple projects I'm working on. I have compared it with meteorjs, and it has much better performace - I'm guessing due to meteor running on NodeJs (I can give more details about the comparison I did...).

    (Also, on one of my projects - there is an already existing code in Java + OracleDB and I have written a replicator from Oracle to RethinkDB/Mongo (for meteor). Oracle is used for Buisness logic (which is already implemented in java and has tens of thousands of lines of code and needs a DB with ACID) and RehinkDB is for data distribution to web clients (former client was swing over Java). I'm about to finish the replicator soon(matter of days) - I hope it will help people with already existing code and systems to create new web client sides for their data and help increase RethinkDB popularity - I will let you know when I'm done - if this should interest you)

  20. danielmewes commented on Jul 24, 2015

    @danielmewes
    Member

    @shimonmagal Currently changefeeds will always be terminated if a server shuts down or a table is resharded.
    We do have some improvements to that in the pipeline. The first step is going to ship with RethinkDB 2.2 and allow changefeeds to survive brief disconnects between the client and the server (see #3471 ). Later we also plan to add a type of changefeed that can survive server failures.

    I'm looking forward to your Oracle -> RethinkDB replicator! :-)

  21. larkost commented on Jul 27, 2015

    @larkost
    Collaborator

    @shimonmagal: The (probably) subsequent feature to allow changefeeds to natively survive these transitions (in most cases) is #3549. There have been a few informal conversations, and a proper implementation of this might well require the infrastructure of #3471.

  22. adamkdean commented on May 5, 2016

    @adamkdean

    @danielmewes

    For completeness: 2.1 will have automatic failover and semi-lossless rebalance (the time where the table is unavailable during a rebalance will be a lot shorter), but it won't have automatic rebalancing.

    Is this still the case with 2.3? I thought with 2.2 onwards we could do a rebalance and still be able to write documents but we get an error that the primary shard is not available if we try to insert a document while the rebalance is in progress.

  23. danielmewes commented on May 5, 2016

    @danielmewes
    Member

    @adamkdean This is still the current state. Individual primaries are still becoming unavailable intermittently during a reconfiguration. Most documents should be writeable individually most of the time, but especially queries that need to touch multiple documents or use secondary indexes will more frequently fail while rebalancing.

  24. danielmewes commented on May 5, 2016

    @danielmewes
    Member

    @adamkdean We're going to look into whether we can significantly reduce the downtime by tweaking RethinkDB's reconfiguration strategy... Maybe there are some small improvements we can do relatively quickly that will have a big impact on improving availability.

  25. adamkdean commented on May 16, 2016

    @adamkdean

    Thanks @danielmewes, appreciate the effort!

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions