diff --git a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/StateMachineProcedure.java b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/StateMachineProcedure.java index 0e3a4cd6547..69ecb296f50 100644 --- a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/StateMachineProcedure.java +++ b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/StateMachineProcedure.java @@ -142,10 +142,15 @@ public abstract class StateMachineProcedure * Add a child procedure to execute * @param subProcedure the child procedure */ - protected void addChildProcedure(Procedure... subProcedure) { - if (subProcedure == null) return; + protected > void addChildProcedure( + @SuppressWarnings("unchecked") T... subProcedure) { + if (subProcedure == null) { + return; + } final int len = subProcedure.length; - if (len == 0) return; + if (len == 0) { + return; + } if (subProcList == null) { subProcList = new ArrayList<>(len); } diff --git a/hbase-protocol-shaded/src/main/protobuf/MasterProcedure.proto b/hbase-protocol-shaded/src/main/protobuf/MasterProcedure.proto index 17a81cdbfa8..b65551f50da 100644 --- a/hbase-protocol-shaded/src/main/protobuf/MasterProcedure.proto +++ b/hbase-protocol-shaded/src/main/protobuf/MasterProcedure.proto @@ -437,3 +437,11 @@ message EnablePeerStateData { message DisablePeerStateData { } + +enum ReopenTableRegionsState { + REOPEN_TABLE_REGIONS_REOPEN_ALL_REGIONS = 1; +} + +message ReopenTableRegionsStateData { + required TableName table_name = 1; +} diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ReopenTableRegionsProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ReopenTableRegionsProcedure.java new file mode 100644 index 00000000000..133d6f48a3b --- /dev/null +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ReopenTableRegionsProcedure.java @@ -0,0 +1,114 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.master.procedure; + +import java.io.IOException; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer; +import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException; +import org.apache.hadoop.hbase.procedure2.ProcedureYieldException; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; +import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.ReopenTableRegionsState; +import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.ReopenTableRegionsStateData; + +/** + * Used for non table procedures to reopen the regions for a table. For example, + * {@link org.apache.hadoop.hbase.master.replication.ModifyPeerProcedure}. + */ +@InterfaceAudience.Private +public class ReopenTableRegionsProcedure + extends AbstractStateMachineTableProcedure { + + private static final Logger LOG = LoggerFactory.getLogger(ReopenTableRegionsProcedure.class); + + private TableName tableName; + + public ReopenTableRegionsProcedure() { + } + + public ReopenTableRegionsProcedure(TableName tableName) { + this.tableName = tableName; + } + + @Override + public TableName getTableName() { + return tableName; + } + + @Override + public TableOperationType getTableOperationType() { + return TableOperationType.REGION_EDIT; + } + + @Override + protected Flow executeFromState(MasterProcedureEnv env, ReopenTableRegionsState state) + throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException { + switch (state) { + case REOPEN_TABLE_REGIONS_REOPEN_ALL_REGIONS: + try { + addChildProcedure(env.getAssignmentManager().createReopenProcedures( + env.getAssignmentManager().getRegionStates().getRegionsOfTable(tableName))); + } catch (IOException e) { + LOG.warn("Failed to schedule reopen procedures for {}", tableName, e); + throw new ProcedureSuspendedException(); + } + return Flow.NO_MORE_STATE; + default: + throw new UnsupportedOperationException("unhandled state=" + state); + } + } + + @Override + protected void rollbackState(MasterProcedureEnv env, ReopenTableRegionsState state) + throws IOException, InterruptedException { + throw new UnsupportedOperationException(); + } + + @Override + protected ReopenTableRegionsState getState(int stateId) { + return ReopenTableRegionsState.forNumber(stateId); + } + + @Override + protected int getStateId(ReopenTableRegionsState state) { + return state.getNumber(); + } + + @Override + protected ReopenTableRegionsState getInitialState() { + return ReopenTableRegionsState.REOPEN_TABLE_REGIONS_REOPEN_ALL_REGIONS; + } + + @Override + protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException { + super.serializeStateData(serializer); + serializer.serialize(ReopenTableRegionsStateData.newBuilder() + .setTableName(ProtobufUtil.toProtoTableName(tableName)).build()); + } + + @Override + protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException { + super.deserializeStateData(serializer); + tableName = ProtobufUtil + .toTableName(serializer.deserialize(ReopenTableRegionsStateData.class).getTableName()); + } +} diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ModifyPeerProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ModifyPeerProcedure.java index ea2e314d3b0..6fd8aa3b412 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ModifyPeerProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ModifyPeerProcedure.java @@ -30,6 +30,7 @@ import org.apache.hadoop.hbase.master.TableStateManager; import org.apache.hadoop.hbase.master.TableStateManager.TableStateNotFoundException; import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; import org.apache.hadoop.hbase.master.procedure.ProcedurePrepareLatch; +import org.apache.hadoop.hbase.master.procedure.ReopenTableRegionsProcedure; import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException; import org.apache.hadoop.hbase.procedure2.ProcedureYieldException; import org.apache.hadoop.hbase.replication.ReplicationException; @@ -165,8 +166,7 @@ public abstract class ModifyPeerProcedure extends AbstractPeerProcedure