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.client;
019
020import java.io.Closeable;
021import java.io.IOException;
022import java.util.List;
023
024import org.apache.hadoop.hbase.Abortable;
025import org.apache.hadoop.hbase.HBaseInterfaceAudience;
026import org.apache.yetus.audience.InterfaceAudience;
027
028import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;
029
030/**
031 * Hbck APIs for HBase. Obtain an instance from {@link ClusterConnection#getHbck()} and call
032 * {@link #close()} when done.
033 * <p>WARNING: the below methods can damage the cluster. It may leave the cluster in an
034 * indeterminate state, e.g. region not assigned, or some hdfs files left behind. After running
035 * any of the below, operators may have to do some clean up on hdfs or schedule some assign
036 * procedures to get regions back online. DO AT YOUR OWN RISK. For experienced users only.
037 *
038 * @see ConnectionFactory
039 * @see ClusterConnection
040 * @since 2.0.2, 2.1.1
041 */
042@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.HBCK)
043public interface Hbck extends Abortable, Closeable {
044  /**
045   * Update table state in Meta only. No procedures are submitted to open/ assign or close/
046   * unassign regions of the table. This is useful only when some procedures/ actions are stuck
047   * beause of inconsistency between region and table states.
048   *
049   * NOTE: This is a dangerous action, as existing running procedures for the table or regions
050   * which belong to the table may get confused.
051   *
052   * @param state table state
053   * @return previous state of the table in Meta
054   */
055  TableState setTableStateInMeta(TableState state) throws IOException;
056
057  /**
058   * Like {@link Admin#assign(byte[])} but 'raw' in that it can do more than one Region at a time
059   * -- good if many Regions to online -- and it will schedule the assigns even in the case where
060   * Master is initializing (as long as the ProcedureExecutor is up). Does NOT call Coprocessor
061   * hooks.
062   * @param override You need to add the override for case where a region has previously been
063   *              bypassed. When a Procedure has been bypassed, a Procedure will have completed
064   *              but no other Procedure will be able to make progress on the target entity
065   *              (intentionally). This override flag will override this fencing mechanism.
066   * @param encodedRegionNames Region encoded names; e.g. 1588230740 is the hard-coded encoding
067   *                           for hbase:meta region and de00010733901a05f5a2a3a382e27dd4 is an
068   *                           example of what a random user-space encoded Region name looks like.
069   */
070  List<Long> assigns(List<String> encodedRegionNames, boolean override) throws IOException;
071
072  default List<Long> assigns(List<String> encodedRegionNames) throws IOException {
073    return assigns(encodedRegionNames, false);
074  }
075
076  /**
077   * Like {@link Admin#unassign(byte[], boolean)} but 'raw' in that it can do more than one Region
078   * at a time -- good if many Regions to offline -- and it will schedule the assigns even in the
079   * case where Master is initializing (as long as the ProcedureExecutor is up). Does NOT call
080   * Coprocessor hooks.
081   * @param override You need to add the override for case where a region has previously been
082   *              bypassed. When a Procedure has been bypassed, a Procedure will have completed
083   *              but no other Procedure will be able to make progress on the target entity
084   *              (intentionally). This override flag will override this fencing mechanism.
085   * @param encodedRegionNames Region encoded names; e.g. 1588230740 is the hard-coded encoding
086   *                           for hbase:meta region and de00010733901a05f5a2a3a382e27dd4 is an
087   *                           example of what a random user-space encoded Region name looks like.
088   */
089  List<Long> unassigns(List<String> encodedRegionNames, boolean override) throws IOException;
090
091  default List<Long> unassigns(List<String> encodedRegionNames) throws IOException {
092    return unassigns(encodedRegionNames, false);
093  }
094
095  /**
096   * Bypass specified procedure and move it to completion. Procedure is marked completed but
097   * no actual work is done from the current state/step onwards. Parents of the procedure are
098   * also marked for bypass.
099   *
100   * @param pids of procedures to complete.
101   * @param waitTime wait time in ms for acquiring lock for a procedure
102   * @param override if override set to true, we will bypass the procedure even if it is executing.
103   *   This is for procedures which can't break out during execution (bugs?).
104   * @param recursive If set, if a parent procedure, we will find and bypass children and then
105   *   the parent procedure (Dangerous but useful in case where child procedure has been 'lost').
106   *   Does not always work. Experimental.
107   * @return true if procedure is marked for bypass successfully, false otherwise
108   */
109  List<Boolean> bypassProcedure(List<Long> pids, long waitTime, boolean override, boolean recursive)
110      throws IOException;
111
112  List<Long> scheduleServerCrashProcedure(List<HBaseProtos.ServerName> serverNames)
113      throws IOException;
114
115  /**
116   * Request HBCK chore to run at master side.
117   *
118   * @return <code>true</code> if HBCK chore ran, <code>false</code> if HBCK chore already running
119   * @throws IOException if a remote or network exception occurs
120   */
121  boolean runHbckChore() throws IOException;
122
123  /**
124   * Fix Meta.
125   */
126  void fixMeta() throws IOException;
127}