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.assignment; 019 020import java.io.IOException; 021import java.util.Optional; 022import org.apache.hadoop.hbase.ServerName; 023import org.apache.hadoop.hbase.exceptions.UnexpectedStateException; 024import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; 025import org.apache.hadoop.hbase.procedure2.ProcedureMetrics; 026import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer; 027import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException; 028import org.apache.hadoop.hbase.procedure2.RemoteProcedureDispatcher.RemoteOperation; 029import org.apache.yetus.audience.InterfaceAudience; 030 031import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; 032import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.AssignRegionStateData; 033import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionTransitionState; 034import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode; 035 036/** 037 * Leave here only for checking if we can successfully start the master. 038 * @deprecated Do not use any more. 039 * @see TransitRegionStateProcedure 040 */ 041@Deprecated 042@InterfaceAudience.Private 043public class AssignProcedure extends RegionTransitionProcedure { 044 045 private boolean forceNewPlan = false; 046 047 protected volatile ServerName targetServer; 048 049 public AssignProcedure() { 050 } 051 052 @Override 053 public TableOperationType getTableOperationType() { 054 return TableOperationType.REGION_ASSIGN; 055 } 056 057 @Override 058 protected boolean isRollbackSupported(final RegionTransitionState state) { 059 switch (state) { 060 case REGION_TRANSITION_QUEUE: 061 return true; 062 default: 063 return false; 064 } 065 } 066 067 @Override 068 protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException { 069 final AssignRegionStateData.Builder state = 070 AssignRegionStateData.newBuilder().setTransitionState(getTransitionState()) 071 .setRegionInfo(ProtobufUtil.toRegionInfo(getRegionInfo())); 072 if (forceNewPlan) { 073 state.setForceNewPlan(true); 074 } 075 if (this.targetServer != null) { 076 state.setTargetServer(ProtobufUtil.toServerName(this.targetServer)); 077 } 078 if (getAttempt() > 0) { 079 state.setAttempt(getAttempt()); 080 } 081 serializer.serialize(state.build()); 082 } 083 084 @Override 085 protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException { 086 final AssignRegionStateData state = serializer.deserialize(AssignRegionStateData.class); 087 setTransitionState(state.getTransitionState()); 088 setRegionInfo(ProtobufUtil.toRegionInfo(state.getRegionInfo())); 089 forceNewPlan = state.getForceNewPlan(); 090 if (state.hasTargetServer()) { 091 this.targetServer = ProtobufUtil.toServerName(state.getTargetServer()); 092 } 093 if (state.hasAttempt()) { 094 setAttempt(state.getAttempt()); 095 } 096 } 097 098 @Override 099 protected boolean startTransition(final MasterProcedureEnv env, final RegionStateNode regionNode) 100 throws IOException { 101 return true; 102 } 103 104 @Override 105 protected boolean updateTransition(final MasterProcedureEnv env, final RegionStateNode regionNode) 106 throws IOException, ProcedureSuspendedException { 107 return true; 108 } 109 110 @Override 111 protected void finishTransition(final MasterProcedureEnv env, final RegionStateNode regionNode) 112 throws IOException { 113 } 114 115 @Override 116 protected void reportTransition(final MasterProcedureEnv env, final RegionStateNode regionNode, 117 final TransitionCode code, final long openSeqNum) throws UnexpectedStateException { 118 } 119 120 @Override 121 public Optional<RemoteOperation> remoteCallBuild(final MasterProcedureEnv env, 122 final ServerName serverName) { 123 return Optional.empty(); 124 } 125 126 @Override 127 protected boolean remoteCallFailed(final MasterProcedureEnv env, final RegionStateNode regionNode, 128 final IOException exception) { 129 return true; 130 } 131 132 @Override 133 public void toStringClassDetails(StringBuilder sb) { 134 super.toStringClassDetails(sb); 135 if (this.targetServer != null) sb.append(", target=").append(this.targetServer); 136 } 137 138 @Override 139 protected ProcedureMetrics getProcedureMetrics(MasterProcedureEnv env) { 140 return env.getAssignmentManager().getAssignmentManagerMetrics().getAssignProcMetrics(); 141 } 142 143 @Override 144 public void setProcId(long procId) { 145 super.setProcId(procId); 146 } 147}