tikv / pd

Placement driver for TiKV

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rule_list: should we consider a peer should be leader and follower in 2 rules in `checkApplyRules`

AndreMouche opened this issue · comments

Bug Report

when we try to add new placement-rule into the cluster, we would use the following function to check whether the new rule has conflictions with some exist rules.

func checkApplyRules(rules []*Rule) error {
// check raft constraint
// one and only one leader
leaderCount := 0
voterCount := 0
for _, rule := range rules {
if rule.Role == Leader {
leaderCount += rule.Count
} else if rule.Role == Voter {
voterCount += rule.Count
}
if leaderCount > 1 {
return errors.New("multiple leader replicas")
}
}
if (leaderCount + voterCount) < 1 {
return errors.New("needs at least one leader or voter")
}
return nil
}
)

however, the above function miss the following corner case, which would save conflict placement-rule in the system:

both zone has only 1 tikv instance and the rule defines as the following:
leader should in tikv1, follower should in tikv1, for example:

 CREATE PLACEMENT POLICY leader_follower_in_1 LEADER_CONSTRAINTS="[+zone=bj1]" FOLLOWER_CONSTRAINTS="{+zone=bj1: 1,+zone=bj3: 1}"; 

the above function will return success, while we could never make the replica on tikv1 meet these 2 rules at the same time.