[Tarantool-patches] [PATCH 6/7] box: introduce `box.ctl.demote`

Serge Petrenko sergepetrenko at tarantool.org
Mon Jun 21 17:56:09 MSK 2021



19.06.2021 01:52, Vladislav Shpilevoy пишет:
> Thanks for the patch!
>
> See 3 comments below.

Thanks for the review!

>>      box: introduce `box.ctl.demote`
>>      
>>      Introduce a new journal entry, DEMOTE. The entry has the same meaning as
>>      PROMOTE, with the only difference that it clears limbo ownership instead
>>      of transferring it to the issuer.
>>      
>>      Introduce `box.ctl.demote`, which works exactly like `box.ctl.promote`,
>>      but results in writing DEMOTE instead of PROMOTE.
>>      
>>      A new request was necessary instead of simply writing PROMOTE(origin_id
>>      = 0), because origin_id is deduced from row.replica_id, which cannot be
>>      0 for replicated rows (it's always equal to instance_id of the row
>>      originator).
>>      
>>      Closes #6034
>>      
>>      @TarantoolBod document
> 1. TarantoolBod -> TarantoolBot

Fixed.

>
>>      Title: box.ctl.demote
>>      
>>      `box.ctl.demote()` is a new function, which works exactly like
>>      `box.ctl.promote()`, with one exception that it results in the instance
>>      writing DEMOTE request to WAL instead of a PROMOTE request.
>>      
>>      A DEMOTE request (DEMOTE = 32) copies PROMOTE behaviour (it clears the
>>      limbo as well), but clears limbo ownership instead of assigning it to a
>>      new instance.
>>
>> diff --git a/src/box/box.cc b/src/box/box.cc
>> index 53a8f80e5..f2bde910c 100644
>> --- a/src/box/box.cc
>> +++ b/src/box/box.cc
>> @@ -1527,8 +1527,8 @@ box_wait_quorum(uint32_t lead_id, int64_t target_lsn, int quorum,
>>   	return 0;
>>   }
>>   
>> -int
>> -box_promote(void)
>> +static int
>> +box_clear_synchro_queue(bool demote)
>>   {
>>   	/* A guard to block multiple simultaneous function invocations. */
>>   	static bool in_promote = false;
> 2. A few lines below there is an error message about simultaneous invocations.
> It still talks only about promote(), but I think it should mention demote() too.

Sure, fixed. Please find the diff below.

>
>> @@ -1691,10 +1691,16 @@ promote:
> 3. That looks strange.
>
> tarantool> box.cfg{election_mode = 'candidate'}
>
> tarantool> box.info.election
> ---
> - state: leader
>    vote: 1
>    leader: 1
>    term: 2
> ...
>
> tarantool> box.ctl.demote()
> ---
> ...
>
> tarantool> box.info.election
> ---
> - state: leader
>    vote: 1
>    leader: 1
>    term: 2
> ...
>
> So demote() didn't demote the leader nor raised an error. I
> would rather expect from demote() that it can be called only
> on the leader, and always makes it a follower. Even if the
> node is mode='candidate' and would elect itself again, still
> I would think it should step down in the current term.
>

Ok, I see.

Maybe rename `box.ctl.demote()` to something else?
The notorious `clear_synchro_queue`, for example.
This way the user won't expect the function to demote a leader.

I intended the function to be used as PROMOTE for replica id 0,
i.e. someone has to become the leader before writing PROMOTE/DEMOTE.

This means both functions result in electing a leader. But for a different
purpose: either to pin the limbo to it, or free the limbo from any other 
owner.

=================================================

diff --git a/src/box/box.cc b/src/box/box.cc
index f2bde910c..44ee327e9 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -1533,7 +1533,8 @@ box_clear_synchro_queue(bool demote)
         /* A guard to block multiple simultaneous function invocations. */
         static bool in_promote = false;
         if (in_promote) {
-               diag_set(ClientError, ER_UNSUPPORTED, "box.ctl.promote",
+               diag_set(ClientError, ER_UNSUPPORTED,
+                        demote ? "box.ctl.demote" : "box.ctl.promote",
                          "simultaneous invocations");
                 return -1;
         }


=================================================

-- 
Serge Petrenko



More information about the Tarantool-patches mailing list