1 /** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 package org.apache.hadoop.hbase; 20 21 import java.io.InterruptedIOException; 22 import java.util.Set; 23 24 import org.apache.hadoop.hbase.classification.InterfaceAudience; 25 import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; 26 27 /** 28 * Helper class for table state management for operations running inside 29 * RegionServer or HMaster. 30 * Depending on implementation, fetches information from HBase system table, 31 * local data store, ZooKeeper ensemble or somewhere else. 32 * Code running on client side (with no coordinated state context) shall instead use 33 * {@link org.apache.hadoop.hbase.zookeeper.ZKTableStateClientSideReader} 34 */ 35 @InterfaceAudience.Private 36 public interface TableStateManager { 37 38 /** 39 * Sets the table into desired state. Fails silently if the table is already in this state. 40 * @param tableName table to process 41 * @param state new state of this table 42 * @throws CoordinatedStateException if error happened when trying to set table state 43 */ 44 void setTableState(TableName tableName, ZooKeeperProtos.Table.State state) 45 throws CoordinatedStateException; 46 47 /** 48 * Sets the specified table into the newState, but only if the table is already in 49 * one of the possibleCurrentStates (otherwise no operation is performed). 50 * @param tableName table to process 51 * @param newState new state for the table 52 * @param states table should be in one of these states for the operation 53 * to be performed 54 * @throws CoordinatedStateException if error happened while performing operation 55 * @return true if operation succeeded, false otherwise 56 */ 57 boolean setTableStateIfInStates(TableName tableName, ZooKeeperProtos.Table.State newState, 58 ZooKeeperProtos.Table.State... states) 59 throws CoordinatedStateException; 60 61 /** 62 * Sets the specified table into the newState, but only if the table is NOT in 63 * one of the possibleCurrentStates (otherwise no operation is performed). 64 * @param tableName table to process 65 * @param newState new state for the table 66 * @param states table should NOT be in one of these states for the operation 67 * to be performed 68 * @throws CoordinatedStateException if error happened while performing operation 69 * @return true if operation succeeded, false otherwise 70 */ 71 boolean setTableStateIfNotInStates(TableName tableName, ZooKeeperProtos.Table.State newState, 72 ZooKeeperProtos.Table.State... states) 73 throws CoordinatedStateException; 74 75 /** 76 * @return true if the table is in any one of the listed states, false otherwise. 77 */ 78 boolean isTableState(TableName tableName, ZooKeeperProtos.Table.State... states); 79 80 /** 81 * @return true if the table is in any one of the listed states, false otherwise. 82 */ 83 boolean isTableState(TableName tableName, boolean checkSource, 84 ZooKeeperProtos.Table.State... states); 85 86 /** 87 * Mark table as deleted. Fails silently if the table is not currently marked as disabled. 88 * @param tableName table to be deleted 89 * @throws CoordinatedStateException if error happened while performing operation 90 */ 91 void setDeletedTable(TableName tableName) throws CoordinatedStateException; 92 93 /** 94 * Checks if table is present. 95 * 96 * @param tableName table we're checking 97 * @return true if the table is present, false otherwise 98 */ 99 boolean isTablePresent(TableName tableName); 100 101 /** 102 * @return set of tables which are in any one of the listed states, empty Set if none 103 */ 104 Set<TableName> getTablesInStates(ZooKeeperProtos.Table.State... states) 105 throws InterruptedIOException, CoordinatedStateException; 106 107 /** 108 * If the table is found in the given state the in-memory state is removed. This 109 * helps in cases where CreateTable is to be retried by the client in case of 110 * failures. If deletePermanentState is true - the flag kept permanently is 111 * also reset. 112 * 113 * @param tableName table we're working on 114 * @param states if table isn't in any one of these states, operation aborts 115 * @param deletePermanentState if true, reset the permanent flag 116 * @throws CoordinatedStateException if error happened in underlying coordination engine 117 */ 118 void checkAndRemoveTableState(TableName tableName, ZooKeeperProtos.Table.State states, 119 boolean deletePermanentState) 120 throws CoordinatedStateException; 121 }