From 5102fea7d4b2e124ee770688353ea2da6f085ba3 Mon Sep 17 00:00:00 2001 From: bsglz <18031031@qq.com> Date: Fri, 25 Mar 2022 17:42:49 +0800 Subject: [PATCH] HBASE-26884 Find unavailable regions by the startcode checking on hmaster start up and reassign them --- .../master/assignment/AssignmentManager.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManager.java index d94edea912a..ec38d21d323 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManager.java @@ -1696,7 +1696,29 @@ public class AssignmentManager { if (localState.matches(State.OPEN, State.OPENING, State.CLOSING, State.SPLITTING, State.MERGING)) { assert regionLocation != null : "found null region location for " + regionNode; - regionStates.addRegionToServer(regionNode); + + // If the startcode of the regionLocation expired, and neither TRSP on region nor SCP on + // regionserver, then we should reassign the region + boolean startcodeExpired = false; + if (localState.matches(State.OPEN, State.OPENING) && regionNode.getProcedure() == null + && !getMaster().getServerManager().getDeadServers().isDeadServer(regionLocation)) { + List serverNames = getMaster().getServerManager().getOnlineServersList(); + for (ServerName sn : serverNames) { + if (regionLocation.getHostname().equals(sn.getHostname()) + && regionLocation.getPort() == sn.getPort() + && regionLocation.getStartcode() < sn.getStartcode()) { + startcodeExpired = true; + break; + } + } + } + if (startcodeExpired) { + LOG.warn("The startcode of regionLocation expired, reassign the region {}", regionNode); + regionNode.setState(State.OFFLINE); + regionStates.addToOfflineRegions(regionNode); + } else { + regionStates.addRegionToServer(regionNode); + } } else if (localState == State.OFFLINE || regionInfo.isOffline()) { regionStates.addToOfflineRegions(regionNode); }