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