Skip to content

Commit

Permalink
unsafe recovery: Add newly created empty regions output for unsafe re…
Browse files Browse the repository at this point in the history
…covery (tikv#6869)

ref tikv#6715

In DR auto sync scenario, it is possible that a empty range hole is left in the secondary data center 
when the primary data center is totally unavailable and the replication mode is "sync recover" (super 
rare). In this case, unsafe recovery + flashback is not able to recover the cluster. The fallback 
is BR + PiTR.  While, to help the people faster identify whether the fallback is needed, we need to add 
empty regions info in the output of unsafe recovery.

If there are empty regions created, use BR+PiTR. If there are no empty regions, use flashback.

Signed-off-by: Yang Zhang <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
v01dstar and ti-chi-bot[bot] authored Aug 7, 2023
1 parent effaab2 commit ebd2cfe
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/unsaferecovery/unsafe_recovery_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ type Controller struct {
// exposed to the outside for testing
AffectedTableIDs map[int64]struct{}
affectedMetaRegions map[uint64]struct{}
newlyCreatedRegions map[uint64]struct{}
err error
}

Expand Down Expand Up @@ -167,6 +168,7 @@ func (u *Controller) reset() {
u.output = make([]StageOutput, 0)
u.AffectedTableIDs = make(map[int64]struct{}, 0)
u.affectedMetaRegions = make(map[uint64]struct{}, 0)
u.newlyCreatedRegions = make(map[uint64]struct{}, 0)
u.err = nil
}

Expand Down Expand Up @@ -666,6 +668,15 @@ func (u *Controller) getAffectedTableDigest() []string {
}
details = append(details, "affected table ids: "+strings.Trim(tables, ", "))
}
if len(u.newlyCreatedRegions) != 0 {
regions := ""
for r := range u.newlyCreatedRegions {
regions += fmt.Sprintf("%d, ", r)
}
details = append(details, "newly created empty regions: "+strings.Trim(regions, ", "))
} else {
details = append(details, "no newly created empty regions")
}
return details
}

Expand Down Expand Up @@ -1201,6 +1212,7 @@ func (u *Controller) generateCreateEmptyRegionPlan(newestRegionTree *regionTree,
storeRecoveryPlan := u.getRecoveryPlan(storeID)
storeRecoveryPlan.Creates = append(storeRecoveryPlan.Creates, newRegion)
u.recordAffectedRegion(newRegion)
u.newlyCreatedRegions[newRegion.GetId()] = struct{}{}
hasPlan = true
}
lastEnd = region.EndKey
Expand Down

0 comments on commit ebd2cfe

Please sign in to comment.