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.client;
20  
21  import java.io.Closeable;
22  import java.io.IOException;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.concurrent.Future;
26  import java.util.regex.Pattern;
27  
28  import org.apache.hadoop.conf.Configuration;
29  import org.apache.hadoop.hbase.Abortable;
30  import org.apache.hadoop.hbase.ClusterStatus;
31  import org.apache.hadoop.hbase.HColumnDescriptor;
32  import org.apache.hadoop.hbase.HRegionInfo;
33  import org.apache.hadoop.hbase.HTableDescriptor;
34  import org.apache.hadoop.hbase.NamespaceDescriptor;
35  import org.apache.hadoop.hbase.ProcedureInfo;
36  import org.apache.hadoop.hbase.ServerName;
37  import org.apache.hadoop.hbase.TableExistsException;
38  import org.apache.hadoop.hbase.TableName;
39  import org.apache.hadoop.hbase.TableNotFoundException;
40  import org.apache.hadoop.hbase.backup.BackupRequest;
41  import org.apache.hadoop.hbase.backup.BackupType;
42  import org.apache.hadoop.hbase.classification.InterfaceAudience;
43  import org.apache.hadoop.hbase.classification.InterfaceStability;
44  import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel;
45  import org.apache.hadoop.hbase.protobuf.generated.AdminProtos;
46  import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
47  import org.apache.hadoop.hbase.protobuf.generated.MasterProtos;
48  import org.apache.hadoop.hbase.quotas.QuotaFilter;
49  import org.apache.hadoop.hbase.quotas.QuotaRetriever;
50  import org.apache.hadoop.hbase.quotas.QuotaSettings;
51  import org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException;
52  import org.apache.hadoop.hbase.snapshot.HBaseSnapshotException;
53  import org.apache.hadoop.hbase.snapshot.RestoreSnapshotException;
54  import org.apache.hadoop.hbase.snapshot.SnapshotCreationException;
55  import org.apache.hadoop.hbase.snapshot.UnknownSnapshotException;
56  import org.apache.hadoop.hbase.util.Pair;
57  
58  /**
59   * The administrative API for HBase. Obtain an instance from an {@link Connection#getAdmin()} and
60   * call {@link #close()} afterwards.
61   * <p>Admin can be used to create, drop, list, enable and disable tables, add and drop table
62   * column families and other administrative operations.
63   *
64   * @see ConnectionFactory
65   * @see Connection
66   * @see Table
67   * @since 0.99.0
68   */
69  @InterfaceAudience.Public
70  @InterfaceStability.Evolving
71  public interface Admin extends Abortable, Closeable {
72    int getOperationTimeout();
73  
74    @Override
75    void abort(String why, Throwable e);
76  
77    @Override
78    boolean isAborted();
79  
80    /**
81     * @return Connection used by this object.
82     */
83    Connection getConnection();
84  
85    /**
86     * @param tableName Table to check.
87     * @return True if table exists already.
88     * @throws IOException
89     */
90    boolean tableExists(final TableName tableName) throws IOException;
91  
92    /**
93     * List all the userspace tables.
94     *
95     * @return - returns an array of HTableDescriptors
96     * @throws IOException if a remote or network exception occurs
97     */
98    HTableDescriptor[] listTables() throws IOException;
99  
100   /**
101    * List all the userspace tables matching the given pattern.
102    *
103    * @param pattern The compiled regular expression to match against
104    * @return - returns an array of HTableDescriptors
105    * @throws IOException if a remote or network exception occurs
106    * @see #listTables()
107    */
108   HTableDescriptor[] listTables(Pattern pattern) throws IOException;
109 
110   /**
111    * List all the userspace tables matching the given regular expression.
112    *
113    * @param regex The regular expression to match against
114    * @return - returns an array of HTableDescriptors
115    * @throws IOException if a remote or network exception occurs
116    * @see #listTables(java.util.regex.Pattern)
117    */
118   HTableDescriptor[] listTables(String regex) throws IOException;
119 
120   /**
121    * List all the tables matching the given pattern.
122    *
123    * @param pattern The compiled regular expression to match against
124    * @param includeSysTables False to match only against userspace tables
125    * @return - returns an array of HTableDescriptors
126    * @throws IOException if a remote or network exception occurs
127    * @see #listTables()
128    */
129   HTableDescriptor[] listTables(Pattern pattern, boolean includeSysTables)
130       throws IOException;
131 
132   /**
133    * List all the tables matching the given pattern.
134    *
135    * @param regex The regular expression to match against
136    * @param includeSysTables False to match only against userspace tables
137    * @return - returns an array of HTableDescriptors
138    * @throws IOException if a remote or network exception occurs
139    * @see #listTables(java.util.regex.Pattern, boolean)
140    */
141   HTableDescriptor[] listTables(String regex, boolean includeSysTables)
142       throws IOException;
143 
144   /**
145    * List all of the names of userspace tables.
146    *
147    * @return TableName[] table names
148    * @throws IOException if a remote or network exception occurs
149    */
150   TableName[] listTableNames() throws IOException;
151 
152   /**
153    * List all of the names of userspace tables.
154    * @param pattern The regular expression to match against
155    * @return TableName[] table names
156    * @throws IOException if a remote or network exception occurs
157    */
158   TableName[] listTableNames(Pattern pattern) throws IOException;
159 
160   /**
161    * List all of the names of userspace tables.
162    * @param regex The regular expression to match against
163    * @return TableName[] table names
164    * @throws IOException if a remote or network exception occurs
165    */
166   TableName[] listTableNames(String regex) throws IOException;
167 
168   /**
169    * List all of the names of userspace tables.
170    * @param pattern The regular expression to match against
171    * @param includeSysTables False to match only against userspace tables
172    * @return TableName[] table names
173    * @throws IOException if a remote or network exception occurs
174    */
175   TableName[] listTableNames(final Pattern pattern, final boolean includeSysTables)
176       throws IOException;
177 
178   /**
179    * List all of the names of userspace tables.
180    * @param regex The regular expression to match against
181    * @param includeSysTables False to match only against userspace tables
182    * @return TableName[] table names
183    * @throws IOException if a remote or network exception occurs
184    */
185   TableName[] listTableNames(final String regex, final boolean includeSysTables)
186       throws IOException;
187 
188   /**
189    * Method for getting the tableDescriptor
190    *
191    * @param tableName as a {@link TableName}
192    * @return the tableDescriptor
193    * @throws org.apache.hadoop.hbase.TableNotFoundException
194    * @throws IOException if a remote or network exception occurs
195    */
196   HTableDescriptor getTableDescriptor(final TableName tableName)
197       throws TableNotFoundException, IOException;
198 
199   /**
200    * Creates a new table. Synchronous operation.
201    *
202    * @param desc table descriptor for table
203    * @throws IllegalArgumentException if the table name is reserved
204    * @throws MasterNotRunningException if master is not running
205    * @throws org.apache.hadoop.hbase.TableExistsException if table already exists (If concurrent
206    * threads, the table may have been created between test-for-existence and attempt-at-creation).
207    * @throws IOException if a remote or network exception occurs
208    */
209   void createTable(HTableDescriptor desc) throws IOException;
210 
211   /**
212    * Creates a new table with the specified number of regions.  The start key specified will become
213    * the end key of the first region of the table, and the end key specified will become the start
214    * key of the last region of the table (the first region has a null start key and the last region
215    * has a null end key). BigInteger math will be used to divide the key range specified into enough
216    * segments to make the required number of total regions. Synchronous operation.
217    *
218    * @param desc table descriptor for table
219    * @param startKey beginning of key range
220    * @param endKey end of key range
221    * @param numRegions the total number of regions to create
222    * @throws IllegalArgumentException if the table name is reserved
223    * @throws MasterNotRunningException if master is not running
224    * @throws org.apache.hadoop.hbase.TableExistsException if table already exists (If concurrent
225    * threads, the table may have been created between test-for-existence and attempt-at-creation).
226    * @throws IOException
227    */
228   void createTable(HTableDescriptor desc, byte[] startKey, byte[] endKey, int numRegions)
229       throws IOException;
230 
231   /**
232    * Creates a new table with an initial set of empty regions defined by the specified split keys.
233    * The total number of regions created will be the number of split keys plus one. Synchronous
234    * operation. Note : Avoid passing empty split key.
235    *
236    * @param desc table descriptor for table
237    * @param splitKeys array of split keys for the initial regions of the table
238    * @throws IllegalArgumentException if the table name is reserved, if the split keys are repeated
239    * and if the split key has empty byte array.
240    * @throws MasterNotRunningException if master is not running
241    * @throws org.apache.hadoop.hbase.TableExistsException if table already exists (If concurrent
242    * threads, the table may have been created between test-for-existence and attempt-at-creation).
243    * @throws IOException
244    */
245   void createTable(final HTableDescriptor desc, byte[][] splitKeys) throws IOException;
246 
247   /**
248    * Creates a new table but does not block and wait for it to come online. Asynchronous operation.
249    * To check if the table exists, use {@link #isTableAvailable} -- it is not safe to create an
250    * HTable instance to this table before it is available. Note : Avoid passing empty split key.
251    *
252    * @param desc table descriptor for table
253    * @throws IllegalArgumentException Bad table name, if the split keys are repeated and if the
254    * split key has empty byte array.
255    * @throws MasterNotRunningException if master is not running
256    * @throws org.apache.hadoop.hbase.TableExistsException if table already exists (If concurrent
257    * threads, the table may have been created between test-for-existence and attempt-at-creation).
258    * @throws IOException
259    */
260   void createTableAsync(final HTableDescriptor desc, final byte[][] splitKeys) throws IOException;
261 
262   /**
263    * Deletes a table. Synchronous operation.
264    *
265    * @param tableName name of table to delete
266    * @throws IOException if a remote or network exception occurs
267    */
268   void deleteTable(final TableName tableName) throws IOException;
269 
270   /**
271    * Deletes tables matching the passed in pattern and wait on completion. Warning: Use this method
272    * carefully, there is no prompting and the effect is immediate. Consider using {@link
273    * #listTables(java.lang.String)} and {@link #deleteTable(org.apache.hadoop.hbase.TableName)}
274    *
275    * @param regex The regular expression to match table names against
276    * @return Table descriptors for tables that couldn't be deleted
277    * @throws IOException
278    * @see #deleteTables(java.util.regex.Pattern)
279    * @see #deleteTable(org.apache.hadoop.hbase.TableName)
280    */
281   HTableDescriptor[] deleteTables(String regex) throws IOException;
282 
283   /**
284    * Delete tables matching the passed in pattern and wait on completion. Warning: Use this method
285    * carefully, there is no prompting and the effect is immediate. Consider using {@link
286    * #listTables(java.util.regex.Pattern) } and
287    * {@link #deleteTable(org.apache.hadoop.hbase.TableName)}
288    *
289    * @param pattern The pattern to match table names against
290    * @return Table descriptors for tables that couldn't be deleted
291    * @throws IOException
292    */
293   HTableDescriptor[] deleteTables(Pattern pattern) throws IOException;
294 
295   /**
296    * Truncate a table.
297    * Synchronous operation.
298    *
299    * @param tableName name of table to truncate
300    * @param preserveSplits True if the splits should be preserved
301    * @throws IOException if a remote or network exception occurs
302    */
303   public void truncateTable(final TableName tableName, final boolean preserveSplits)
304       throws IOException;
305 
306   /**
307    * Enable a table.  May timeout.  Use {@link #enableTableAsync(org.apache.hadoop.hbase.TableName)}
308    * and {@link #isTableEnabled(org.apache.hadoop.hbase.TableName)} instead. The table has to be in
309    * disabled state for it to be enabled.
310    *
311    * @param tableName name of the table
312    * @throws IOException if a remote or network exception occurs There could be couple types of
313    * IOException TableNotFoundException means the table doesn't exist. TableNotDisabledException
314    * means the table isn't in disabled state.
315    * @see #isTableEnabled(org.apache.hadoop.hbase.TableName)
316    * @see #disableTable(org.apache.hadoop.hbase.TableName)
317    * @see #enableTableAsync(org.apache.hadoop.hbase.TableName)
318    */
319   void enableTable(final TableName tableName) throws IOException;
320 
321   /**
322    * Brings a table on-line (enables it).  Method returns immediately though enable of table may
323    * take some time to complete, especially if the table is large (All regions are opened as part of
324    * enabling process).  Check {@link #isTableEnabled(org.apache.hadoop.hbase.TableName)} to learn
325    * when table is fully online.  If table is taking too long to online, check server logs.
326    *
327    * @param tableName
328    * @throws IOException
329    * @since 0.90.0
330    */
331   void enableTableAsync(final TableName tableName) throws IOException;
332 
333   /**
334    * Enable tables matching the passed in pattern and wait on completion. Warning: Use this method
335    * carefully, there is no prompting and the effect is immediate. Consider using {@link
336    * #listTables(java.lang.String)} and {@link #enableTable(org.apache.hadoop.hbase.TableName)}
337    *
338    * @param regex The regular expression to match table names against
339    * @throws IOException
340    * @see #enableTables(java.util.regex.Pattern)
341    * @see #enableTable(org.apache.hadoop.hbase.TableName)
342    */
343   HTableDescriptor[] enableTables(String regex) throws IOException;
344 
345   /**
346    * Enable tables matching the passed in pattern and wait on completion. Warning: Use this method
347    * carefully, there is no prompting and the effect is immediate. Consider using {@link
348    * #listTables(java.util.regex.Pattern) } and
349    * {@link #enableTable(org.apache.hadoop.hbase.TableName)}
350    *
351    * @param pattern The pattern to match table names against
352    * @throws IOException
353    */
354   HTableDescriptor[] enableTables(Pattern pattern) throws IOException;
355 
356   /**
357    * Starts the disable of a table.  If it is being served, the master will tell the servers to stop
358    * serving it.  This method returns immediately. The disable of a table can take some time if the
359    * table is large (all regions are closed as part of table disable operation). Call {@link
360    * #isTableDisabled(org.apache.hadoop.hbase.TableName)} to check for when disable completes. If
361    * table is taking too long to online, check server logs.
362    *
363    * @param tableName name of table
364    * @throws IOException if a remote or network exception occurs
365    * @see #isTableDisabled(org.apache.hadoop.hbase.TableName)
366    * @see #isTableEnabled(org.apache.hadoop.hbase.TableName)
367    * @since 0.90.0
368    */
369   void disableTableAsync(final TableName tableName) throws IOException;
370 
371   /**
372    * Disable table and wait on completion.  May timeout eventually.  Use {@link
373    * #disableTableAsync(org.apache.hadoop.hbase.TableName)} and
374    * {@link #isTableDisabled(org.apache.hadoop.hbase.TableName)} instead. The table has to be in
375    * enabled state for it to be disabled.
376    *
377    * @param tableName
378    * @throws IOException There could be couple types of IOException TableNotFoundException means the
379    * table doesn't exist. TableNotEnabledException means the table isn't in enabled state.
380    */
381   void disableTable(final TableName tableName) throws IOException;
382 
383   /**
384    * Disable tables matching the passed in pattern and wait on completion. Warning: Use this method
385    * carefully, there is no prompting and the effect is immediate. Consider using {@link
386    * #listTables(java.lang.String)} and {@link #disableTable(org.apache.hadoop.hbase.TableName)}
387    *
388    * @param regex The regular expression to match table names against
389    * @return Table descriptors for tables that couldn't be disabled
390    * @throws IOException
391    * @see #disableTables(java.util.regex.Pattern)
392    * @see #disableTable(org.apache.hadoop.hbase.TableName)
393    */
394   HTableDescriptor[] disableTables(String regex) throws IOException;
395 
396   /**
397    * Disable tables matching the passed in pattern and wait on completion. Warning: Use this method
398    * carefully, there is no prompting and the effect is immediate. Consider using {@link
399    * #listTables(java.util.regex.Pattern) } and
400    * {@link #disableTable(org.apache.hadoop.hbase.TableName)}
401    *
402    * @param pattern The pattern to match table names against
403    * @return Table descriptors for tables that couldn't be disabled
404    * @throws IOException
405    */
406   HTableDescriptor[] disableTables(Pattern pattern) throws IOException;
407 
408   /**
409    * @param tableName name of table to check
410    * @return true if table is on-line
411    * @throws IOException if a remote or network exception occurs
412    */
413   boolean isTableEnabled(TableName tableName) throws IOException;
414 
415   /**
416    * @param tableName name of table to check
417    * @return true if table is off-line
418    * @throws IOException if a remote or network exception occurs
419    */
420   boolean isTableDisabled(TableName tableName) throws IOException;
421 
422   /**
423    * @param tableName name of table to check
424    * @return true if all regions of the table are available
425    * @throws IOException if a remote or network exception occurs
426    */
427   boolean isTableAvailable(TableName tableName) throws IOException;
428 
429   /**
430    * Use this api to check if the table has been created with the specified number of splitkeys
431    * which was used while creating the given table. Note : If this api is used after a table's
432    * region gets splitted, the api may return false.
433    *
434    * @param tableName name of table to check
435    * @param splitKeys keys to check if the table has been created with all split keys
436    * @throws IOException if a remote or network excpetion occurs
437    */
438   boolean isTableAvailable(TableName tableName, byte[][] splitKeys) throws IOException;
439 
440   /**
441    * Get the status of alter command - indicates how many regions have received the updated schema
442    * Asynchronous operation.
443    *
444    * @param tableName TableName instance
445    * @return Pair indicating the number of regions updated Pair.getFirst() is the regions that are
446    * yet to be updated Pair.getSecond() is the total number of regions of the table
447    * @throws IOException if a remote or network exception occurs
448    */
449   Pair<Integer, Integer> getAlterStatus(final TableName tableName) throws IOException;
450 
451   /**
452    * Get the status of alter command - indicates how many regions have received the updated schema
453    * Asynchronous operation.
454    *
455    * @param tableName name of the table to get the status of
456    * @return Pair indicating the number of regions updated Pair.getFirst() is the regions that are
457    * yet to be updated Pair.getSecond() is the total number of regions of the table
458    * @throws IOException if a remote or network exception occurs
459    */
460   Pair<Integer, Integer> getAlterStatus(final byte[] tableName) throws IOException;
461 
462   /**
463    * Add a column to an existing table. Asynchronous operation.
464    *
465    * @param tableName name of the table to add column to
466    * @param column column descriptor of column to be added
467    * @throws IOException if a remote or network exception occurs
468    */
469   void addColumn(final TableName tableName, final HColumnDescriptor column) throws IOException;
470 
471   /**
472    * Delete a column from a table. Asynchronous operation.
473    *
474    * @param tableName name of table
475    * @param columnName name of column to be deleted
476    * @throws IOException if a remote or network exception occurs
477    */
478   void deleteColumn(final TableName tableName, final byte[] columnName) throws IOException;
479 
480   /**
481    * Modify an existing column family on a table. Asynchronous operation.
482    *
483    * @param tableName name of table
484    * @param descriptor new column descriptor to use
485    * @throws IOException if a remote or network exception occurs
486    */
487   void modifyColumn(final TableName tableName, final HColumnDescriptor descriptor)
488       throws IOException;
489 
490   /**
491    * Close a region. For expert-admins.  Runs close on the regionserver.  The master will not be
492    * informed of the close.
493    *
494    * @param regionname region name to close
495    * @param serverName If supplied, we'll use this location rather than the one currently in
496    * <code>hbase:meta</code>
497    * @throws IOException if a remote or network exception occurs
498    */
499   void closeRegion(final String regionname, final String serverName) throws IOException;
500 
501   /**
502    * Close a region.  For expert-admins  Runs close on the regionserver.  The master will not be
503    * informed of the close.
504    *
505    * @param regionname region name to close
506    * @param serverName The servername of the regionserver.  If passed null we will use servername
507    * found in the hbase:meta table. A server name is made of host, port and startcode.  Here is an
508    * example: <code> host187.example.com,60020,1289493121758</code>
509    * @throws IOException if a remote or network exception occurs
510    */
511   void closeRegion(final byte[] regionname, final String serverName) throws IOException;
512 
513   /**
514    * For expert-admins. Runs close on the regionserver. Closes a region based on the encoded region
515    * name. The region server name is mandatory. If the servername is provided then based on the
516    * online regions in the specified regionserver the specified region will be closed. The master
517    * will not be informed of the close. Note that the regionname is the encoded regionname.
518    *
519    * @param encodedRegionName The encoded region name; i.e. the hash that makes up the region name
520    * suffix: e.g. if regionname is
521    * <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>,
522    * then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>.
523    * @param serverName The servername of the regionserver. A server name is made of host, port and
524    * startcode. This is mandatory. Here is an example:
525    * <code> host187.example.com,60020,1289493121758</code>
526    * @return true if the region was closed, false if not.
527    * @throws IOException if a remote or network exception occurs
528    */
529   boolean closeRegionWithEncodedRegionName(final String encodedRegionName, final String serverName)
530       throws IOException;
531 
532   /**
533    * Close a region.  For expert-admins  Runs close on the regionserver.  The master will not be
534    * informed of the close.
535    *
536    * @param sn
537    * @param hri
538    * @throws IOException
539    */
540   void closeRegion(final ServerName sn, final HRegionInfo hri) throws IOException;
541 
542   /**
543    * Get all the online regions on a region server.
544    */
545   List<HRegionInfo> getOnlineRegions(final ServerName sn) throws IOException;
546 
547   /**
548    * Flush a table. Synchronous operation.
549    *
550    * @param tableName table to flush
551    * @throws IOException if a remote or network exception occurs
552    */
553   void flush(final TableName tableName) throws IOException;
554 
555   /**
556    * Flush an individual region. Synchronous operation.
557    *
558    * @param regionName region to flush
559    * @throws IOException if a remote or network exception occurs
560    */
561   void flushRegion(final byte[] regionName) throws IOException;
562 
563   /**
564    * Compact a table. Asynchronous operation.
565    *
566    * @param tableName table to compact
567    * @throws IOException if a remote or network exception occurs
568    */
569   void compact(final TableName tableName) throws IOException;
570 
571   /**
572    * Compact an individual region. Asynchronous operation.
573    *
574    * @param regionName region to compact
575    * @throws IOException if a remote or network exception occurs
576    */
577   void compactRegion(final byte[] regionName) throws IOException;
578 
579   /**
580    * Compact a column family within a table. Asynchronous operation.
581    *
582    * @param tableName table to compact
583    * @param columnFamily column family within a table
584    * @throws IOException if a remote or network exception occurs
585    */
586   void compact(final TableName tableName, final byte[] columnFamily)
587     throws IOException;
588 
589   /**
590    * Compact a column family within a region. Asynchronous operation.
591    *
592    * @param regionName region to compact
593    * @param columnFamily column family within a region
594    * @throws IOException if a remote or network exception occurs
595    */
596   void compactRegion(final byte[] regionName, final byte[] columnFamily)
597     throws IOException;
598 
599   /**
600    * Major compact a table. Asynchronous operation.
601    *
602    * @param tableName table to major compact
603    * @throws IOException if a remote or network exception occurs
604    */
605   void majorCompact(TableName tableName) throws IOException;
606 
607   /**
608    * Major compact a table or an individual region. Asynchronous operation.
609    *
610    * @param regionName region to major compact
611    * @throws IOException if a remote or network exception occurs
612    */
613   void majorCompactRegion(final byte[] regionName) throws IOException;
614 
615   /**
616    * Major compact a column family within a table. Asynchronous operation.
617    *
618    * @param tableName table to major compact
619    * @param columnFamily column family within a table
620    * @throws IOException if a remote or network exception occurs
621    */
622   void majorCompact(TableName tableName, final byte[] columnFamily)
623     throws IOException;
624 
625   /**
626    * Major compact a column family within region. Asynchronous operation.
627    *
628    * @param regionName egion to major compact
629    * @param columnFamily column family within a region
630    * @throws IOException if a remote or network exception occurs
631    */
632   void majorCompactRegion(final byte[] regionName, final byte[] columnFamily)
633     throws IOException;
634 
635   /**
636    * Compact all regions on the region server
637    * @param sn the region server name
638    * @param major if it's major compaction
639    * @throws IOException
640    * @throws InterruptedException
641    */
642   public void compactRegionServer(final ServerName sn, boolean major)
643     throws IOException, InterruptedException;
644 
645   /**
646    * Move the region <code>r</code> to <code>dest</code>.
647    *
648    * @param encodedRegionName The encoded region name; i.e. the hash that makes up the region name
649    * suffix: e.g. if regionname is
650    * <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>,
651    * then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>.
652    * @param destServerName The servername of the destination regionserver.  If passed the empty byte
653    * array we'll assign to a random server.  A server name is made of host, port and startcode.
654    * Here is an example: <code> host187.example.com,60020,1289493121758</code>
655    * @throws UnknownRegionException Thrown if we can't find a region named
656    * <code>encodedRegionName</code>
657    */
658   void move(final byte[] encodedRegionName, final byte[] destServerName)
659       throws IOException;
660 
661   /**
662    * @param regionName Region name to assign.
663    */
664   void assign(final byte[] regionName)
665       throws IOException;
666 
667   /**
668    * Unassign a region from current hosting regionserver.  Region will then be assigned to a
669    * regionserver chosen at random.  Region could be reassigned back to the same server.  Use {@link
670    * #move(byte[], byte[])} if you want to control the region movement.
671    *
672    * @param regionName Region to unassign. Will clear any existing RegionPlan if one found.
673    * @param force If true, force unassign (Will remove region from regions-in-transition too if
674    * present. If results in double assignment use hbck -fix to resolve. To be used by experts).
675    */
676   void unassign(final byte[] regionName, final boolean force)
677       throws IOException;
678 
679   /**
680    * Offline specified region from master's in-memory state. It will not attempt to reassign the
681    * region as in unassign. This API can be used when a region not served by any region server and
682    * still online as per Master's in memory state. If this API is incorrectly used on active region
683    * then master will loose track of that region. This is a special method that should be used by
684    * experts or hbck.
685    *
686    * @param regionName Region to offline.
687    * @throws IOException
688    */
689   void offline(final byte[] regionName) throws IOException;
690 
691   /**
692    * Turn the load balancer on or off.
693    *
694    * @param synchronous If true, it waits until current balance() call, if outstanding, to return.
695    * @return Previous balancer value
696    */
697   boolean setBalancerRunning(final boolean on, final boolean synchronous)
698       throws IOException;
699 
700   /**
701    * Invoke the balancer.  Will run the balancer and if regions to move, it will go ahead and do the
702    * reassignments.  Can NOT run for various reasons.  Check logs.
703    *
704    * @return True if balancer ran, false otherwise.
705    */
706   boolean balancer() throws IOException;
707 
708   /**
709    * Invoke the balancer.  Will run the balancer and if regions to move, it will
710    * go ahead and do the reassignments. If there is region in transition, force parameter of true
711    * would still run balancer. Can *not* run for other reasons.  Check
712    * logs.
713    * @param force whether we should force balance even if there is region in transition
714    * @return True if balancer ran, false otherwise.
715    */
716   boolean balancer(boolean force) throws IOException;
717   
718   /**
719    * Query the current state of the balancer
720    *
721    * @return true if the balancer is enabled, false otherwise.
722    */
723   boolean isBalancerEnabled() throws IOException;
724 
725   /**
726    * Invoke region normalizer. Can NOT run for various reasons.  Check logs.
727    *
728    * @return True if region normalizer ran, false otherwise.
729    */
730   boolean normalize() throws IOException;
731 
732   /**
733    * Query the current state of the region normalizer
734    *
735    * @return true if region normalizer is enabled, false otherwise.
736    */
737   boolean isNormalizerEnabled() throws IOException;
738 
739   /**
740    * Turn region normalizer on or off.
741    *
742    * @return Previous normalizer value
743    */
744   boolean setNormalizerRunning(final boolean on)
745     throws IOException;
746 
747   /**
748    * Enable/Disable the catalog janitor
749    *
750    * @param enable if true enables the catalog janitor
751    * @return the previous state
752    */
753   boolean enableCatalogJanitor(boolean enable) throws IOException;
754 
755   /**
756    * Ask for a scan of the catalog table
757    *
758    * @return the number of entries cleaned
759    */
760   int runCatalogScan() throws IOException;
761 
762   /**
763    * Query on the catalog janitor state (Enabled/Disabled?)
764    *
765    */
766   boolean isCatalogJanitorEnabled() throws IOException;
767 
768   /**
769    * Merge two regions. Asynchronous operation.
770    *
771    * @param encodedNameOfRegionA encoded name of region a
772    * @param encodedNameOfRegionB encoded name of region b
773    * @param forcible true if do a compulsory merge, otherwise we will only merge two adjacent
774    * regions
775    * @throws IOException
776    */
777   void mergeRegions(final byte[] encodedNameOfRegionA, final byte[] encodedNameOfRegionB,
778       final boolean forcible) throws IOException;
779 
780   /**
781    * Split a table. Asynchronous operation.
782    *
783    * @param tableName table to split
784    * @throws IOException if a remote or network exception occurs
785    */
786   void split(final TableName tableName) throws IOException;
787 
788   /**
789    * Split an individual region. Asynchronous operation.
790    *
791    * @param regionName region to split
792    * @throws IOException if a remote or network exception occurs
793    */
794   void splitRegion(final byte[] regionName) throws IOException;
795 
796   /**
797    * Split a table. Asynchronous operation.
798    *
799    * @param tableName table to split
800    * @param splitPoint the explicit position to split on
801    * @throws IOException if a remote or network exception occurs
802    */
803   void split(final TableName tableName, final byte[] splitPoint)
804     throws IOException;
805 
806   /**
807    * Split an individual region. Asynchronous operation.
808    *
809    * @param regionName region to split
810    * @param splitPoint the explicit position to split on
811    * @throws IOException if a remote or network exception occurs
812    */
813   void splitRegion(final byte[] regionName, final byte[] splitPoint)
814     throws IOException;
815 
816 
817   /**
818    * Modify an existing table, more IRB friendly version. Asynchronous operation.  This means that
819    * it may be a while before your schema change is updated across all of the table.
820    *
821    * @param tableName name of table.
822    * @param htd modified description of the table
823    * @throws IOException if a remote or network exception occurs
824    */
825   void modifyTable(final TableName tableName, final HTableDescriptor htd)
826       throws IOException;
827 
828   /**
829    * Shuts down the HBase cluster
830    *
831    * @throws IOException if a remote or network exception occurs
832    */
833   void shutdown() throws IOException;
834 
835   /**
836    * Shuts down the current HBase master only. Does not shutdown the cluster.
837    *
838    * @throws IOException if a remote or network exception occurs
839    * @see #shutdown()
840    */
841   void stopMaster() throws IOException;
842 
843   /**
844    * Check whether Master is in maintenance mode
845    *
846    * @throws IOException if a remote or network exception occurs
847    */
848   boolean isMasterInMaintenanceMode()  throws IOException;
849 
850   /**
851    * Stop the designated regionserver
852    *
853    * @param hostnamePort Hostname and port delimited by a <code>:</code> as in
854    * <code>example.org:1234</code>
855    * @throws IOException if a remote or network exception occurs
856    */
857   void stopRegionServer(final String hostnamePort) throws IOException;
858 
859   /**
860    * @return cluster status
861    * @throws IOException if a remote or network exception occurs
862    */
863   ClusterStatus getClusterStatus() throws IOException;
864 
865   /**
866    * @return Configuration used by the instance.
867    */
868   Configuration getConfiguration();
869 
870   /**
871    * Create a new namespace
872    *
873    * @param descriptor descriptor which describes the new namespace
874    * @throws IOException
875    */
876   void createNamespace(final NamespaceDescriptor descriptor)
877       throws IOException;
878 
879   /**
880    * Modify an existing namespace
881    *
882    * @param descriptor descriptor which describes the new namespace
883    * @throws IOException
884    */
885   void modifyNamespace(final NamespaceDescriptor descriptor)
886       throws IOException;
887 
888   /**
889    * Delete an existing namespace. Only empty namespaces (no tables) can be removed.
890    *
891    * @param name namespace name
892    * @throws IOException
893    */
894   void deleteNamespace(final String name) throws IOException;
895 
896   /**
897    * Get a namespace descriptor by name
898    *
899    * @param name name of namespace descriptor
900    * @return A descriptor
901    * @throws IOException
902    */
903   NamespaceDescriptor getNamespaceDescriptor(final String name)
904       throws IOException;
905 
906   /**
907    * List available namespace descriptors
908    *
909    * @return List of descriptors
910    * @throws IOException
911    */
912   NamespaceDescriptor[] listNamespaceDescriptors()
913     throws IOException;
914 
915   /**
916    * Get list of table descriptors by namespace
917    *
918    * @param name namespace name
919    * @return A descriptor
920    * @throws IOException
921    */
922   HTableDescriptor[] listTableDescriptorsByNamespace(final String name)
923       throws IOException;
924 
925   /**
926    * Get list of table names by namespace
927    *
928    * @param name namespace name
929    * @return The list of table names in the namespace
930    * @throws IOException
931    */
932   TableName[] listTableNamesByNamespace(final String name)
933       throws IOException;
934 
935   /**
936    * Get the regions of a given table.
937    *
938    * @param tableName the name of the table
939    * @return List of {@link HRegionInfo}.
940    * @throws IOException
941    */
942   List<HRegionInfo> getTableRegions(final TableName tableName)
943     throws IOException;
944 
945   @Override
946   void close() throws IOException;
947 
948   /**
949    * Get tableDescriptors
950    *
951    * @param tableNames List of table names
952    * @return HTD[] the tableDescriptor
953    * @throws IOException if a remote or network exception occurs
954    */
955   HTableDescriptor[] getTableDescriptorsByTableName(List<TableName> tableNames)
956     throws IOException;
957 
958   /**
959    * Get tableDescriptors
960    *
961    * @param names List of table names
962    * @return HTD[] the tableDescriptor
963    * @throws IOException if a remote or network exception occurs
964    */
965   HTableDescriptor[] getTableDescriptors(List<String> names)
966     throws IOException;
967 
968   /**
969    * abort a procedure
970    * @param procId ID of the procedure to abort
971    * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
972    * @return true if aborted, false if procedure already completed or does not exist
973    * @throws IOException
974    */
975   boolean abortProcedure(
976       final long procId,
977       final boolean mayInterruptIfRunning) throws IOException;
978 
979   /**
980    * List procedures
981    * @return procedure list
982    * @throws IOException
983    */
984   ProcedureInfo[] listProcedures() throws IOException;
985 
986   /**
987    * Abort a procedure but does not block and wait for it be completely removed.
988    * You can use Future.get(long, TimeUnit) to wait on the operation to complete.
989    * It may throw ExecutionException if there was an error while executing the operation
990    * or TimeoutException in case the wait timeout was not long enough to allow the
991    * operation to complete.
992    *
993    * @param procId ID of the procedure to abort
994    * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
995    * @return true if aborted, false if procedure already completed or does not exist
996    * @throws IOException
997    */
998   Future<Boolean> abortProcedureAsync(
999     final long procId,
1000     final boolean mayInterruptIfRunning) throws IOException;
1001 
1002   /**
1003    * Roll the log writer. I.e. for filesystem based write ahead logs, start writing to a new file.
1004    *
1005    * Note that the actual rolling of the log writer is asynchronous and may not be complete when
1006    * this method returns. As a side effect of this call, the named region server may schedule
1007    * store flushes at the request of the wal.
1008    *
1009    * @param serverName The servername of the regionserver.
1010    * @throws IOException if a remote or network exception occurs
1011    * @throws org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException
1012    */
1013   void rollWALWriter(ServerName serverName) throws IOException, FailedLogCloseException;
1014 
1015   /**
1016    * Helper delegage to getClusterStatus().getMasterCoprocessors().
1017    * @return an array of master coprocessors
1018    * @see org.apache.hadoop.hbase.ClusterStatus#getMasterCoprocessors()
1019    */
1020   String[] getMasterCoprocessors() throws IOException;
1021 
1022   /**
1023    * Get the current compaction state of a table. It could be in a major compaction, a minor
1024    * compaction, both, or none.
1025    *
1026    * @param tableName table to examine
1027    * @return the current compaction state
1028    * @throws IOException if a remote or network exception occurs
1029    */
1030   AdminProtos.GetRegionInfoResponse.CompactionState getCompactionState(final TableName tableName)
1031     throws IOException;
1032 
1033   /**
1034    * Get the current compaction state of region. It could be in a major compaction, a minor
1035    * compaction, both, or none.
1036    *
1037    * @param regionName region to examine
1038    * @return the current compaction state
1039    * @throws IOException if a remote or network exception occurs
1040    */
1041   AdminProtos.GetRegionInfoResponse.CompactionState getCompactionStateForRegion(
1042     final byte[] regionName) throws IOException;
1043 
1044   /**
1045    * Get the timestamp of the last major compaction for the passed table
1046    *
1047    * The timestamp of the oldest HFile resulting from a major compaction of that table,
1048    * or 0 if no such HFile could be found.
1049    *
1050    * @param tableName table to examine
1051    * @return the last major compaction timestamp or 0
1052    * @throws IOException if a remote or network exception occurs
1053    */
1054   long getLastMajorCompactionTimestamp(final TableName tableName)
1055     throws IOException;
1056 
1057   /**
1058    * Get the timestamp of the last major compaction for the passed region.
1059    *
1060    * The timestamp of the oldest HFile resulting from a major compaction of that region,
1061    * or 0 if no such HFile could be found.
1062    *
1063    * @param regionName region to examine
1064    * @return the last major compaction timestamp or 0
1065    * @throws IOException if a remote or network exception occurs
1066    */
1067   long getLastMajorCompactionTimestampForRegion(final byte[] regionName)
1068       throws IOException;
1069 
1070   /**
1071    * Take a snapshot for the given table. If the table is enabled, a FLUSH-type snapshot will be
1072    * taken. If the table is disabled, an offline snapshot is taken. Snapshots are considered unique
1073    * based on <b>the name of the snapshot</b>. Attempts to take a snapshot with the same name (even
1074    * a different type or with different parameters) will fail with a {@link
1075    * org.apache.hadoop.hbase.snapshot.SnapshotCreationException} indicating the duplicate naming.
1076    * Snapshot names follow the same naming constraints as tables in HBase. See {@link
1077    * org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}.
1078    *
1079    * @param snapshotName name of the snapshot to be created
1080    * @param tableName name of the table for which snapshot is created
1081    * @throws IOException if a remote or network exception occurs
1082    * @throws org.apache.hadoop.hbase.snapshot.SnapshotCreationException if snapshot creation failed
1083    * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
1084    */
1085   void snapshot(final String snapshotName, final TableName tableName)
1086       throws IOException, SnapshotCreationException, IllegalArgumentException;
1087 
1088   /**
1089    * public void snapshot(final String snapshotName, Create a timestamp consistent snapshot for the
1090    * given table. final byte[] tableName) throws IOException, Snapshots are considered unique based
1091    * on <b>the name of the snapshot</b>. Attempts to take a snapshot with the same name (even a
1092    * different type or with different parameters) will fail with a {@link SnapshotCreationException}
1093    * indicating the duplicate naming. Snapshot names follow the same naming constraints as tables in
1094    * HBase.
1095    *
1096    * @param snapshotName name of the snapshot to be created
1097    * @param tableName name of the table for which snapshot is created
1098    * @throws IOException if a remote or network exception occurs
1099    * @throws SnapshotCreationException if snapshot creation failed
1100    * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
1101    */
1102   void snapshot(final byte[] snapshotName, final TableName tableName)
1103       throws IOException, SnapshotCreationException, IllegalArgumentException;
1104 
1105   /**
1106    * Create typed snapshot of the table. Snapshots are considered unique based on <b>the name of the
1107    * snapshot</b>. Attempts to take a snapshot with the same name (even a different type or with
1108    * different parameters) will fail with a {@link SnapshotCreationException} indicating the
1109    * duplicate naming. Snapshot names follow the same naming constraints as tables in HBase. See
1110    * {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}.
1111    *
1112    * @param snapshotName name to give the snapshot on the filesystem. Must be unique from all other
1113    * snapshots stored on the cluster
1114    * @param tableName name of the table to snapshot
1115    * @param type type of snapshot to take
1116    * @throws IOException we fail to reach the master
1117    * @throws SnapshotCreationException if snapshot creation failed
1118    * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
1119    */
1120   void snapshot(final String snapshotName,
1121       final TableName tableName,
1122       HBaseProtos.SnapshotDescription.Type type) throws IOException, SnapshotCreationException,
1123       IllegalArgumentException;
1124 
1125   /**
1126    * Take a snapshot and wait for the server to complete that snapshot (blocking). Only a single
1127    * snapshot should be taken at a time for an instance of HBase, or results may be undefined (you
1128    * can tell multiple HBase clusters to snapshot at the same time, but only one at a time for a
1129    * single cluster). Snapshots are considered unique based on <b>the name of the snapshot</b>.
1130    * Attempts to take a snapshot with the same name (even a different type or with different
1131    * parameters) will fail with a {@link SnapshotCreationException} indicating the duplicate naming.
1132    * Snapshot names follow the same naming constraints as tables in HBase. See {@link
1133    * org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}. You should probably
1134    * use {@link #snapshot(String, org.apache.hadoop.hbase.TableName)} or
1135    * {@link #snapshot(byte[], org.apache.hadoop.hbase.TableName)} unless you are sure about the type
1136    * of snapshot that you want to take.
1137    *
1138    * @param snapshot snapshot to take
1139    * @throws IOException or we lose contact with the master.
1140    * @throws SnapshotCreationException if snapshot failed to be taken
1141    * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
1142    */
1143   void snapshot(HBaseProtos.SnapshotDescription snapshot)
1144       throws IOException, SnapshotCreationException, IllegalArgumentException;
1145 
1146   /**
1147    * Take a snapshot without waiting for the server to complete that snapshot (asynchronous) Only a
1148    * single snapshot should be taken at a time, or results may be undefined.
1149    *
1150    * @param snapshot snapshot to take
1151    * @return response from the server indicating the max time to wait for the snapshot
1152    * @throws IOException if the snapshot did not succeed or we lose contact with the master.
1153    * @throws SnapshotCreationException if snapshot creation failed
1154    * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
1155    */
1156   MasterProtos.SnapshotResponse takeSnapshotAsync(HBaseProtos.SnapshotDescription snapshot)
1157       throws IOException, SnapshotCreationException;
1158 
1159   /**
1160    * Check the current state of the passed snapshot. There are three possible states: <ol>
1161    * <li>running - returns <tt>false</tt></li> <li>finished - returns <tt>true</tt></li>
1162    * <li>finished with error - throws the exception that caused the snapshot to fail</li> </ol> The
1163    * cluster only knows about the most recent snapshot. Therefore, if another snapshot has been
1164    * run/started since the snapshot your are checking, you will recieve an {@link
1165    * org.apache.hadoop.hbase.snapshot.UnknownSnapshotException}.
1166    *
1167    * @param snapshot description of the snapshot to check
1168    * @return <tt>true</tt> if the snapshot is completed, <tt>false</tt> if the snapshot is still
1169    * running
1170    * @throws IOException if we have a network issue
1171    * @throws org.apache.hadoop.hbase.snapshot.HBaseSnapshotException if the snapshot failed
1172    * @throws org.apache.hadoop.hbase.snapshot.UnknownSnapshotException if the requested snapshot is
1173    * unknown
1174    */
1175   boolean isSnapshotFinished(final HBaseProtos.SnapshotDescription snapshot)
1176       throws IOException, HBaseSnapshotException, UnknownSnapshotException;
1177 
1178   /**
1179    * Restore the specified snapshot on the original table. (The table must be disabled) If the
1180    * "hbase.snapshot.restore.take.failsafe.snapshot" configuration property is set to true, a
1181    * snapshot of the current table is taken before executing the restore operation. In case of
1182    * restore failure, the failsafe snapshot will be restored. If the restore completes without
1183    * problem the failsafe snapshot is deleted.
1184    *
1185    * @param snapshotName name of the snapshot to restore
1186    * @throws IOException if a remote or network exception occurs
1187    * @throws org.apache.hadoop.hbase.snapshot.RestoreSnapshotException if snapshot failed to be
1188    * restored
1189    * @throws IllegalArgumentException if the restore request is formatted incorrectly
1190    */
1191   void restoreSnapshot(final byte[] snapshotName) throws IOException, RestoreSnapshotException;
1192 
1193   /**
1194    * Restore the specified snapshot on the original table. (The table must be disabled) If the
1195    * "hbase.snapshot.restore.take.failsafe.snapshot" configuration property is set to true, a
1196    * snapshot of the current table is taken before executing the restore operation. In case of
1197    * restore failure, the failsafe snapshot will be restored. If the restore completes without
1198    * problem the failsafe snapshot is deleted.
1199    *
1200    * @param snapshotName name of the snapshot to restore
1201    * @throws IOException if a remote or network exception occurs
1202    * @throws RestoreSnapshotException if snapshot failed to be restored
1203    * @throws IllegalArgumentException if the restore request is formatted incorrectly
1204    */
1205   void restoreSnapshot(final String snapshotName) throws IOException, RestoreSnapshotException;
1206 
1207   /**
1208    * Restore the specified snapshot on the original table. (The table must be disabled) If
1209    * 'takeFailSafeSnapshot' is set to true, a snapshot of the current table is taken before
1210    * executing the restore operation. In case of restore failure, the failsafe snapshot will be
1211    * restored. If the restore completes without problem the failsafe snapshot is deleted. The
1212    * failsafe snapshot name is configurable by using the property
1213    * "hbase.snapshot.restore.failsafe.name".
1214    *
1215    * @param snapshotName name of the snapshot to restore
1216    * @param takeFailSafeSnapshot true if the failsafe snapshot should be taken
1217    * @throws IOException if a remote or network exception occurs
1218    * @throws RestoreSnapshotException if snapshot failed to be restored
1219    * @throws IllegalArgumentException if the restore request is formatted incorrectly
1220    */
1221   void restoreSnapshot(final byte[] snapshotName, final boolean takeFailSafeSnapshot)
1222       throws IOException, RestoreSnapshotException;
1223 
1224   /**
1225    * Restore the specified snapshot on the original table. (The table must be disabled) If
1226    * 'takeFailSafeSnapshot' is set to true, a snapshot of the current table is taken before
1227    * executing the restore operation. In case of restore failure, the failsafe snapshot will be
1228    * restored. If the restore completes without problem the failsafe snapshot is deleted. The
1229    * failsafe snapshot name is configurable by using the property
1230    * "hbase.snapshot.restore.failsafe.name".
1231    *
1232    * @param snapshotName name of the snapshot to restore
1233    * @param takeFailSafeSnapshot true if the failsafe snapshot should be taken
1234    * @throws IOException if a remote or network exception occurs
1235    * @throws RestoreSnapshotException if snapshot failed to be restored
1236    * @throws IllegalArgumentException if the restore request is formatted incorrectly
1237    */
1238   void restoreSnapshot(final String snapshotName, boolean takeFailSafeSnapshot)
1239       throws IOException, RestoreSnapshotException;
1240 
1241   /**
1242   * Restore the specified snapshot on the original table. (The table must be disabled) If
1243   * 'takeFailSafeSnapshot' is set to true, a snapshot of the current table is taken before
1244   * executing the restore operation. In case of restore failure, the failsafe snapshot will be
1245   * restored. If the restore completes without problem the failsafe snapshot is deleted. The
1246   * failsafe snapshot name is configurable by using the property
1247   * "hbase.snapshot.restore.failsafe.name".
1248   * @param snapshotName name of the snapshot to restore
1249   * @param takeFailSafeSnapshot true if the failsafe snapshot should be taken
1250   * @param restoreAcl true to restore acl of snapshot into table.
1251   * @throws IOException if a remote or network exception occurs
1252   * @throws RestoreSnapshotException if snapshot failed to be restored
1253   * @throws IllegalArgumentException if the restore request is formatted incorrectly
1254   */
1255   void restoreSnapshot(final String snapshotName, boolean takeFailSafeSnapshot, boolean restoreAcl)
1256     throws IOException, RestoreSnapshotException;
1257 
1258   /**
1259    * Create a new table by cloning the snapshot content.
1260    *
1261    * @param snapshotName name of the snapshot to be cloned
1262    * @param tableName name of the table where the snapshot will be restored
1263    * @throws IOException if a remote or network exception occurs
1264    * @throws TableExistsException if table to be created already exists
1265    * @throws RestoreSnapshotException if snapshot failed to be cloned
1266    * @throws IllegalArgumentException if the specified table has not a valid name
1267    */
1268   void cloneSnapshot(final byte[] snapshotName, final TableName tableName)
1269       throws IOException, TableExistsException, RestoreSnapshotException;
1270 
1271   /**
1272    * Create a new table by cloning the snapshot content.
1273    *
1274    * @param snapshotName name of the snapshot to be cloned
1275    * @param tableName name of the table where the snapshot will be restored
1276    * @throws IOException if a remote or network exception occurs
1277    * @throws TableExistsException if table to be created already exists
1278    * @throws RestoreSnapshotException if snapshot failed to be cloned
1279    * @throws IllegalArgumentException if the specified table has not a valid name
1280    */
1281   void cloneSnapshot(final String snapshotName, final TableName tableName)
1282       throws IOException, TableExistsException, RestoreSnapshotException;
1283 
1284   /**
1285   * Create a new table by cloning the snapshot content.
1286   * @param snapshotName name of the snapshot to be cloned
1287   * @param tableName name of the table where the snapshot will be restored
1288   * @param restoreAcl true to restore acl of snapshot into newly created table
1289   * @throws IOException if a remote or network exception occurs
1290   * @throws TableExistsException if table to be created already exists
1291   * @throws RestoreSnapshotException if snapshot failed to be cloned
1292   * @throws IllegalArgumentException if the specified table has not a valid name
1293   */
1294   void cloneSnapshot(final String snapshotName, final TableName tableName, final boolean restoreAcl)
1295       throws IOException, TableExistsException, RestoreSnapshotException;
1296 
1297   /**
1298    * Execute a distributed procedure on a cluster.
1299    *
1300    * @param signature A distributed procedure is uniquely identified by its signature (default the
1301    * root ZK node name of the procedure).
1302    * @param instance The instance name of the procedure. For some procedures, this parameter is
1303    * optional.
1304    * @param props Property/Value pairs of properties passing to the procedure
1305    * @throws IOException
1306    */
1307    void execProcedure(String signature, String instance, Map<String, String> props)
1308       throws IOException;
1309 
1310   /**
1311    * Execute a distributed procedure on a cluster.
1312    *
1313    * @param signature A distributed procedure is uniquely identified by its signature (default the
1314    * root ZK node name of the procedure).
1315    * @param instance The instance name of the procedure. For some procedures, this parameter is
1316    * optional.
1317    * @param props Property/Value pairs of properties passing to the procedure
1318    * @return data returned after procedure execution. null if no return data.
1319    * @throws IOException
1320    */
1321   byte[] execProcedureWithRet(String signature, String instance, Map<String, String> props)
1322       throws IOException;
1323 
1324   /**
1325    * Check the current state of the specified procedure. There are three possible states: <ol>
1326    * <li>running - returns <tt>false</tt></li> <li>finished - returns <tt>true</tt></li>
1327    * <li>finished with error - throws the exception that caused the procedure to fail</li> </ol>
1328    *
1329    * @param signature The signature that uniquely identifies a procedure
1330    * @param instance The instance name of the procedure
1331    * @param props Property/Value pairs of properties passing to the procedure
1332    * @return true if the specified procedure is finished successfully, false if it is still running
1333    * @throws IOException if the specified procedure finished with error
1334    */
1335   boolean isProcedureFinished(String signature, String instance, Map<String, String> props)
1336       throws IOException;
1337 
1338   /**
1339    * List completed snapshots.
1340    *
1341    * @return a list of snapshot descriptors for completed snapshots
1342    * @throws IOException if a network error occurs
1343    */
1344   List<HBaseProtos.SnapshotDescription> listSnapshots() throws IOException;
1345 
1346   /**
1347    * List all the completed snapshots matching the given regular expression.
1348    *
1349    * @param regex The regular expression to match against
1350    * @return - returns a List of SnapshotDescription
1351    * @throws IOException if a remote or network exception occurs
1352    */
1353   List<HBaseProtos.SnapshotDescription> listSnapshots(String regex) throws IOException;
1354 
1355   /**
1356    * List all the completed snapshots matching the given pattern.
1357    *
1358    * @param pattern The compiled regular expression to match against
1359    * @return - returns a List of SnapshotDescription
1360    * @throws IOException if a remote or network exception occurs
1361    */
1362   List<HBaseProtos.SnapshotDescription> listSnapshots(Pattern pattern) throws IOException;
1363 
1364   /**
1365    * Delete an existing snapshot.
1366    *
1367    * @param snapshotName name of the snapshot
1368    * @throws IOException if a remote or network exception occurs
1369    */
1370   void deleteSnapshot(final byte[] snapshotName) throws IOException;
1371 
1372   /**
1373    * Delete an existing snapshot.
1374    *
1375    * @param snapshotName name of the snapshot
1376    * @throws IOException if a remote or network exception occurs
1377    */
1378   void deleteSnapshot(final String snapshotName) throws IOException;
1379 
1380   /**
1381    * Delete existing snapshots whose names match the pattern passed.
1382    *
1383    * @param regex The regular expression to match against
1384    * @throws IOException if a remote or network exception occurs
1385    */
1386   void deleteSnapshots(final String regex) throws IOException;
1387 
1388   /**
1389    * Delete existing snapshots whose names match the pattern passed.
1390    *
1391    * @param pattern pattern for names of the snapshot to match
1392    * @throws IOException if a remote or network exception occurs
1393    */
1394   void deleteSnapshots(final Pattern pattern) throws IOException;
1395   
1396   /**
1397    * Apply the new quota settings.
1398    * @param quota the quota settings
1399    * @throws IOException if a remote or network exception occurs
1400    */
1401   void setQuota(final QuotaSettings quota) throws IOException;
1402 
1403   /**
1404    * Return a QuotaRetriever to list the quotas based on the filter.
1405    * @param filter the quota settings filter
1406    * @return the quota retriever
1407    * @throws IOException if a remote or network exception occurs
1408    */
1409   QuotaRetriever getQuotaRetriever(final QuotaFilter filter) throws IOException;
1410 
1411   /**
1412    * Creates and returns a {@link com.google.protobuf.RpcChannel} instance connected to the active
1413    * master. <p> The obtained {@link com.google.protobuf.RpcChannel} instance can be used to access
1414    * a published coprocessor {@link com.google.protobuf.Service} using standard protobuf service
1415    * invocations: </p> <div style="background-color: #cccccc; padding: 2px">
1416    * <blockquote><pre>
1417    * CoprocessorRpcChannel channel = myAdmin.coprocessorService();
1418    * MyService.BlockingInterface service = MyService.newBlockingStub(channel);
1419    * MyCallRequest request = MyCallRequest.newBuilder()
1420    *     ...
1421    *     .build();
1422    * MyCallResponse response = service.myCall(null, request);
1423    * </pre></blockquote></div>
1424    *
1425    * @return A MasterCoprocessorRpcChannel instance
1426    */
1427   CoprocessorRpcChannel coprocessorService();
1428 
1429 
1430   /**
1431    * Creates and returns a {@link com.google.protobuf.RpcChannel} instance
1432    * connected to the passed region server.
1433    *
1434    * <p>
1435    * The obtained {@link com.google.protobuf.RpcChannel} instance can be used to access a published
1436    * coprocessor {@link com.google.protobuf.Service} using standard protobuf service invocations:
1437    * </p>
1438    *
1439    * <div style="background-color: #cccccc; padding: 2px">
1440    * <blockquote><pre>
1441    * CoprocessorRpcChannel channel = myAdmin.coprocessorService(serverName);
1442    * MyService.BlockingInterface service = MyService.newBlockingStub(channel);
1443    * MyCallRequest request = MyCallRequest.newBuilder()
1444    *     ...
1445    *     .build();
1446    * MyCallResponse response = service.myCall(null, request);
1447    * </pre></blockquote></div>
1448    *
1449    * @param sn the server name to which the endpoint call is made
1450    * @return A RegionServerCoprocessorRpcChannel instance
1451    */
1452   CoprocessorRpcChannel coprocessorService(ServerName sn);
1453 
1454 
1455   /**
1456    * Update the configuration and trigger an online config change
1457    * on the regionserver
1458    * @param server : The server whose config needs to be updated.
1459    * @throws IOException
1460    */
1461   void updateConfiguration(ServerName server) throws IOException;
1462 
1463 
1464   /**
1465    * Update the configuration and trigger an online config change
1466    * on all the regionservers
1467    * @throws IOException
1468    */
1469   void updateConfiguration() throws IOException;
1470 
1471   /**
1472    * Get the info port of the current master if one is available.
1473    * @return master info port
1474    * @throws IOException
1475    */
1476   public int getMasterInfoPort() throws IOException;
1477 
1478   /**
1479    * Compact a table. Asynchronous operation.
1480    *
1481    * @param tableName table to compact
1482    * @param compactType {@link org.apache.hadoop.hbase.client.Admin.CompactType}
1483    * @throws IOException
1484    * @throws InterruptedException
1485    */
1486   void compact(final TableName tableName, CompactType compactType)
1487       throws IOException, InterruptedException;
1488 
1489   /**
1490    * Compact a column family within a table. Asynchronous operation.
1491    *
1492    * @param tableName table to compact
1493    * @param columnFamily column family within a table
1494    * @param compactType {@link org.apache.hadoop.hbase.client.Admin.CompactType}
1495    * @throws IOException if not a mob column family or if a remote or network exception occurs
1496    * @throws InterruptedException
1497    */
1498   void compact(final TableName tableName, final byte[] columnFamily, CompactType compactType)
1499       throws IOException, InterruptedException;
1500 
1501   /**
1502    * Major compact a table. Asynchronous operation.
1503    *
1504    * @param tableName table to compact
1505    * @param compactType {@link org.apache.hadoop.hbase.client.Admin.CompactType}
1506    * @throws IOException
1507    * @throws InterruptedException
1508    */
1509   void majorCompact(final TableName tableName, CompactType compactType) throws IOException,
1510   InterruptedException;
1511 
1512   /**
1513    * Major compact a column family within a table. Asynchronous operation.
1514    *
1515    * @param tableName table to compact
1516    * @param columnFamily column family within a table
1517    * @param compactType {@link org.apache.hadoop.hbase.client.Admin.CompactType}
1518    * @throws IOException if not a mob column family or if a remote or network exception occurs
1519    * @throws InterruptedException
1520    */
1521   void majorCompact(final TableName tableName, final byte[] columnFamily, CompactType compactType)
1522       throws IOException, InterruptedException;
1523 
1524   /**
1525    * Get the current compaction state of a table. It could be in a compaction, or none.
1526    *
1527    * @param tableName table to examine
1528    * @param compactType {@link org.apache.hadoop.hbase.client.Admin.CompactType}
1529    * @return the current compaction state
1530    * @throws IOException if a remote or network exception occurs
1531    */
1532   AdminProtos.GetRegionInfoResponse.CompactionState getCompactionState(final TableName tableName,
1533       CompactType compactType) throws IOException;
1534 
1535   /**
1536    * Get Backup Admin interface 
1537    * @return backup admin object
1538    * @throws IOException exception
1539    */
1540   BackupAdmin getBackupAdmin() throws IOException;
1541   
1542   /**
1543    * Currently, there are only two compact types:
1544    * {@code NORMAL} means do store files compaction;
1545    * {@code MOB} means do mob files compaction.
1546    * */
1547 
1548   @InterfaceAudience.Public
1549   @InterfaceStability.Unstable
1550   public enum CompactType {
1551 
1552     NORMAL    (0),
1553     MOB       (1);
1554 
1555     CompactType(int value) {}
1556   }
1557 
1558   /**
1559    * Turn the Split or Merge switches on or off.
1560    *
1561    * @param enabled enabled or not
1562    * @param synchronous If true, it waits until current split() call, if outstanding, to return.
1563    * @param switchTypes switchType list {@link MasterSwitchType}
1564    * @return Previous switch value array
1565    */
1566   boolean[] setSplitOrMergeEnabled(final boolean enabled, final boolean synchronous,
1567                                    final MasterSwitchType... switchTypes) throws IOException;
1568 
1569   /**
1570    * Query the current state of the switch
1571    *
1572    * @return true if the switch is enabled, false otherwise.
1573    */
1574   boolean isSplitOrMergeEnabled(final MasterSwitchType switchType) throws IOException;
1575 
1576   @InterfaceAudience.Public
1577   @InterfaceStability.Evolving
1578   public enum MasterSwitchType {
1579     SPLIT,
1580     MERGE
1581   }
1582   
1583 }