001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.master.procedure; 019 020import java.io.IOException; 021import java.util.function.Consumer; 022import org.apache.hadoop.hbase.TableName; 023import org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure; 024import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer; 025import org.apache.yetus.audience.InterfaceAudience; 026 027import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; 028import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.CloseTableRegionsProcedureState; 029import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.CloseTableRegionsProcedureStateData; 030 031/** 032 * Procedure for closing all regions for a table. 033 */ 034@InterfaceAudience.Private 035public class CloseTableRegionsProcedure 036 extends AbstractCloseTableRegionsProcedure<CloseTableRegionsProcedureState> { 037 038 public CloseTableRegionsProcedure() { 039 } 040 041 public CloseTableRegionsProcedure(TableName tableName) { 042 super(tableName); 043 } 044 045 @Override 046 protected int submitUnassignProcedure(MasterProcedureEnv env, 047 Consumer<TransitRegionStateProcedure> submit) { 048 return env.getAssignmentManager().submitUnassignProcedureForDisablingTable(tableName, submit); 049 } 050 051 @Override 052 protected int numberOfUnclosedRegions(MasterProcedureEnv env) { 053 return env.getAssignmentManager().numberOfUnclosedRegionsForDisabling(tableName); 054 } 055 056 @Override 057 protected CloseTableRegionsProcedureState getState(int stateId) { 058 return CloseTableRegionsProcedureState.forNumber(stateId); 059 } 060 061 @Override 062 protected int getStateId(CloseTableRegionsProcedureState state) { 063 return state.getNumber(); 064 } 065 066 @Override 067 protected CloseTableRegionsProcedureState getInitialState() { 068 return CloseTableRegionsProcedureState.CLOSE_TABLE_REGIONS_SCHEDULE; 069 } 070 071 @Override 072 protected CloseTableRegionsProcedureState getConfirmState() { 073 return CloseTableRegionsProcedureState.CLOSE_TABLE_REGIONS_CONFIRM; 074 } 075 076 @Override 077 protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException { 078 super.serializeStateData(serializer); 079 CloseTableRegionsProcedureStateData data = CloseTableRegionsProcedureStateData.newBuilder() 080 .setTableName(ProtobufUtil.toProtoTableName(tableName)).build(); 081 serializer.serialize(data); 082 } 083 084 @Override 085 protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException { 086 super.deserializeStateData(serializer); 087 CloseTableRegionsProcedureStateData data = 088 serializer.deserialize(CloseTableRegionsProcedureStateData.class); 089 tableName = ProtobufUtil.toTableName(data.getTableName()); 090 } 091}