HBASE-20659 Implement a reopen table regions procedure

This commit is contained in:
zhangduo 2018-05-30 15:33:29 +08:00
parent 61651fbab3
commit b785896cbd
4 changed files with 132 additions and 5 deletions

View File

@ -142,10 +142,15 @@ public abstract class StateMachineProcedure<TEnvironment, TState>
* Add a child procedure to execute
* @param subProcedure the child procedure
*/
protected void addChildProcedure(Procedure<TEnvironment>... subProcedure) {
if (subProcedure == null) return;
protected <T extends Procedure<TEnvironment>> 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);
}

View File

@ -437,3 +437,11 @@ message EnablePeerStateData {
message DisablePeerStateData {
}
enum ReopenTableRegionsState {
REOPEN_TABLE_REGIONS_REOPEN_ALL_REGIONS = 1;
}
message ReopenTableRegionsStateData {
required TableName table_name = 1;
}

View File

@ -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<ReopenTableRegionsState> {
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());
}
}

View File

@ -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<PeerModi
continue;
}
if (needReopen(tsm, tn)) {
addChildProcedure(env.getAssignmentManager().createReopenProcedures(
env.getAssignmentManager().getRegionStates().getRegionsOfTable(tn)));
addChildProcedure(new ReopenTableRegionsProcedure(tn));
}
}
}