[Tarantool-patches] [PATCH 5/6] replication: use 'score' to find a join-master

Cyrill Gorcunov gorcunov at gmail.com
Fri Jun 11 00:28:51 MSK 2021


On Thu, Jun 10, 2021 at 10:09:24PM +0200, Vladislav Shpilevoy wrote:
> Hi! Thanks for the review!
> 
> On 10.06.2021 17:02, Cyrill Gorcunov wrote:
> > On Sat, Jun 05, 2021 at 01:37:59AM +0200, Vladislav Shpilevoy wrote:
> >> +		int score = 0;
> >>  		/*
> >> -		 * Try to find a replica which has already left
> >> -		 * orphan mode.
> >> +		 * Prefer instances not configured as read-only via box.cfg, and
> >> +		 * not being in read-only state due to any other reason. The
> >> +		 * config is stronger because if it is configured as read-only,
> >> +		 * it is in read-only state for sure, until the config is
> >> +		 * changed.
> >>  		 */
> >> -		if (ballot->is_ro && !leader_ballot->is_ro)
> >> +		if (!ballot->is_ro_cfg)
> >> +			score += 5;
> >> +		if (!ballot->is_ro)
> >> +			score += 1;
> >> +		if (leader_score < score)
> >> +			goto elect;
> >> +		if (score < leader_score)
> >>  			continue;
> > 
> > Vlad, if only I'm not missing something obvious we can do simplier
> > without branching at all, say
> > 
> > 		score = (ballot->is_booted << 3) |
> > 			(ballot->is_ro_cfg << 2) |
> > 			(ballot->is_ro << 1);
> > 
> > up to you, just an idea.
> 
> This would work, technically. But TBH I don't see how it is simpler.

Due to (x)2^N poly properties when each member is used once and
we use additions only.

First, we drop the branching which allows to save BPU cycles but
since this is not a hot path is doesn't matter. What is matter is
the way we choose weigth triplets. Each score addition (in the
form they are chosen now) generates strict partial order, such
as 1 < 5 < 10, thus if someone occasionally change 5 to 9 this
won't longer work properly I think. In case if someone has to
add fourth score he _is_ to modify the numbers carefully so
the order would remain.

In reverse the 2^N poly already has all these properties: each new
power won't be equal to a sum of previous powers, so that if
fourth score is needed then we simply add (x << 4) to the formula
above.

Anyway, I'm fine with current code, just wanted to explain why
I consider using pows here is more simple and flexible. Since we
have only 3 scores by now plain natural triplets should not
be a problem.


More information about the Tarantool-patches mailing list