Skip to content

Commit

Permalink
[BugFix] Fix delete LOCATION_MISMATCH redundant replica bug (StarRock…
Browse files Browse the repository at this point in the history
…s#50331)

Signed-off-by: gengjun-git <[email protected]>
Signed-off-by: zhiminr.ren <[email protected]>
  • Loading branch information
gengjun-git authored and renzhimin7 committed Nov 7, 2024
1 parent e476ce8 commit 8dca4d6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/clone/TabletScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -1151,13 +1152,33 @@ private boolean deleteLocationMismatchReplica(TabletSchedCtx tabletCtx, boolean
// won't delete location mismatched replica.
return false;
}

Set<Pair<String, String>> matchedLocations = new HashSet<>();
Replica dupReplica = null;
//1. delete the unmatched replica
for (Replica replica : tabletCtx.getReplicas()) {
if (!TabletChecker.isLocationMatch(replica.getBackendId(), tabletCtx.getRequiredLocation())) {
deleteReplicaInternal(tabletCtx, replica, "location mismatch", force);
return true;
} else {
Backend backend = systemInfoService.getBackend(replica.getBackendId());
if (backend != null) {
Pair<String, String> location = backend.getSingleLevelLocationKV();
if (location != null && matchedLocations.contains(location)) {
dupReplica = replica;
} else {
matchedLocations.add(location);
}
}
}
}

//2. delete the duplicate location replica
if (dupReplica != null) {
deleteReplicaInternal(tabletCtx, dupReplica, "duplicate location", force);
return true;
}

return false;
}

Expand Down

0 comments on commit 8dca4d6

Please sign in to comment.