Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 02FF7200CE6 for ; Tue, 1 Aug 2017 17:07:51 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 014AC167432; Tue, 1 Aug 2017 15:07:51 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id AAA9C167413 for ; Tue, 1 Aug 2017 17:07:49 +0200 (CEST) Received: (qmail 95222 invoked by uid 500); 1 Aug 2017 15:07:47 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 93541 invoked by uid 99); 1 Aug 2017 15:07:46 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Aug 2017 15:07:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 4632DF3330; Tue, 1 Aug 2017 15:07:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: git-site-role@apache.org To: commits@hbase.apache.org Date: Tue, 01 Aug 2017 15:07:54 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [12/43] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd. archived-at: Tue, 01 Aug 2017 15:07:51 -0000 http://git-wip-us.apache.org/repos/asf/hbase-site/blob/110df817/devapidocs/src-html/org/apache/hadoop/hbase/master/procedure/RecoverMetaProcedure.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/master/procedure/RecoverMetaProcedure.html b/devapidocs/src-html/org/apache/hadoop/hbase/master/procedure/RecoverMetaProcedure.html new file mode 100644 index 0000000..cabadda --- /dev/null +++ b/devapidocs/src-html/org/apache/hadoop/hbase/master/procedure/RecoverMetaProcedure.html @@ -0,0 +1,325 @@ + + + +Source code + + + +
+
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 */
+018
+019package org.apache.hadoop.hbase.master.procedure;
+020
+021import com.google.common.base.Preconditions;
+022import org.apache.commons.logging.Log;
+023import org.apache.commons.logging.LogFactory;
+024import org.apache.hadoop.hbase.HRegionInfo;
+025import org.apache.hadoop.hbase.ServerName;
+026import org.apache.hadoop.hbase.TableName;
+027import org.apache.hadoop.hbase.client.RegionReplicaUtil;
+028import org.apache.hadoop.hbase.master.HMaster;
+029import org.apache.hadoop.hbase.master.assignment.AssignProcedure;
+030import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;
+031import org.apache.hadoop.hbase.procedure2.ProcedureYieldException;
+032import org.apache.hadoop.hbase.procedure2.StateMachineProcedure;
+033import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
+034import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos;
+035import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RecoverMetaState;
+036import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
+037import org.apache.zookeeper.KeeperException;
+038
+039import java.io.IOException;
+040import java.io.InputStream;
+041import java.io.OutputStream;
+042import java.util.Set;
+043
+044/**
+045 * This procedure recovers meta from prior shutdown/ crash of a server, and brings meta online by
+046 * assigning meta region/s. Any place where meta is accessed and requires meta to be online, need to
+047 * submit this procedure instead of duplicating steps to recover meta in the code.
+048 */
+049public class RecoverMetaProcedure
+050    extends StateMachineProcedure<MasterProcedureEnv, MasterProcedureProtos.RecoverMetaState>
+051    implements TableProcedureInterface {
+052  private static final Log LOG = LogFactory.getLog(RecoverMetaProcedure.class);
+053
+054  private ServerName failedMetaServer;
+055  private boolean shouldSplitWal;
+056  private int replicaId;
+057
+058  private final ProcedurePrepareLatch syncLatch;
+059  private HMaster master;
+060
+061  /**
+062   * Call this constructor to queue up a {@link RecoverMetaProcedure} in response to meta
+063   * carrying server crash
+064   * @param failedMetaServer failed/ crashed region server that was carrying meta
+065   * @param shouldSplitLog split log file of meta region
+066   */
+067  public RecoverMetaProcedure(final ServerName failedMetaServer, final boolean shouldSplitLog) {
+068    this(failedMetaServer, shouldSplitLog, null);
+069  }
+070
+071  /**
+072   * Constructor with latch, for blocking/ sync usage
+073   */
+074  public RecoverMetaProcedure(final ServerName failedMetaServer, final boolean shouldSplitLog,
+075                              final ProcedurePrepareLatch latch) {
+076    this.failedMetaServer = failedMetaServer;
+077    this.shouldSplitWal = shouldSplitLog;
+078    this.replicaId = HRegionInfo.DEFAULT_REPLICA_ID;
+079    this.syncLatch = latch;
+080  }
+081
+082  /**
+083   * This constructor is also used when deserializing from a procedure store; we'll construct one
+084   * of these then call {@link #deserializeStateData(InputStream)}. Do not use directly.
+085   */
+086  public RecoverMetaProcedure() {
+087    this(null, false);
+088  }
+089
+090  @Override
+091  protected Flow executeFromState(MasterProcedureEnv env,
+092      MasterProcedureProtos.RecoverMetaState state)
+093      throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException {
+094    prepare(env);
+095
+096    if (!isRunRequired()) {
+097      LOG.info(this + "; Meta already initialized. Skipping run");
+098      return Flow.NO_MORE_STATE;
+099    }
+100
+101    try {
+102      switch (state) {
+103        case RECOVER_META_SPLIT_LOGS:
+104          LOG.info("Start " + this);
+105          if (shouldSplitWal) {
+106            // TODO: Matteo. We BLOCK here but most important thing to be doing at this moment.
+107            if (failedMetaServer != null) {
+108              master.getMasterWalManager().splitMetaLog(failedMetaServer);
+109            } else {
+110              ServerName serverName =
+111                  master.getMetaTableLocator().getMetaRegionLocation(master.getZooKeeper());
+112              Set<ServerName> previouslyFailedServers =
+113                  master.getMasterWalManager().getFailedServersFromLogFolders();
+114              if (serverName != null && previouslyFailedServers.contains(serverName)) {
+115                master.getMasterWalManager().splitMetaLog(serverName);
+116              }
+117            }
+118          }
+119          setNextState(RecoverMetaState.RECOVER_META_ASSIGN_REGIONS);
+120          break;
+121
+122        case RECOVER_META_ASSIGN_REGIONS:
+123          HRegionInfo hri = RegionReplicaUtil.getRegionInfoForReplica(
+124              HRegionInfo.FIRST_META_REGIONINFO, this.replicaId);
+125
+126          AssignProcedure metaAssignProcedure;
+127          if (failedMetaServer != null) {
+128            LOG.info(this + "; Assigning meta with new plan. previous meta server=" +
+129                failedMetaServer);
+130            metaAssignProcedure = master.getAssignmentManager().createAssignProcedure(hri, true);
+131          } else {
+132            // get server carrying meta from zk
+133            ServerName metaServer =
+134                MetaTableLocator.getMetaRegionState(master.getZooKeeper()).getServerName();
+135            LOG.info(this + "; Retaining meta assignment to server=" + metaServer);
+136            metaAssignProcedure =
+137                master.getAssignmentManager().createAssignProcedure(hri, metaServer);
+138          }
+139
+140          addChildProcedure(metaAssignProcedure);
+141          return Flow.NO_MORE_STATE;
+142
+143        default:
+144          throw new UnsupportedOperationException("unhandled state=" + state);
+145      }
+146    } catch (IOException|KeeperException e) {
+147      LOG.warn(this + "; Failed state=" + state + ", retry " + this + "; cycles=" +
+148          getCycles(), e);
+149    }
+150    return Flow.HAS_MORE_STATE;
+151  }
+152
+153  @Override
+154  protected void rollbackState(MasterProcedureEnv env,
+155      MasterProcedureProtos.RecoverMetaState recoverMetaState)
+156      throws IOException, InterruptedException {
+157    // Can't rollback
+158    throw new UnsupportedOperationException("unhandled state=" + recoverMetaState);
+159  }
+160
+161  @Override
+162  protected MasterProcedureProtos.RecoverMetaState getState(int stateId) {
+163    return RecoverMetaState.forNumber(stateId);
+164  }
+165
+166  @Override
+167  protected int getStateId(MasterProcedureProtos.RecoverMetaState recoverMetaState) {
+168    return recoverMetaState.getNumber();
+169  }
+170
+171  @Override
+172  protected MasterProcedureProtos.RecoverMetaState getInitialState() {
+173    return RecoverMetaState.RECOVER_META_SPLIT_LOGS;
+174  }
+175
+176  @Override
+177  protected void toStringClassDetails(StringBuilder sb) {
+178    sb.append(getClass().getSimpleName());
+179    sb.append(" failedMetaServer=");
+180    sb.append(failedMetaServer);
+181    sb.append(", splitWal=");
+182    sb.append(shouldSplitWal);
+183  }
+184
+185  @Override
+186  protected void serializeStateData(OutputStream stream) throws IOException {
+187    super.serializeStateData(stream);
+188    MasterProcedureProtos.RecoverMetaStateData.Builder state =
+189        MasterProcedureProtos.RecoverMetaStateData.newBuilder().setShouldSplitWal(shouldSplitWal);
+190    if (failedMetaServer != null) {
+191      state.setFailedMetaServer(ProtobufUtil.toServerName(failedMetaServer));
+192    }
+193    state.setReplicaId(replicaId);
+194    state.build().writeDelimitedTo(stream);
+195  }
+196
+197  @Override
+198  protected void deserializeStateData(InputStream stream) throws IOException {
+199    super.deserializeStateData(stream);
+200    MasterProcedureProtos.RecoverMetaStateData state =
+201        MasterProcedureProtos.RecoverMetaStateData.parseDelimitedFrom(stream);
+202    this.shouldSplitWal = state.hasShouldSplitWal() && state.getShouldSplitWal();
+203    this.failedMetaServer = state.hasFailedMetaServer() ?
+204        ProtobufUtil.toServerName(state.getFailedMetaServer()) : null;
+205    this.replicaId = state.hasReplicaId() ? state.getReplicaId() : HRegionInfo.DEFAULT_REPLICA_ID;
+206  }
+207
+208  @Override
+209  protected LockState acquireLock(MasterProcedureEnv env) {
+210    if (env.getProcedureScheduler().waitTableExclusiveLock(this, TableName.META_TABLE_NAME)) {
+211      return LockState.LOCK_EVENT_WAIT;
+212    }
+213    return LockState.LOCK_ACQUIRED;
+214  }
+215
+216  @Override
+217  protected void releaseLock(MasterProcedureEnv env) {
+218    env.getProcedureScheduler().wakeTableExclusiveLock(this, TableName.META_TABLE_NAME);
+219  }
+220
+221  @Override
+222  protected void completionCleanup(MasterProcedureEnv env) {
+223    ProcedurePrepareLatch.releaseLatch(syncLatch, this);
+224  }
+225
+226  @Override
+227  public TableName getTableName() {
+228    return TableName.META_TABLE_NAME;
+229  }
+230
+231  @Override
+232  public TableOperationType getTableOperationType() {
+233    return TableOperationType.ENABLE;
+234  }
+235
+236  /**
+237   * @return true if failedMetaServer is not null (meta carrying server crashed) or meta is
+238   * already initialized
+239   */
+240  private boolean isRunRequired() {
+241    return failedMetaServer != null || !master.getAssignmentManager().isMetaInitialized();
+242  }
+243
+244  /**
+245   * Prepare for execution
+246   */
+247  private void prepare(MasterProcedureEnv env) {
+248    if (master == null) {
+249      master = (HMaster) env.getMasterServices();
+250      Preconditions.checkArgument(master != null);
+251    }
+252  }
+253}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +