001/** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020package org.apache.hadoop.hbase.master.assignment; 021 022import java.io.IOException; 023import java.util.Optional; 024 025import org.apache.hadoop.hbase.ServerName; 026import org.apache.hadoop.hbase.exceptions.UnexpectedStateException; 027import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; 028import org.apache.hadoop.hbase.procedure2.ProcedureMetrics; 029import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer; 030import org.apache.hadoop.hbase.procedure2.RemoteProcedureDispatcher.RemoteOperation; 031import org.apache.yetus.audience.InterfaceAudience; 032 033import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; 034import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionTransitionState; 035import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.UnassignRegionStateData; 036import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode; 037 038/** 039 * Leave here only for checking if we can successfully start the master. 040 * @deprecated Do not use any more. 041 * @see TransitRegionStateProcedure 042 */ 043@Deprecated 044@InterfaceAudience.Private 045public class UnassignProcedure extends RegionTransitionProcedure { 046 047 protected volatile ServerName hostingServer; 048 049 protected volatile ServerName destinationServer; 050 051 private boolean force; 052 053 private boolean removeAfterUnassigning; 054 055 public UnassignProcedure() { 056 } 057 058 @Override 059 public TableOperationType getTableOperationType() { 060 return TableOperationType.REGION_UNASSIGN; 061 } 062 063 @Override 064 protected boolean isRollbackSupported(final RegionTransitionState state) { 065 switch (state) { 066 case REGION_TRANSITION_QUEUE: 067 case REGION_TRANSITION_DISPATCH: 068 return true; 069 default: 070 return false; 071 } 072 } 073 074 @Override 075 protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException { 076 UnassignRegionStateData.Builder state = 077 UnassignRegionStateData.newBuilder().setTransitionState(getTransitionState()) 078 .setHostingServer(ProtobufUtil.toServerName(this.hostingServer)) 079 .setRegionInfo(ProtobufUtil.toRegionInfo(getRegionInfo())); 080 if (this.destinationServer != null) { 081 state.setDestinationServer(ProtobufUtil.toServerName(destinationServer)); 082 } 083 if (force) { 084 state.setForce(true); 085 } 086 if (removeAfterUnassigning) { 087 state.setRemoveAfterUnassigning(true); 088 } 089 if (getAttempt() > 0) { 090 state.setAttempt(getAttempt()); 091 } 092 serializer.serialize(state.build()); 093 } 094 095 @Override 096 protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException { 097 final UnassignRegionStateData state = serializer.deserialize(UnassignRegionStateData.class); 098 setTransitionState(state.getTransitionState()); 099 setRegionInfo(ProtobufUtil.toRegionInfo(state.getRegionInfo())); 100 this.hostingServer = ProtobufUtil.toServerName(state.getHostingServer()); 101 force = state.getForce(); 102 if (state.hasDestinationServer()) { 103 this.destinationServer = ProtobufUtil.toServerName(state.getDestinationServer()); 104 } 105 removeAfterUnassigning = state.getRemoveAfterUnassigning(); 106 if (state.hasAttempt()) { 107 setAttempt(state.getAttempt()); 108 } 109 } 110 111 @Override 112 protected boolean startTransition(final MasterProcedureEnv env, 113 final RegionStateNode regionNode) { 114 // nothing to do here. we skip the step in the constructor 115 // by jumping to REGION_TRANSITION_DISPATCH 116 throw new UnsupportedOperationException(); 117 } 118 119 @Override 120 protected boolean updateTransition(final MasterProcedureEnv env, final RegionStateNode regionNode) 121 throws IOException { 122 return true; 123 } 124 125 @Override 126 protected void finishTransition(final MasterProcedureEnv env, final RegionStateNode regionNode) 127 throws IOException { 128 } 129 130 @Override 131 public Optional<RemoteOperation> remoteCallBuild(final MasterProcedureEnv env, 132 final ServerName serverName) { 133 return Optional.empty(); 134 } 135 136 @Override 137 protected void reportTransition(final MasterProcedureEnv env, final RegionStateNode regionNode, 138 final TransitionCode code, final long seqId) throws UnexpectedStateException { 139 } 140 141 /** 142 * @return If true, we will re-wake up this procedure; if false, the procedure stays suspended. 143 */ 144 @Override 145 protected boolean remoteCallFailed(final MasterProcedureEnv env, final RegionStateNode regionNode, 146 final IOException exception) { 147 return true; 148 } 149 150 @Override 151 public void toStringClassDetails(StringBuilder sb) { 152 super.toStringClassDetails(sb); 153 sb.append(", server=").append(this.hostingServer); 154 } 155 156 @Override 157 protected ProcedureMetrics getProcedureMetrics(MasterProcedureEnv env) { 158 return env.getAssignmentManager().getAssignmentManagerMetrics().getUnassignProcMetrics(); 159 } 160}