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 org.apache.hadoop.hbase.ServerName;
022import org.apache.hadoop.hbase.client.RegionInfo;
023import org.apache.hadoop.hbase.master.MasterServices;
024import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
025import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;
026import org.apache.hadoop.hbase.procedure2.ProcedureYieldException;
027import org.apache.hadoop.hbase.procedure2.StateMachineProcedure;
028import org.apache.yetus.audience.InterfaceAudience;
029import org.slf4j.Logger;
030import org.slf4j.LoggerFactory;
031
032import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
033import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos;
034import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RecoverMetaState;
035
036/**
037 * Leave here only for checking if we can successfully start the master.
038 * @deprecated Do not use any more, leave it here only for compatible. The recovery work will be
039 *             done in {@link ServerCrashProcedure} directly, and the initial work for meta table
040 *             will be done by {@link InitMetaProcedure}.
041 * @see ServerCrashProcedure
042 * @see InitMetaProcedure
043 */
044@Deprecated
045@InterfaceAudience.Private
046public class RecoverMetaProcedure
047  extends StateMachineProcedure<MasterProcedureEnv, MasterProcedureProtos.RecoverMetaState>
048  implements MetaProcedureInterface {
049  private static final Logger LOG = LoggerFactory.getLogger(RecoverMetaProcedure.class);
050
051  private ServerName failedMetaServer;
052  private boolean shouldSplitWal;
053  private int replicaId;
054
055  private MasterServices master;
056
057  public RecoverMetaProcedure() {
058
059  }
060
061  @Override
062  protected Flow executeFromState(MasterProcedureEnv env,
063    MasterProcedureProtos.RecoverMetaState state)
064    throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException {
065    return Flow.NO_MORE_STATE;
066  }
067
068  @Override
069  protected void rollbackState(MasterProcedureEnv env,
070    MasterProcedureProtos.RecoverMetaState recoverMetaState)
071    throws IOException, InterruptedException {
072    // Can't rollback
073    throw new UnsupportedOperationException("unhandled state=" + recoverMetaState);
074  }
075
076  @Override
077  protected MasterProcedureProtos.RecoverMetaState getState(int stateId) {
078    return RecoverMetaState.forNumber(stateId);
079  }
080
081  @Override
082  protected int getStateId(MasterProcedureProtos.RecoverMetaState recoverMetaState) {
083    return recoverMetaState.getNumber();
084  }
085
086  @Override
087  protected MasterProcedureProtos.RecoverMetaState getInitialState() {
088    return RecoverMetaState.RECOVER_META_PREPARE;
089  }
090
091  @Override
092  protected void toStringClassDetails(StringBuilder sb) {
093    sb.append(getClass().getSimpleName());
094    sb.append(" failedMetaServer=");
095    sb.append(failedMetaServer);
096    sb.append(", splitWal=");
097    sb.append(shouldSplitWal);
098  }
099
100  @Override
101  protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException {
102    super.serializeStateData(serializer);
103    MasterProcedureProtos.RecoverMetaStateData.Builder state =
104      MasterProcedureProtos.RecoverMetaStateData.newBuilder().setShouldSplitWal(shouldSplitWal);
105    if (failedMetaServer != null) {
106      state.setFailedMetaServer(ProtobufUtil.toServerName(failedMetaServer));
107    }
108    state.setReplicaId(replicaId);
109    serializer.serialize(state.build());
110  }
111
112  @Override
113  protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException {
114    super.deserializeStateData(serializer);
115    MasterProcedureProtos.RecoverMetaStateData state =
116      serializer.deserialize(MasterProcedureProtos.RecoverMetaStateData.class);
117    this.shouldSplitWal = state.hasShouldSplitWal() && state.getShouldSplitWal();
118    this.failedMetaServer =
119      state.hasFailedMetaServer() ? ProtobufUtil.toServerName(state.getFailedMetaServer()) : null;
120    this.replicaId = state.hasReplicaId() ? state.getReplicaId() : RegionInfo.DEFAULT_REPLICA_ID;
121  }
122}