Skip to content

Commit

Permalink
unsafe recovery: Fix lock contention (#8013)
Browse files Browse the repository at this point in the history
close #4399

Signed-off-by: Yang Zhang <[email protected]>
  • Loading branch information
v01dstar authored Apr 2, 2024
1 parent 6ea3d29 commit 39fa88e
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions server/cluster/unsafe_recovery_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func (u *unsafeRecoveryController) generatePlan(newestRegionTree *regionTree, pe
}
fallthrough
case createEmptyRegion:
if hasPlan, err = u.generateCreateEmptyRegionPlan(newestRegionTree, peersMap); hasPlan && err == nil {
if hasPlan, err = u.generateCreateEmptyRegionPlan(newestRegionTree); hasPlan && err == nil {
u.changeStage(createEmptyRegion)
break
}
Expand Down Expand Up @@ -1104,7 +1104,7 @@ func (u *unsafeRecoveryController) generateDemoteFailedVoterPlan(newestRegionTre
return hasPlan
}

func (u *unsafeRecoveryController) generateCreateEmptyRegionPlan(newestRegionTree *regionTree, peersMap map[uint64][]*regionItem) (bool, error) {
func (u *unsafeRecoveryController) generateCreateEmptyRegionPlan(newestRegionTree *regionTree) (bool, error) {
if u.err != nil {
return false, nil
}
Expand Down Expand Up @@ -1159,25 +1159,6 @@ func (u *unsafeRecoveryController) generateCreateEmptyRegionPlan(newestRegionTre
err = createRegionErr
return false
}
// paranoid check: shouldn't overlap with any of the peers
for _, peers := range peersMap {
for _, peer := range peers {
if !peer.IsInitialized() {
continue
}
if (bytes.Compare(newRegion.StartKey, peer.Region().StartKey) <= 0 &&
(len(newRegion.EndKey) == 0 || bytes.Compare(peer.Region().StartKey, newRegion.EndKey) < 0)) ||
((len(peer.Region().EndKey) == 0 || bytes.Compare(newRegion.StartKey, peer.Region().EndKey) < 0) &&
(len(newRegion.EndKey) == 0 || (len(peer.Region().EndKey) != 0 && bytes.Compare(peer.Region().EndKey, newRegion.EndKey) <= 0))) {
err = errors.Errorf(
"Find overlap peer %v with newly created empty region %v",
logutil.RedactStringer(core.RegionToHexMeta(peer.Region())),
logutil.RedactStringer(core.RegionToHexMeta(newRegion)),
)
return false
}
}
}
storeRecoveryPlan := u.getRecoveryPlan(storeID)
storeRecoveryPlan.Creates = append(storeRecoveryPlan.Creates, newRegion)
u.recordAffectedRegion(newRegion)
Expand Down

0 comments on commit 39fa88e

Please sign in to comment.