From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Serge Petrenko <sergepetrenko@tarantool.org>, gorcunov@gmail.com Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH v3 04/12] box: make promote always bump the term Date: Sun, 4 Jul 2021 14:14:33 +0200 [thread overview] Message-ID: <fe808d3a-823d-22dc-6953-db0325db78a9@tarantool.org> (raw) In-Reply-To: <46c167f8c9bfe0e35370b0cbf10505d9d4a888ba.1624918077.git.sergepetrenko@tarantool.org> Thanks for the patch! Did you think about making it NOP when the node is already a leader (even in manual/off mode)? The current solution is all good except that it makes the current leader temporary read-only until it wins the election again, which looks strange. I would say "unexpected" for users. See 4 comments below. > diff --git a/src/box/box.cc b/src/box/box.cc > index 6a0950f44..ce37b307d 100644 > --- a/src/box/box.cc > +++ b/src/box/box.cc > @@ -1687,16 +1687,19 @@ box_promote(void) > rc = -1; > } else { > promote: > - /* We cannot possibly get here in a volatile state. */ > - assert(box_raft()->volatile_term == box_raft()->term); > - txn_limbo_write_promote(&txn_limbo, wait_lsn, > - box_raft()->term); > + if (try_wait) { > + raft_new_term(box_raft()); > + if (box_raft_wait_persisted() < 0) 1. What if during term WAL write another node also started promote, won the elections and delivered the promote to us? I suppose after the WAL write we will silently write PROMOTE for the term which was won by somebody else, right? Can it be covered by a test? > + return -1; > + } > + uint64_t term = box_raft()->term; > + txn_limbo_write_promote(&txn_limbo, wait_lsn, term); > struct synchro_request req = { > .type = IPROTO_PROMOTE, > .replica_id = former_leader_id, > .origin_id = instance_id, > .lsn = wait_lsn, > - .term = box_raft()->term, > + .term = term, > }; > txn_limbo_process(&txn_limbo, &req); > assert(txn_limbo_is_empty(&txn_limbo)); > diff --git a/src/box/raft.c b/src/box/raft.c > index 7f787c0c5..17caf6f54 100644 > --- a/src/box/raft.c > +++ b/src/box/raft.c > @@ -354,6 +354,42 @@ box_raft_wait_leader_found(void) > return 0; > } > > +struct raft_wait_persisted_data { > + struct fiber *waiter; > + uint64_t term; > +}; > + > +static int > +box_raft_wait_persisted_f(struct trigger *trig, void *event) > +{ > + struct raft *raft = event; > + struct raft_wait_persisted_data *data = trig->data; > + if (raft->term >= data->term) > + fiber_wakeup(data->waiter); > + return 0; > +} > + > +int > +box_raft_wait_persisted(void) > +{ > + if (box_raft()->term == box_raft()->volatile_term) 2. Since it only waits for term being persisted, I would rather call it 'wait_term_persisted'. Because there is also vote, and you do not look at it. > + return 0; > + struct raft_wait_persisted_data data = { > + .waiter = fiber(), > + .term = box_raft()->volatile_term, > + }; > + struct trigger trig; > + trigger_create(&trig, box_raft_wait_persisted_f, &data, NULL); > + raft_on_update(box_raft(), &trig); > + fiber_yield(); 3. What about spurious wakeups? I could call fiber.wakeup() from Lua on this fiber. > + trigger_clear(&trig); > + if (fiber_is_cancelled()) { > + diag_set(FiberIsCancelled); > + return -1; > + } > + return 0; > +} > diff --git a/test/replication/gh-4114-local-space-replication.result b/test/replication/gh-4114-local-space-replication.result > index 9b63a4b99..e71eb60a8 100644 > --- a/test/replication/gh-4114-local-space-replication.result > +++ b/test/replication/gh-4114-local-space-replication.result > @@ -45,9 +45,8 @@ test_run:cmd('switch replica') > | --- > | - true > | ... > -box.info.vclock[0] > +a = box.info.vclock[0] or 0 > | --- > - | - null > | ... > box.cfg{checkpoint_count=1} > | --- > @@ -77,9 +76,9 @@ box.space.test:insert{3} > | - [3] > | ... > > -box.info.vclock[0] > +assert(box.info.vclock[0] == a + 3) > | --- > - | - 3 > + | - true 4. Why do you need these changes? I reverted this test and it passed.
next prev parent reply other threads:[~2021-07-04 12:14 UTC|newest] Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-06-28 22:12 [Tarantool-patches] [PATCH v3 00/12] forbid implicit limbo ownership transition Serge Petrenko via Tarantool-patches 2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 01/12] replication: always send raft state to subscribers Serge Petrenko via Tarantool-patches 2021-07-04 12:12 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-09 9:43 ` Serge Petrenko via Tarantool-patches 2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 02/12] txn_limbo: fix promote term filtering Serge Petrenko via Tarantool-patches 2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 03/12] raft: refactor raft_new_term() Serge Petrenko via Tarantool-patches 2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 04/12] box: make promote always bump the term Serge Petrenko via Tarantool-patches 2021-07-04 12:14 ` Vladislav Shpilevoy via Tarantool-patches [this message] 2021-07-14 18:26 ` Serge Petrenko via Tarantool-patches 2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 05/12] replication: forbid implicit limbo owner transition Serge Petrenko via Tarantool-patches 2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 06/12] box: allow calling promote on a candidate Serge Petrenko via Tarantool-patches 2021-07-04 12:14 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-14 18:26 ` Serge Petrenko via Tarantool-patches 2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 07/12] box: introduce `box.ctl.demote` Serge Petrenko via Tarantool-patches 2021-07-04 12:27 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-14 18:28 ` Serge Petrenko via Tarantool-patches 2021-07-21 23:28 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-23 7:44 ` Sergey Petrenko via Tarantool-patches 2021-07-26 23:50 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-29 20:56 ` Sergey Petrenko via Tarantool-patches 2021-08-01 16:19 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-03 7:56 ` Serge Petrenko via Tarantool-patches 2021-08-03 23:25 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-04 13:08 ` Serge Petrenko via Tarantool-patches 2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 08/12] txn_limbo: persist the latest effective promote in snapshot Serge Petrenko via Tarantool-patches 2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 09/12] replication: encode version in JOIN request Serge Petrenko via Tarantool-patches 2021-07-04 12:27 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-14 18:28 ` Serge Petrenko via Tarantool-patches 2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 10/12] replication: add META stage to JOIN Serge Petrenko via Tarantool-patches 2021-07-04 12:28 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-14 18:28 ` Serge Petrenko via Tarantool-patches 2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 11/12] replication: send latest effective promote in initial join Serge Petrenko via Tarantool-patches 2021-07-04 12:28 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-14 18:28 ` Serge Petrenko via Tarantool-patches 2021-06-28 22:12 ` [Tarantool-patches] [PATCH v3 12/12] replication: send current Raft term in join response Serge Petrenko via Tarantool-patches 2021-07-04 12:29 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-14 18:28 ` Serge Petrenko via Tarantool-patches 2021-08-04 22:41 ` [Tarantool-patches] [PATCH v3 00/12] forbid implicit limbo ownership transition Vladislav Shpilevoy via Tarantool-patches 2021-08-06 7:54 ` Vitaliia Ioffe via Tarantool-patches 2021-08-06 8:31 ` Kirill Yukhin via Tarantool-patches 2021-08-08 10:46 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-09 7:14 ` Kirill Yukhin via Tarantool-patches
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=fe808d3a-823d-22dc-6953-db0325db78a9@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=gorcunov@gmail.com \ --cc=sergepetrenko@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v3 04/12] box: make promote always bump the term' \ /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