From: Sergey Ostanevich <sergos@tarantool.org> To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [RFC] Quorum-based synchronous replication Date: Thu, 28 May 2020 00:17:35 +0300 [thread overview] Message-ID: <20200527211735.GA50@tarantool.org> (raw) In-Reply-To: <887a0ec5-3a01-565a-0c31-f7fab619af8f@tarantool.org> Hi! Thanks for review! Some comments below. On 26 мая 01:41, Vladislav Shpilevoy wrote: > >> > >> The reads should not be inconsistent - so that cluster will keep > >> answering A or B for the same request. And in case we lost quorum we > >> can't say for sure that all instances will answer the same. > >> > >> As we discussed it before, if leader appears in minor part of the > >> cluster it can't issue rollback for all unconfirmed txns, since the > >> majority will re-elect leader who will collect quorum for them. Means, > >> we will appear is a state that cluster split in two. So the minor part > >> should stop. Am I wrong here? > > Yeah, kinda. As long as you allow reading from replicas, you *always* will > have a time slot, when you will be able to read different data for the > same key on different replicas. Even with reads going through quorum. > > Because it is physically impossible to make nodes A and B start answering > the same data at the same time moment. To notify them about a confirm you will > send network messages, they will have not the same delay, won't be processed > in the same moment of time, and some of them probably won't be even delivered. > > The only correct way to read the same - read from one node only. From the > leader. And since this is not our way, it means we can't beat the 'inconsistent' > reads problems. And I don't think we should. Because if somebody needs to do > 'consistent' reads, they should read from leader only. > > In other words, the concept of 'consistency' is highly application dependent > here. If we provide a way to read from replicas, we give flexibility to choose: > read from leader only and see always the same data, or read from all, and have > a possibility, that requests may see different data on different replicas > sometimes. So, it looks like we will follow the current approach: if quorum can't be achieved, cluster appears in r/o mode. Objections? > > > > Replica should report a TXN application success to the leader via the > > IPROTO explicitly to allow leader to collect the quorum for the TXN. > > In case of application failure the replica has to disconnect from the > > replication the same way as it is done now. The replica also has to > > report its disconnection to the orchestrator. Further actions require > > human intervention, since failure means either technical problem (such > > as not enough space for WAL) that has to be resolved or an inconsistent > > state that requires rejoin. > > I don't think a replica should report disconnection. Problem of > disconnection is that it leads to loosing the connection. So it may be > not able to connect to the orchestrator. Also it would be strange for > tarantool to depend on some external service, to which it should report. > This looks like the orchestrator's business how will it determine > connectivity. Replica has nothing to do with it from its side. External service is something I expect to be useful for the first part of implementation - the quorum part. Definitely, we will move onward to achieve some automation in leader election and failover. I just don't expect this to be part of this RFC. Anyways, orchestrator has to ask replica to figure out the connectivity between replica and leader. > > > As soon as leader appears in a situation it has not enough replicas > > to achieve quorum, the cluster should stop accepting any requests - both > > write and read. > > The moment of not having enough replicas can't be determined properly. > You may loose connection to replicas (they could be powered off), but > TCP won't see that, and the node will continue working. The failure will > be discovered only when a 'write' request will try to collect a quorum, > or after a timeout will pass on not delivering heartbeats. During this > time reads will be served. And there is no way to prevent them except > collecting a quorum on that. See my first comment in this email for more > details. > > On the summary: we can't stop accepting read requests. > > Btw, what to do with reads, which were *in-progress*, when the quorum > was lost? Such as long vinyl reads. But the quorum was in place at the start of it? Then according to transaction manager behavior only older version data will be available for read - means data that collected quorum. > > > The reason for this is that replication of transactions > > can achieve quorum on replicas not visible to the leader. On the other > > hand, leader can't achieve quorum with available minority. Leader has to > > report the state and wait for human intervention. > > Yeah, but if the leader couldn't achieve a quorum on some transactions, > they are not visible (assuming MVCC will work properly). So they can't > be read anyway. And if a leader answered an error, it does not mean that > the transaction wasn't replicated on the majority, as we discussed at some > meeting, I don't already remember when. So here read allowance also works > fine - not having some data visible and getting error at a sync transaction > does not mean it is not committed. A user should be aware of that. True, we discussed that we should guarantee only that if we answered 'Ok' then data is present in quorum number of instances. [...] > > demote(ID) - should be called from the Leader instance. > > The Leader has to switch in ro mode and wait for its' undo log is > > empty. This effectively means all transactions are committed in the > > cluster and it is safe pass the leadership. Then it should write > > CURRENT_LEADER_ID as a FORMER_LEADER_ID and put CURRENT_LEADER_ID > > into 0. > > This looks like box.ctl.promote() algorithm. Although I thought we decided > not to implement any kind of auto election here, no? Box.ctl.promote() > assumed, that it does all the steps automatically, except choosing on which > node to call this function. This is what it was so complicated. It was > basically raft. > > But yeah, as discussed verbally, this is a subject for improvement. I personally would like to postpone the algorithm should be postponed for the next stage (Q3-Q4) but now we should not mess up too much to revamp. Hence, we have to elaborate the internals - such as _voting table I mentioned. Even with introduction of terms for each leader - as in RAFT for example - we still can keep it in a replicated space, isn't it? > > The way I see it is that we need to give vclock based algorithm of choosing > a new leader; tell how to stop replication from the old leader; allow to > read vclock from replicas (basically, let the external service read box.info). That's the #1 for me by now: how a read-only replica can quit listening to a demoted leader, which can be not aware of its demotion? Still, for efficiency it should be done w/o disconnection. > > Since you said you think we should not provide an API for all sync transactions > rollback, it looks like no need in a special new API. But if we still want > to allow to rollback all pending transactions of the old leader on a new leader > (like Mons wants) then yeah, seems like we would need a new function. For example, > box.ctl.sync_rollback() to rollback all pending. And box.ctl.sync_confirm() to > confirm all pending. Perhaps we could add more admin-line parameters such as > replica_id with which to write 'confirm/rollback' message. I believe it's a good point to keep two approaches and perhaps set one of the two in configuration. This should resolve the issue with 'the rest of the cluster confirms old leader's transactions and because of it leader can't rollback'. > > > ### Recovery and failover. > > > > Tarantool instance during reading WAL should postpone the undo log > > deletion until the 'confirm' is read. In case the WAL eof is achieved, > > the instance should keep undo log for all transactions that are waiting > > for a confirm entry until the role of the instance is set. > > > > If this instance will be assigned a leader role then all transactions > > that have no corresponding confirm message should be confirmed (see the > > leader role assignment). > > > > In case there's not enough replicas to set up a quorum the cluster can > > be switched into a read-only mode. Note, this can't be done by default > > since some of transactions can have confirmed state. It is up to human > > intervention to force rollback of all transactions that have no confirm > > and to put the cluster into a consistent state. > > Above you said: > > >> As soon as leader appears in a situation it has not enough replicas > >> to achieve quorum, the cluster should stop accepting any requests - both > >> write and read. > > But here I see, that the cluster "switched into a read-only mode". So there > is a contradiction. And I think it should be resolved in favor of > 'read-only mode'. I explained why in the previous comments. My bad, I was moving around this problem already and tend to allow r/o. Will update. > > > In case the instance will be assigned a replica role, it may appear in > > a state that it has conflicting WAL entries, in case it recovered from a > > leader role and some of transactions didn't replicated to the current > > leader. This situation should be resolved through rejoin of the instance. > > > > Consider an example below. Originally instance with ID1 was assigned a > > Leader role and the cluster had 2 replicas with quorum set to 2. > > > > ``` > > +---------------------+---------------------+---------------------+ > > | ID1 | ID2 | ID3 | > > | Leader | Replica 1 | Replica 2 | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx1 | ID1 Tx1 | ID1 Tx1 | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx2 | ID1 Tx2 | ID1 Tx2 | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx3 | ID1 Tx3 | ID1 Tx3 | > > +---------------------+---------------------+---------------------+ > > | ID1 Conf [ID1, Tx1] | ID1 Conf [ID1, Tx1] | | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx4 | ID1 Tx4 | | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx5 | ID1 Tx5 | | > > +---------------------+---------------------+---------------------+ > > | ID1 Conf [ID1, Tx2] | | | > > +---------------------+---------------------+---------------------+ > > | Tx6 | | | > > +---------------------+---------------------+---------------------+ > > | Tx7 | | | > > +---------------------+---------------------+---------------------+ > > ``` > > Suppose at this moment the ID1 instance crashes. Then the ID2 instance > > should be assigned a leader role since its ID1 LSN is the biggest. > > Then this new leader will deliver its WAL to all replicas. > > > > As soon as quorum for Tx4 and Tx5 will be obtained, it should write the > > corresponding Confirms to its WAL. Note that Tx are still uses ID1. > > ``` > > +---------------------+---------------------+---------------------+ > > | ID1 | ID2 | ID3 | > > | (dead) | Leader | Replica 2 | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx1 | ID1 Tx1 | ID1 Tx1 | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx2 | ID1 Tx2 | ID1 Tx2 | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx3 | ID1 Tx3 | ID1 Tx3 | > > +---------------------+---------------------+---------------------+ > > | ID1 Conf [ID1, Tx1] | ID1 Conf [ID1, Tx1] | ID1 Conf [ID1, Tx1] | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx4 | ID1 Tx4 | ID1 Tx4 | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx5 | ID1 Tx5 | ID1 Tx5 | > > +---------------------+---------------------+---------------------+ > > | ID1 Conf [ID1, Tx2] | ID2 Conf [Id1, Tx5] | ID2 Conf [Id1, Tx5] | > > Id1 -> ID1 (typo) Thanks! > > > +---------------------+---------------------+---------------------+ > > | ID1 Tx6 | | | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx7 | | | > > +---------------------+---------------------+---------------------+ > > ``` > > After rejoining ID1 will figure out the inconsistency of its WAL: the > > last WAL entry it has is corresponding to Tx7, while in Leader's log the > > last entry with ID1 is Tx5. Confirm for a Tx can only be issued after > > appearance of the Tx on the majoirty of replicas, hence there's a good > > chances that ID1 will have inconsistency in its WAL covered with undo > > log. So, by rolling back all excessive Txs (in the example they are Tx6 > > and Tx7) the ID1 can put its memtx and vynil in consistent state. > > Yeah, but the problem is that the node1 has vclock[ID1] == 'Conf [ID1, Tx2]'. > This row can't be rolled back. So looks like node1 needs a rejoin. Confirm message is equivalent to a NOP - @sergepetrenko apparently does implementation exactly this way. So there's no need to roll it back in an engine, rather perform the xlog rotation before it. > > > At this point a snapshot can be created at ID1 with appropriate WAL > > rotation. The old WAL should be renamed so it will not be reused in the > > future and can be kept for postmortem. > > ``` > > +---------------------+---------------------+---------------------+ > > | ID1 | ID2 | ID3 | > > | Replica 1 | Leader | Replica 2 | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx1 | ID1 Tx1 | ID1 Tx1 | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx2 | ID1 Tx2 | ID1 Tx2 | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx3 | ID1 Tx3 | ID1 Tx3 | > > +---------------------+---------------------+---------------------+ > > | ID1 Conf [ID1, Tx1] | ID1 Conf [ID1, Tx1] | ID1 Conf [ID1, Tx1] | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx4 | ID1 Tx4 | ID1 Tx4 | > > +---------------------+---------------------+---------------------+ > > | ID1 Tx5 | ID1 Tx5 | ID1 Tx5 | > > +---------------------+---------------------+---------------------+ > > | | ID2 Conf [Id1, Tx5] | ID2 Conf [Id1, Tx5] | > > +---------------------+---------------------+---------------------+ > > | | ID2 Tx1 | ID2 Tx1 | > > +---------------------+---------------------+---------------------+ > > | | ID2 Tx2 | ID2 Tx2 | > > +---------------------+---------------------+---------------------+ > > ``` > > Although, in case undo log is not enough to cover the WAL inconsistence > > with the new leader, the ID1 needs a complete rejoin.
next prev parent reply other threads:[~2020-05-27 21:17 UTC|newest] Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-04-03 21:08 Sergey Ostanevich 2020-04-07 13:02 ` Aleksandr Lyapunov 2020-04-08 9:18 ` Sergey Ostanevich 2020-04-08 14:05 ` Konstantin Osipov 2020-04-08 15:06 ` Sergey Ostanevich 2020-04-14 12:58 ` Sergey Bronnikov 2020-04-14 14:43 ` Sergey Ostanevich 2020-04-15 11:09 ` sergos 2020-04-15 14:50 ` sergos 2020-04-16 7:13 ` Aleksandr Lyapunov 2020-04-17 10:10 ` Konstantin Osipov 2020-04-17 13:45 ` Sergey Ostanevich 2020-04-20 11:20 ` Serge Petrenko 2020-04-20 23:32 ` Vladislav Shpilevoy 2020-04-21 10:49 ` Sergey Ostanevich 2020-04-21 22:17 ` Vladislav Shpilevoy 2020-04-22 16:50 ` Sergey Ostanevich 2020-04-22 20:28 ` Vladislav Shpilevoy 2020-04-23 6:58 ` Konstantin Osipov 2020-04-23 9:14 ` Konstantin Osipov 2020-04-23 11:27 ` Sergey Ostanevich 2020-04-23 11:43 ` Konstantin Osipov 2020-04-23 15:11 ` Sergey Ostanevich 2020-04-23 20:39 ` Konstantin Osipov 2020-04-23 21:38 ` Vladislav Shpilevoy 2020-04-23 22:28 ` Konstantin Osipov 2020-04-30 14:50 ` Sergey Ostanevich 2020-05-06 8:52 ` Konstantin Osipov 2020-05-06 16:39 ` Sergey Ostanevich 2020-05-06 18:44 ` Konstantin Osipov 2020-05-12 15:55 ` Sergey Ostanevich 2020-05-12 16:42 ` Konstantin Osipov 2020-05-13 21:39 ` Vladislav Shpilevoy 2020-05-13 23:54 ` Konstantin Osipov 2020-05-14 20:38 ` Sergey Ostanevich 2020-05-20 20:59 ` Sergey Ostanevich 2020-05-25 23:41 ` Vladislav Shpilevoy 2020-05-27 21:17 ` Sergey Ostanevich [this message] 2020-06-09 16:19 ` Sergey Ostanevich 2020-06-11 15:17 ` Vladislav Shpilevoy 2020-06-12 20:31 ` Sergey Ostanevich 2020-05-13 21:36 ` Vladislav Shpilevoy 2020-05-13 23:45 ` Konstantin Osipov 2020-05-06 18:55 ` Konstantin Osipov 2020-05-06 19:10 ` Konstantin Osipov 2020-05-12 16:03 ` Sergey Ostanevich 2020-05-13 21:42 ` Vladislav Shpilevoy 2020-05-14 0:05 ` Konstantin Osipov 2020-05-07 23:01 ` Konstantin Osipov 2020-05-12 16:40 ` Sergey Ostanevich 2020-05-12 17:47 ` Konstantin Osipov 2020-05-13 21:34 ` Vladislav Shpilevoy 2020-05-13 23:31 ` Konstantin Osipov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200527211735.GA50@tarantool.org \ --to=sergos@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [RFC] Quorum-based synchronous replication' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox