[Tarantool-patches] [PATCH v4 10/16] box: make promote always bump the term

Sergey Petrenko sergepetrenko at tarantool.org
Thu Jul 29 23:46:52 MSK 2021


27.07.2021 02:45, Vladislav Shpilevoy пишет:
> Thanks for the fixes!
>
>> diff --git a/src/box/raft.c b/src/box/raft.c
>> index eb62e9630..35c471f58 100644
>> --- a/src/box/raft.c
>> +++ b/src/box/raft.c
>> @@ -394,6 +394,46 @@ box_raft_wait_term_outcome(void)
> <...>
>
>> +
>> +int
>> +box_raft_wait_term_persisted(void)
>> +{
>> +	if (box_raft()->term == box_raft()->volatile_term)
>> +		return 0;
>> +	struct raft_wait_persisted_data data = {
>> +		.waiter = fiber(),
>> +		.term = box_raft()->volatile_term,
>> +	};
>> +	struct trigger trig;
>> +	trigger_create(&trig, box_raft_wait_term_persisted_f, &data, NULL);
>> +	raft_on_update(box_raft(), &trig);
>> +
>> +	do {
>> +		fiber_yield();
>> +	} while (box_raft()->term < data.term && !fiber_is_cancelled());
> Could I ask you please to cache box_raft() into a variable?
> It would be shorter and slightly easier to read.

Sure. Done.


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

diff --git a/src/box/raft.c b/src/box/raft.c
index 35c471f58..bef9414c3 100644
--- a/src/box/raft.c
+++ b/src/box/raft.c
@@ -412,19 +412,20 @@ box_raft_wait_term_persisted_f(struct trigger 
*trig, void *event)
  int
  box_raft_wait_term_persisted(void)
  {
-       if (box_raft()->term == box_raft()->volatile_term)
+       struct raft *raft = box_raft();
+       if (raft->term == raft->volatile_term)
                 return 0;
         struct raft_wait_persisted_data data = {
                 .waiter = fiber(),
-               .term = box_raft()->volatile_term,
+               .term = raft->volatile_term,
         };
         struct trigger trig;
         trigger_create(&trig, box_raft_wait_term_persisted_f, &data, NULL);
-       raft_on_update(box_raft(), &trig);
+       raft_on_update(raft, &trig);

         do {
                 fiber_yield();
-       } while (box_raft()->term < data.term && !fiber_is_cancelled());
+       } while (raft->term < data.term && !fiber_is_cancelled());

         trigger_clear(&trig);
         if (fiber_is_cancelled()) {

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

>> +
>> +	trigger_clear(&trig);
>> +	if (fiber_is_cancelled()) {
>> +		diag_set(FiberIsCancelled);
>> +		return -1;
>> +	}
>> +	return 0;
>> +}


More information about the Tarantool-patches mailing list