View Javadoc

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 org.apache.hadoop.hbase.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos;
23  
24  import java.io.InterruptedIOException;
25  import java.util.Set;
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     * Mark table as deleted.  Fails silently if the table is not currently marked as disabled.
82     * @param tableName table to be deleted
83     * @throws CoordinatedStateException if error happened while performing operation
84     */
85    void setDeletedTable(TableName tableName) throws CoordinatedStateException;
86  
87    /**
88     * Checks if table is present.
89     *
90     * @param tableName table we're checking
91     * @return true if the table is present, false otherwise
92     */
93    boolean isTablePresent(TableName tableName);
94  
95    /**
96     * @return set of tables which are in any one of the listed states, empty Set if none
97     */
98    Set<TableName> getTablesInStates(ZooKeeperProtos.Table.State... states)
99      throws InterruptedIOException, CoordinatedStateException;
100 
101   /**
102    * If the table is found in the given state the in-memory state is removed. This
103    * helps in cases where CreateTable is to be retried by the client in case of
104    * failures.  If deletePermanentState is true - the flag kept permanently is
105    * also reset.
106    *
107    * @param tableName table we're working on
108    * @param states if table isn't in any one of these states, operation aborts
109    * @param deletePermanentState if true, reset the permanent flag
110    * @throws CoordinatedStateException if error happened in underlying coordination engine
111    */
112   void checkAndRemoveTableState(TableName tableName, ZooKeeperProtos.Table.State states,
113                             boolean deletePermanentState)
114     throws CoordinatedStateException;
115 }