[Tarantool-patches] [PATCH v2 2/8] txn_limbo: fix promote term filtering

Serge Petrenko sergepetrenko at tarantool.org
Mon Jun 21 18:09:42 MSK 2021



18.06.2021 13:31, Cyrill Gorcunov пишет:
> On Fri, Jun 18, 2021 at 12:07:36AM +0300, Serge Petrenko wrote:
>> txn_limbo_process() used to filter out promote requests whose term was
>> equal to the greatest term seen. This wasn't correct for PROMOTE entries
>> with term 1.
>>
>> Such entries appear after box.ctl.promote() is issued on an instance
>> with disabled elections. Every PROMOTE entry from such an instance has
>> term 1, but should still be applied. Fix this in the patch.
>>
>> Also, when an outdated PROMOTE entry with term smaller than already
>> applied from some replica arrived, it wasn't filtered at all. Such a
>> situation shouldn't be possible, but fix it as well.
>>
>> Part-of #6034
>> ---
>>   src/box/txn_limbo.c | 22 +++++++++++++---------
>>   1 file changed, 13 insertions(+), 9 deletions(-)
>>
>> diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c
>> index 51dc2a186..a5d1df00c 100644
>> --- a/src/box/txn_limbo.c
>> +++ b/src/box/txn_limbo.c
>> @@ -665,17 +665,21 @@ txn_limbo_process(struct txn_limbo *limbo, const struct synchro_request *req)
>>   {
>>   	uint64_t term = req->term;
>>   	uint32_t origin = req->origin_id;
>> -	if (txn_limbo_replica_term(limbo, origin) < term) {
>> +	if (txn_limbo_replica_term(limbo, origin) < term)
>>   		vclock_follow(&limbo->promote_term_map, origin, term);
>> -		if (term > limbo->promote_greatest_term) {
>> -			limbo->promote_greatest_term = term;
>> -		} else if (req->type == IPROTO_PROMOTE) {
>> -			/*
>> -			 * PROMOTE for outdated term. Ignore.
>> -			 */
>> -			return;
>> -		}
>> +
>> +	if (term > limbo->promote_greatest_term) {
>> +		limbo->promote_greatest_term = term;
>> +	} else if (req->type == IPROTO_PROMOTE &&
>> +		   limbo->promote_greatest_term > 1) {
>> +		/* PROMOTE for outdated term. Ignore. */
>> +		say_info("RAFT: ignoring PROMOTE request from instance "
>> +			 "id %"PRIu32" for term %"PRIu64". Greatest term seen "
>> +			 "before (%"PRIu64") is bigger.", origin, term,
>> +			 limbo->promote_greatest_term);
>> +		return;
>>   	}

Thanks for the review!

> Serge, here is a moment I don't understand. The promote_term_map
> and promote_greatest_term both are zero initially, then we start
> accepting requests from the net and previously we've been updating
> promote_term_map and promote_greatest_term in same context, iow
> promote_term_map is filtering incoming traffic and update
> promote_greatest_term with max from promote_term_map, thus
> we can denote it as
>
> 	if (term > promote_term_map[i]) {
> 		promote_term_map[i] = term;
> 		promote_greatest_term = max(promote_greatest_term, term);
> 	}
>
> thus promote_greatest_term always = max({promote_term_map[i]}), so I don't
> understart why say
>
> 	uint64_t term = req->term;
> 	uint32_t origin = req->origin_id;
>
> 	if (txn_limbo_replica_term(limbo, origin) < term) {
> 		vclock_follow(&limbo->promote_term_map, origin, term);
> 		if (term > limbo->promote_greatest_term)
> 			limbo->promote_greatest_term = term;
> 	}
>
> 	if (iproto_type_is_promote_request(req->type) &&
> 	    limbo->promote_greatest_term > 1) {
> 		/* PROMOTE for outdated term. Ignore. */
> 		say_info("RAFT: ignoring %s request from instance "
> 			 "id %"PRIu32" for term %"PRIu64". Greatest term seen "
> 			 "before (%"PRIu64") is bigger.",
> 			 iproto_type_name(req->type), origin, term,
> 			 limbo->promote_greatest_term);
> 		return;
> 	}
>
> won't do the trick? Do I miss something obvious here?
It will, thanks for the suggestion! I applied your changes:

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

diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c
index e91782b40..16181b8a0 100644
--- a/src/box/txn_limbo.c
+++ b/src/box/txn_limbo.c
@@ -665,11 +665,10 @@ txn_limbo_process(struct txn_limbo *limbo, const 
struct synchro_request *req)
  {
         uint64_t term = req->term;
         uint32_t origin = req->origin_id;
-       if (txn_limbo_replica_term(limbo, origin) < term)
+       if (txn_limbo_replica_term(limbo, origin) < term) {
                 vclock_follow(&limbo->promote_term_map, origin, term);
-
-       if (term > limbo->promote_greatest_term) {
-               limbo->promote_greatest_term = term;
+               if (term > limbo->promote_greatest_term)
+                       limbo->promote_greatest_term = term;
         } else if (req->type == IPROTO_PROMOTE &&
                    limbo->promote_greatest_term > 1) {
                 /* PROMOTE for outdated term. Ignore. */

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

-- 
Serge Petrenko



More information about the Tarantool-patches mailing list