Skip to content

Commit

Permalink
HBASE-28405 Fix failed procedure rollback when region was not closed …
Browse files Browse the repository at this point in the history
…and is still in state merging (#5799)

Co-authored-by: Duo Zhang <zhangduo@apache.org>
Signed-off-by: Duo Zhang <zhangduo@apache.org>
Signed-off-by: Viraj Jasani <vjasani@apache.org>
(cherry picked from commit ba09913)
  • Loading branch information
mnpoonia authored and Apache9 committed Apr 28, 2024
1 parent 2dc9eb9 commit 1994b26
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ protected void rollbackState(final MasterProcedureEnv env, final MergeTableRegio
postRollBackMergeRegions(env);
break;
case MERGE_TABLE_REGIONS_PREPARE:
rollbackPrepareMerge(env);
break;
default:
throw new UnsupportedOperationException(this + " unhandled state=" + state);
Expand Down Expand Up @@ -513,6 +514,19 @@ private boolean isMergeable(final MasterProcedureEnv env, final RegionState rs)
return response.hasMergeable() && response.getMergeable();
}

/**
* Action for rollback a merge table after prepare merge
*/
private void rollbackPrepareMerge(final MasterProcedureEnv env) throws IOException {
for (RegionInfo rinfo : regionsToMerge) {
RegionStateNode regionStateNode =
env.getAssignmentManager().getRegionStates().getRegionStateNode(rinfo);
if (regionStateNode.getState() == State.MERGING) {
regionStateNode.setState(State.OPEN);
}
}
}

/**
* Pre merge region action
* @param env MasterProcedureEnv
Expand Down Expand Up @@ -633,8 +647,20 @@ private void cleanupMergedRegion(final MasterProcedureEnv env) throws IOExceptio
* Rollback close regions
**/
private void rollbackCloseRegionsForMerge(MasterProcedureEnv env) throws IOException {
AssignmentManagerUtil.reopenRegionsForRollback(env, Arrays.asList(regionsToMerge),
getRegionReplication(env), getServerName(env));
// At this point we should check if region was actually closed. If it was not closed then we
// don't need to repoen the region and we can just change the regionNode state to OPEN.
// if it is alredy closed then we need to do a reopen of region
List<RegionInfo> toAssign = new ArrayList<>();
for (RegionInfo rinfo : regionsToMerge) {
RegionStateNode regionStateNode =
env.getAssignmentManager().getRegionStates().getRegionStateNode(rinfo);
if (regionStateNode.getState() != State.MERGING) {
// same as before HBASE-28405
toAssign.add(rinfo);
}
}
AssignmentManagerUtil.reopenRegionsForRollback(env, toAssign, getRegionReplication(env),
getServerName(env));
}

private TransitRegionStateProcedure[] createUnassignProcedures(MasterProcedureEnv env)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Coprocessor;
import org.apache.hadoop.hbase.CoprocessorEnvironment;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
Expand All @@ -52,7 +53,6 @@
import org.apache.hadoop.hbase.client.CompactionState;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.DoNotRetryRegionException;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.RegionLocator;
import org.apache.hadoop.hbase.client.Table;
Expand Down Expand Up @@ -405,7 +405,7 @@ public boolean evaluate() throws Exception {
try {
ADMIN.split(tableTwo, Bytes.toBytes("6"));
fail();
} catch (DoNotRetryRegionException e) {
} catch (DoNotRetryIOException e) {
// Expected
}
Thread.sleep(2000);
Expand Down

0 comments on commit 1994b26

Please sign in to comment.