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.Collection;
023import java.util.EnumSet;
024import java.util.List;
025import java.util.Map;
026import java.util.Set;
027import java.util.concurrent.Future;
028import java.util.regex.Pattern;
029import org.apache.hadoop.conf.Configuration;
030import org.apache.hadoop.hbase.Abortable;
031import org.apache.hadoop.hbase.CacheEvictionStats;
032import org.apache.hadoop.hbase.ClusterMetrics;
033import org.apache.hadoop.hbase.ClusterMetrics.Option;
034import org.apache.hadoop.hbase.ClusterStatus;
035import org.apache.hadoop.hbase.HRegionInfo;
036import org.apache.hadoop.hbase.HTableDescriptor;
037import org.apache.hadoop.hbase.NamespaceDescriptor;
038import org.apache.hadoop.hbase.NamespaceNotFoundException;
039import org.apache.hadoop.hbase.RegionMetrics;
040import org.apache.hadoop.hbase.ServerName;
041import org.apache.hadoop.hbase.TableExistsException;
042import org.apache.hadoop.hbase.TableName;
043import org.apache.hadoop.hbase.TableNotFoundException;
044import org.apache.hadoop.hbase.client.replication.TableCFs;
045import org.apache.hadoop.hbase.client.security.SecurityCapability;
046import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel;
047import org.apache.hadoop.hbase.quotas.QuotaFilter;
048import org.apache.hadoop.hbase.quotas.QuotaRetriever;
049import org.apache.hadoop.hbase.quotas.QuotaSettings;
050import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshotView;
051import org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException;
052import org.apache.hadoop.hbase.replication.ReplicationException;
053import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
054import org.apache.hadoop.hbase.replication.ReplicationPeerDescription;
055import org.apache.hadoop.hbase.security.access.GetUserPermissionsRequest;
056import org.apache.hadoop.hbase.security.access.Permission;
057import org.apache.hadoop.hbase.security.access.UserPermission;
058import org.apache.hadoop.hbase.snapshot.HBaseSnapshotException;
059import org.apache.hadoop.hbase.snapshot.RestoreSnapshotException;
060import org.apache.hadoop.hbase.snapshot.SnapshotCreationException;
061import org.apache.hadoop.hbase.snapshot.UnknownSnapshotException;
062import org.apache.hadoop.hbase.util.Bytes;
063import org.apache.hadoop.hbase.util.Pair;
064import org.apache.yetus.audience.InterfaceAudience;
065
066/**
067 * The administrative API for HBase. Obtain an instance from {@link Connection#getAdmin()} and
068 * call {@link #close()} when done.
069 * <p>Admin can be used to create, drop, list, enable and disable and otherwise modify tables,
070 * as well as perform other administrative operations.
071 *
072 * @see ConnectionFactory
073 * @see Connection
074 * @see Table
075 * @since 0.99.0
076 */
077@InterfaceAudience.Public
078public interface Admin extends Abortable, Closeable {
079  int getOperationTimeout();
080
081  @Override
082  void abort(String why, Throwable e);
083
084  @Override
085  boolean isAborted();
086
087  /**
088   * @return Connection used by this object.
089   */
090  Connection getConnection();
091
092  /**
093   * @param tableName Table to check.
094   * @return <code>true</code> if table exists already.
095   * @throws IOException
096   */
097  boolean tableExists(TableName tableName) throws IOException;
098
099  /**
100   * List all the userspace tables.
101   *
102   * @return an array of read-only HTableDescriptors
103   * @throws IOException if a remote or network exception occurs
104   * @deprecated since 2.0 version and will be removed in 3.0 version.
105   *             Use {@link #listTableDescriptors()}.
106   * @see #listTableDescriptors()
107   */
108  @Deprecated
109  HTableDescriptor[] listTables() throws IOException;
110
111  /**
112   * List all the userspace tables.
113   *
114   * @return a list of TableDescriptors
115   * @throws IOException if a remote or network exception occurs
116   */
117  List<TableDescriptor> listTableDescriptors() throws IOException;
118
119  /**
120   * List all the userspace tables that match the given pattern.
121   *
122   * @param pattern The compiled regular expression to match against
123   * @return an array of read-only HTableDescriptors
124   * @throws IOException if a remote or network exception occurs
125   * @see #listTables()
126   * @deprecated since 2.0 version and will be removed in 3.0 version.
127   *             Use {@link #listTableDescriptors(java.util.regex.Pattern)}.
128   * @see #listTableDescriptors(Pattern)
129   */
130  @Deprecated
131  HTableDescriptor[] listTables(Pattern pattern) throws IOException;
132
133  /**
134   * List all the userspace tables that match the given pattern.
135   *
136   * @param pattern The compiled regular expression to match against
137   * @return a list of TableDescriptors
138   * @throws IOException if a remote or network exception occurs
139   * @see #listTables()
140   */
141  List<TableDescriptor> listTableDescriptors(Pattern pattern) throws IOException;
142
143  /**
144   * List all the userspace tables matching the given regular expression.
145   *
146   * @param regex The regular expression to match against
147   * @return a list of read-only HTableDescriptors
148   * @throws IOException if a remote or network exception occurs
149   * @see #listTableDescriptors(Pattern)
150   * @deprecated since 2.0 version and will be removed in 3.0 version. Use
151   *             {@link #listTableDescriptors(Pattern)} instead.
152   */
153  @Deprecated
154  HTableDescriptor[] listTables(String regex) throws IOException;
155
156  /**
157   * List all the tables matching the given pattern.
158   *
159   * @param pattern The compiled regular expression to match against
160   * @param includeSysTables <code>false</code> to match only against userspace tables
161   * @return an array of read-only HTableDescriptors
162   * @throws IOException if a remote or network exception occurs
163   * @see #listTables()
164   * @deprecated since 2.0 version and will be removed in 3.0 version.
165   *             Use {@link #listTableDescriptors(java.util.regex.Pattern, boolean)}.
166   * @see #listTableDescriptors(java.util.regex.Pattern, boolean)
167   */
168  @Deprecated
169  HTableDescriptor[] listTables(Pattern pattern, boolean includeSysTables)
170      throws IOException;
171
172  /**
173   * List all the tables matching the given pattern.
174   *
175   * @param pattern The compiled regular expression to match against
176   * @param includeSysTables <code>false</code> to match only against userspace tables
177   * @return a list of TableDescriptors
178   * @throws IOException if a remote or network exception occurs
179   * @see #listTables()
180   */
181  List<TableDescriptor> listTableDescriptors(Pattern pattern, boolean includeSysTables)
182      throws IOException;
183
184  /**
185   * List all the tables matching the given pattern.
186   *
187   * @param regex The regular expression to match against
188   * @param includeSysTables <code>false</code> to match only against userspace tables
189   * @return an array of read-only HTableDescriptors
190   * @throws IOException if a remote or network exception occurs
191   * @see #listTables(java.util.regex.Pattern, boolean)
192   * @deprecated since 2.0 version and will be removed in 3.0 version.
193   *             Use {@link #listTableDescriptors(Pattern, boolean)}.
194   */
195  @Deprecated
196  HTableDescriptor[] listTables(String regex, boolean includeSysTables)
197      throws IOException;
198
199  /**
200   * List all of the names of userspace tables.
201   *
202   * @return TableName[] table names
203   * @throws IOException if a remote or network exception occurs
204   */
205  TableName[] listTableNames() throws IOException;
206
207  /**
208   * List all of the names of userspace tables.
209   * @param pattern The regular expression to match against
210   * @return array of table names
211   * @throws IOException if a remote or network exception occurs
212   */
213  TableName[] listTableNames(Pattern pattern) throws IOException;
214
215  /**
216   * List all of the names of userspace tables.
217   * @param regex The regular expression to match against
218   * @return TableName[] table names
219   * @throws IOException if a remote or network exception occurs
220   * @deprecated since 2.0 version and will be removed in 3.0 version. Use
221   *             {@link #listTableNames(Pattern)} instead.
222   */
223  @Deprecated
224  TableName[] listTableNames(String regex) throws IOException;
225
226  /**
227   * List all of the names of userspace tables.
228   * @param pattern The regular expression to match against
229   * @param includeSysTables <code>false</code> to match only against userspace tables
230   * @return TableName[] table names
231   * @throws IOException if a remote or network exception occurs
232   */
233  TableName[] listTableNames(Pattern pattern, boolean includeSysTables)
234      throws IOException;
235
236  /**
237   * List all of the names of userspace tables.
238   * @param regex The regular expression to match against
239   * @param includeSysTables <code>false</code> to match only against userspace tables
240   * @return TableName[] table names
241   * @throws IOException if a remote or network exception occurs
242   * @deprecated since 2.0 version and will be removed in 3.0 version. Use
243   *             {@link #listTableNames(Pattern, boolean)} instead.
244   */
245  @Deprecated
246  TableName[] listTableNames(String regex, boolean includeSysTables)
247      throws IOException;
248
249  /**
250   * Get a table descriptor.
251   *
252   * @param tableName as a {@link TableName}
253   * @return the read-only tableDescriptor
254   * @throws org.apache.hadoop.hbase.TableNotFoundException
255   * @throws IOException if a remote or network exception occurs
256   * @deprecated since 2.0 version and will be removed in 3.0 version.
257   *             Use {@link #getDescriptor(TableName)}.
258   */
259  @Deprecated
260  HTableDescriptor getTableDescriptor(TableName tableName)
261      throws TableNotFoundException, IOException;
262
263  /**
264   * Get a table descriptor.
265   *
266   * @param tableName as a {@link TableName}
267   * @return the tableDescriptor
268   * @throws org.apache.hadoop.hbase.TableNotFoundException
269   * @throws IOException if a remote or network exception occurs
270   */
271  TableDescriptor getDescriptor(TableName tableName)
272      throws TableNotFoundException, IOException;
273
274  /**
275   * Creates a new table. Synchronous operation.
276   *
277   * @param desc table descriptor for table
278   * @throws IllegalArgumentException if the table name is reserved
279   * @throws org.apache.hadoop.hbase.MasterNotRunningException if master is not running
280   * @throws org.apache.hadoop.hbase.TableExistsException if table already exists (If concurrent
281   * threads, the table may have been created between test-for-existence and attempt-at-creation).
282   * @throws IOException if a remote or network exception occurs
283   */
284  void createTable(TableDescriptor desc) throws IOException;
285
286  /**
287   * Creates a new table with the specified number of regions.  The start key specified will become
288   * the end key of the first region of the table, and the end key specified will become the start
289   * key of the last region of the table (the first region has a null start key and the last region
290   * has a null end key). BigInteger math will be used to divide the key range specified into enough
291   * segments to make the required number of total regions. Synchronous operation.
292   *
293   * @param desc table descriptor for table
294   * @param startKey beginning of key range
295   * @param endKey end of key range
296   * @param numRegions the total number of regions to create
297   * @throws IllegalArgumentException if the table name is reserved
298   * @throws org.apache.hadoop.hbase.MasterNotRunningException if master is not running
299   * @throws org.apache.hadoop.hbase.TableExistsException if table already exists (If concurrent
300   * threads, the table may have been created between test-for-existence and attempt-at-creation).
301   */
302  void createTable(TableDescriptor desc, byte[] startKey, byte[] endKey, int numRegions)
303      throws IOException;
304
305  /**
306   * Creates a new table with an initial set of empty regions defined by the specified split keys.
307   * The total number of regions created will be the number of split keys plus one. Synchronous
308   * operation. Note : Avoid passing empty split key.
309   *
310   * @param desc table descriptor for table
311   * @param splitKeys array of split keys for the initial regions of the table
312   * @throws IllegalArgumentException if the table name is reserved, if the split keys are repeated
313   * and if the split key has empty byte array.
314   * @throws org.apache.hadoop.hbase.MasterNotRunningException if master is not running
315   * @throws org.apache.hadoop.hbase.TableExistsException if table already exists (If concurrent
316   * threads, the table may have been created between test-for-existence and attempt-at-creation).
317   * @throws IOException
318   */
319  void createTable(TableDescriptor desc, byte[][] splitKeys) throws IOException;
320
321  /**
322   * Creates a new table but does not block and wait for it to come online. You can use
323   * Future.get(long, TimeUnit) to wait on the operation to complete. It may throw
324   * ExecutionException if there was an error while executing the operation or TimeoutException in
325   * case the wait timeout was not long enough to allow the operation to complete.
326   * <p/>
327   * Throws IllegalArgumentException Bad table name, if the split keys are repeated and if the split
328   * key has empty byte array.
329   * @param desc table descriptor for table
330   * @throws IOException if a remote or network exception occurs
331   * @return the result of the async creation. You can use Future.get(long, TimeUnit) to wait on the
332   *         operation to complete.
333   */
334  Future<Void> createTableAsync(TableDescriptor desc) throws IOException;
335
336  /**
337   * Creates a new table but does not block and wait for it to come online. You can use
338   * Future.get(long, TimeUnit) to wait on the operation to complete. It may throw
339   * ExecutionException if there was an error while executing the operation or TimeoutException in
340   * case the wait timeout was not long enough to allow the operation to complete.
341   * <p/>
342   * Throws IllegalArgumentException Bad table name, if the split keys are repeated and if the split
343   * key has empty byte array.
344   * @param desc table descriptor for table
345   * @param splitKeys keys to check if the table has been created with all split keys
346   * @throws IOException if a remote or network exception occurs
347   * @return the result of the async creation. You can use Future.get(long, TimeUnit) to wait on the
348   *         operation to complete.
349   */
350  Future<Void> createTableAsync(TableDescriptor desc, byte[][] splitKeys) throws IOException;
351
352  /**
353   * Deletes a table. Synchronous operation.
354   *
355   * @param tableName name of table to delete
356   * @throws IOException if a remote or network exception occurs
357   */
358  void deleteTable(TableName tableName) throws IOException;
359
360  /**
361   * Deletes the table but does not block and wait for it to be completely removed.
362   * You can use Future.get(long, TimeUnit) to wait on the operation to complete.
363   * It may throw ExecutionException if there was an error while executing the operation
364   * or TimeoutException in case the wait timeout was not long enough to allow the
365   * operation to complete.
366   *
367   * @param tableName name of table to delete
368   * @throws IOException if a remote or network exception occurs
369   * @return the result of the async delete. You can use Future.get(long, TimeUnit)
370   *    to wait on the operation to complete.
371   */
372  Future<Void> deleteTableAsync(TableName tableName) throws IOException;
373
374  /**
375   * Deletes tables matching the passed in pattern and wait on completion. Warning: Use this method
376   * carefully, there is no prompting and the effect is immediate. Consider using {@link
377   * #listTableDescriptors(Pattern)}
378   * and {@link #deleteTable(org.apache.hadoop.hbase.TableName)}
379   *
380   * @param regex The regular expression to match table names against
381   * @return Table descriptors for tables that couldn't be deleted.
382   *         The return htds are read-only
383   * @throws IOException
384   * @see #deleteTables(java.util.regex.Pattern)
385   * @see #deleteTable(org.apache.hadoop.hbase.TableName)
386   * @deprecated since 2.0 version and will be removed in 3.0 version
387   *             This is just a trivial helper method without any magic.
388   *             Consider using {@link #listTableDescriptors(Pattern)}
389   *             and {@link #deleteTable(TableName)}
390   */
391  @Deprecated
392  HTableDescriptor[] deleteTables(String regex) throws IOException;
393
394  /**
395   * Delete tables matching the passed in pattern and wait on completion. Warning: Use this method
396   * carefully, there is no prompting and the effect is immediate. Consider using {@link
397   * #listTableDescriptors(java.util.regex.Pattern)} and
398   * {@link #deleteTable(org.apache.hadoop.hbase.TableName)}
399   *
400   * @param pattern The pattern to match table names against
401   * @return Table descriptors for tables that couldn't be deleted
402   *         The return htds are read-only
403   * @throws IOException
404   * @deprecated since 2.0 version and will be removed in 3.0 version
405   *             This is just a trivial helper method without any magic.
406   *             Consider using {@link #listTableDescriptors(java.util.regex.Pattern)}
407   *             and {@link #deleteTable(TableName)}
408   */
409  @Deprecated
410  HTableDescriptor[] deleteTables(Pattern pattern) throws IOException;
411
412  /**
413   * Truncate a table.
414   * Synchronous operation.
415   *
416   * @param tableName name of table to truncate
417   * @param preserveSplits <code>true</code> if the splits should be preserved
418   * @throws IOException if a remote or network exception occurs
419   */
420  void truncateTable(TableName tableName, boolean preserveSplits)
421      throws IOException;
422
423  /**
424   * Truncate the table but does not block and wait for it to be completely enabled. You can use
425   * Future.get(long, TimeUnit) to wait on the operation to complete. It may throw
426   * ExecutionException if there was an error while executing the operation or TimeoutException in
427   * case the wait timeout was not long enough to allow the operation to complete.
428   * @param tableName name of table to delete
429   * @param preserveSplits <code>true</code> if the splits should be preserved
430   * @throws IOException if a remote or network exception occurs
431   * @return the result of the async truncate. You can use Future.get(long, TimeUnit) to wait on the
432   *         operation to complete.
433   */
434  Future<Void> truncateTableAsync(TableName tableName, boolean preserveSplits)
435      throws IOException;
436
437  /**
438   * Enable a table.  May timeout.  Use {@link #enableTableAsync(org.apache.hadoop.hbase.TableName)}
439   * and {@link #isTableEnabled(org.apache.hadoop.hbase.TableName)} instead. The table has to be in
440   * disabled state for it to be enabled.
441   *
442   * @param tableName name of the table
443   * @throws IOException if a remote or network exception occurs There could be couple types of
444   * IOException TableNotFoundException means the table doesn't exist. TableNotDisabledException
445   * means the table isn't in disabled state.
446   * @see #isTableEnabled(org.apache.hadoop.hbase.TableName)
447   * @see #disableTable(org.apache.hadoop.hbase.TableName)
448   * @see #enableTableAsync(org.apache.hadoop.hbase.TableName)
449   */
450  void enableTable(TableName tableName) throws IOException;
451
452  /**
453   * Enable the table but does not block and wait for it to be completely enabled.
454   * You can use Future.get(long, TimeUnit) to wait on the operation to complete.
455   * It may throw ExecutionException if there was an error while executing the operation
456   * or TimeoutException in case the wait timeout was not long enough to allow the
457   * operation to complete.
458   *
459   * @param tableName name of table to delete
460   * @throws IOException if a remote or network exception occurs
461   * @return the result of the async enable. You can use Future.get(long, TimeUnit)
462   *    to wait on the operation to complete.
463   */
464  Future<Void> enableTableAsync(TableName tableName) throws IOException;
465
466  /**
467   * Enable tables matching the passed in pattern and wait on completion. Warning: Use this method
468   * carefully, there is no prompting and the effect is immediate. Consider using {@link
469   * #listTableDescriptors(Pattern)} and {@link #enableTable(org.apache.hadoop.hbase.TableName)}
470   *
471   * @param regex The regular expression to match table names against
472   * @throws IOException
473   * @return Table descriptors for tables that couldn't be enabled.
474   *         The return HTDs are read-only.
475   * @see #enableTables(java.util.regex.Pattern)
476   * @see #enableTable(org.apache.hadoop.hbase.TableName)
477   * @deprecated since 2.0 version and will be removed in 3.0 version
478   *             This is just a trivial helper method without any magic.
479   *             Consider using {@link #listTableDescriptors(Pattern)}
480   *             and {@link #enableTable(org.apache.hadoop.hbase.TableName)}
481   */
482  @Deprecated
483  HTableDescriptor[] enableTables(String regex) throws IOException;
484
485  /**
486   * Enable tables matching the passed in pattern and wait on completion. Warning: Use this method
487   * carefully, there is no prompting and the effect is immediate. Consider using {@link
488   * #listTableDescriptors(java.util.regex.Pattern)} and
489   * {@link #enableTable(org.apache.hadoop.hbase.TableName)}
490   *
491   * @param pattern The pattern to match table names against
492   * @throws IOException
493   * @return Table descriptors for tables that couldn't be enabled.
494   *         The return HTDs are read-only.
495   * @deprecated since 2.0 version and will be removed in 3.0 version
496   *             This is just a trivial helper method without any magic.
497   *             Consider using {@link #listTableDescriptors(java.util.regex.Pattern)}
498   *             and {@link #enableTable(org.apache.hadoop.hbase.TableName)}
499   */
500  @Deprecated
501  HTableDescriptor[] enableTables(Pattern pattern) throws IOException;
502
503  /**
504   * Disable the table but does not block and wait for it to be completely disabled.
505   * You can use Future.get(long, TimeUnit) to wait on the operation to complete.
506   * It may throw ExecutionException if there was an error while executing the operation
507   * or TimeoutException in case the wait timeout was not long enough to allow the
508   * operation to complete.
509   *
510   * @param tableName name of table to delete
511   * @throws IOException if a remote or network exception occurs
512   * @return the result of the async disable. You can use Future.get(long, TimeUnit)
513   *    to wait on the operation to complete.
514   */
515  Future<Void> disableTableAsync(TableName tableName) throws IOException;
516
517  /**
518   * Disable table and wait on completion.  May timeout eventually.  Use {@link
519   * #disableTableAsync(org.apache.hadoop.hbase.TableName)} and
520   * {@link #isTableDisabled(org.apache.hadoop.hbase.TableName)} instead. The table has to be in
521   * enabled state for it to be disabled.
522   *
523   * @param tableName
524   * @throws IOException There could be couple types of IOException TableNotFoundException means the
525   * table doesn't exist. TableNotEnabledException means the table isn't in enabled state.
526   */
527  void disableTable(TableName tableName) throws IOException;
528
529  /**
530   * Disable tables matching the passed in pattern and wait on completion. Warning: Use this method
531   * carefully, there is no prompting and the effect is immediate. Consider using {@link
532   * #listTableDescriptors(Pattern)} and {@link #disableTable(org.apache.hadoop.hbase.TableName)}
533   *
534   * @param regex The regular expression to match table names against
535   * @return Table descriptors for tables that couldn't be disabled
536   *         The return htds are read-only
537   * @throws IOException
538   * @see #disableTables(java.util.regex.Pattern)
539   * @see #disableTable(org.apache.hadoop.hbase.TableName)
540   * @deprecated since 2.0 version and will be removed in 3.0 version
541   *             This is just a trivial helper method without any magic.
542   *             Consider using {@link #listTableDescriptors(Pattern)}
543   *             and {@link #disableTable(org.apache.hadoop.hbase.TableName)}
544   */
545  @Deprecated
546  HTableDescriptor[] disableTables(String regex) throws IOException;
547
548  /**
549   * Disable tables matching the passed in pattern and wait on completion. Warning: Use this method
550   * carefully, there is no prompting and the effect is immediate. Consider using {@link
551   * #listTableDescriptors(java.util.regex.Pattern)} and
552   * {@link #disableTable(org.apache.hadoop.hbase.TableName)}
553   *
554   * @param pattern The pattern to match table names against
555   * @return Table descriptors for tables that couldn't be disabled
556   *         The return htds are read-only
557   * @throws IOException
558   * @deprecated since 2.0 version and will be removed in 3.0 version
559   *             This is just a trivial helper method without any magic.
560   *             Consider using {@link #listTableDescriptors(java.util.regex.Pattern)}
561   *             and {@link #disableTable(org.apache.hadoop.hbase.TableName)}
562   */
563  @Deprecated
564  HTableDescriptor[] disableTables(Pattern pattern) throws IOException;
565
566  /**
567   * @param tableName name of table to check
568   * @return <code>true</code> if table is on-line
569   * @throws IOException if a remote or network exception occurs
570   */
571  boolean isTableEnabled(TableName tableName) throws IOException;
572
573  /**
574   * @param tableName name of table to check
575   * @return <code>true</code> if table is off-line
576   * @throws IOException if a remote or network exception occurs
577   */
578  boolean isTableDisabled(TableName tableName) throws IOException;
579
580  /**
581   * @param tableName name of table to check
582   * @return <code>true</code> if all regions of the table are available
583   * @throws IOException if a remote or network exception occurs
584   */
585  boolean isTableAvailable(TableName tableName) throws IOException;
586
587  /**
588   * Use this api to check if the table has been created with the specified number of splitkeys
589   * which was used while creating the given table. Note : If this api is used after a table's
590   * region gets splitted, the api may return <code>false</code>.
591   *
592   * @param tableName name of table to check
593   * @param splitKeys keys to check if the table has been created with all split keys
594   * @throws IOException if a remote or network excpetion occurs
595   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #isTableAvailable(TableName)}
596   */
597  @Deprecated
598  boolean isTableAvailable(TableName tableName, byte[][] splitKeys) throws IOException;
599
600  /**
601   * Get the status of an <code>alter</code> (a.k.a <code>modify</code>) command - indicates how
602   * many regions have received the updated schema Asynchronous operation.
603   *
604   * @param tableName TableName instance
605   * @return Pair indicating the number of regions updated Pair.getFirst() is the regions that are
606   * yet to be updated Pair.getSecond() is the total number of regions of the table
607   * @throws IOException if a remote or network exception occurs
608   * @deprecated Since 2.0.0. Will be removed in 3.0.0. No longer needed now you get a Future
609   * on an operation.
610   */
611  @Deprecated
612  Pair<Integer, Integer> getAlterStatus(TableName tableName) throws IOException;
613
614  /**
615   * Get the status of <code>alter</code> (a.k.a <code>modify</code>) command - indicates how many
616   * regions have received the updated schema Asynchronous operation.
617   *
618   * @param tableName name of the table to get the status of
619   * @return Pair indicating the number of regions updated Pair.getFirst() is the regions that are
620   * yet to be updated Pair.getSecond() is the total number of regions of the table
621   * @throws IOException if a remote or network exception occurs
622   * @deprecated Since 2.0.0. Will be removed in 3.0.0. No longer needed now you get a Future
623   * on an operation.
624   */
625  @Deprecated
626  Pair<Integer, Integer> getAlterStatus(byte[] tableName) throws IOException;
627
628  /**
629   * Add a column family to an existing table. Synchronous operation.
630   * Use {@link #addColumnFamilyAsync(TableName, ColumnFamilyDescriptor)} instead because it
631   * returns a {@link Future} from which you can learn whether success or failure.
632   *
633   * @param tableName name of the table to add column family to
634   * @param columnFamily column family descriptor of column family to be added
635   * @throws IOException if a remote or network exception occurs
636   * @deprecated As of release 2.0.0.
637   *             This will be removed in HBase 3.0.0.
638   *             Use {@link #addColumnFamily(TableName, ColumnFamilyDescriptor)}.
639   */
640  @Deprecated
641  default void addColumn(TableName tableName, ColumnFamilyDescriptor columnFamily)
642    throws IOException {
643    addColumnFamily(tableName, columnFamily);
644  }
645
646  /**
647   * Add a column family to an existing table. Synchronous operation.
648   * Use {@link #addColumnFamilyAsync(TableName, ColumnFamilyDescriptor)} instead because it
649   * returns a {@link Future} from which you can learn whether success or failure.
650   *
651   * @param tableName name of the table to add column family to
652   * @param columnFamily column family descriptor of column family to be added
653   * @throws IOException if a remote or network exception occurs
654   */
655  void addColumnFamily(TableName tableName, ColumnFamilyDescriptor columnFamily)
656    throws IOException;
657
658  /**
659   * Add a column family to an existing table. Asynchronous operation.
660   * You can use Future.get(long, TimeUnit) to wait on the operation to complete.
661   * It may throw ExecutionException if there was an error while executing the operation
662   * or TimeoutException in case the wait timeout was not long enough to allow the
663   * operation to complete.
664   *
665   * @param tableName name of the table to add column family to
666   * @param columnFamily column family descriptor of column family to be added
667   * @throws IOException if a remote or network exception occurs
668   * @return the result of the async add column family. You can use Future.get(long, TimeUnit) to
669   *         wait on the operation to complete.
670   */
671  Future<Void> addColumnFamilyAsync(TableName tableName, ColumnFamilyDescriptor columnFamily)
672      throws IOException;
673
674  /**
675   * Delete a column family from a table. Synchronous operation.
676   *  Use {@link #deleteColumnFamily(TableName, byte[])} instead because it
677   * returns a {@link Future} from which you can learn whether success or failure.
678   *
679   * @param tableName name of table
680   * @param columnFamily name of column family to be deleted
681   * @throws IOException if a remote or network exception occurs
682   * @deprecated As of release 2.0.0.
683   *             This will be removed in HBase 3.0.0.
684   *             Use {@link #deleteColumnFamily(TableName, byte[])}}.
685   */
686  @Deprecated
687  void deleteColumn(TableName tableName, byte[] columnFamily) throws IOException;
688
689  /**
690   * Delete a column family from a table. Synchronous operation.
691   * Use {@link #deleteColumnFamily(TableName, byte[])} instead because it
692   * returns a {@link Future} from which you can learn whether success or failure.
693   * @param tableName name of table
694   * @param columnFamily name of column family to be deleted
695   * @throws IOException if a remote or network exception occurs
696   */
697  void deleteColumnFamily(TableName tableName, byte[] columnFamily) throws IOException;
698
699  /**
700   * Delete a column family from a table. Asynchronous operation.
701   * You can use Future.get(long, TimeUnit) to wait on the operation to complete.
702   * It may throw ExecutionException if there was an error while executing the operation
703   * or TimeoutException in case the wait timeout was not long enough to allow the
704   * operation to complete.
705   *
706   * @param tableName name of table
707   * @param columnFamily name of column family to be deleted
708   * @throws IOException if a remote or network exception occurs
709   * @return the result of the async delete column family. You can use Future.get(long, TimeUnit) to
710   *         wait on the operation to complete.
711   */
712  Future<Void> deleteColumnFamilyAsync(TableName tableName, byte[] columnFamily)
713      throws IOException;
714
715  /**
716   * Modify an existing column family on a table. Synchronous operation.
717   * Use {@link #modifyColumnFamilyAsync(TableName, ColumnFamilyDescriptor)} instead because it
718   * returns a {@link Future} from which you can learn whether success or failure.
719   * @param tableName name of table
720   * @param columnFamily new column family descriptor to use
721   * @throws IOException if a remote or network exception occurs
722   * @deprecated As of release 2.0.0.
723   *             This will be removed in HBase 3.0.0.
724   *             Use {@link #modifyColumnFamily(TableName, ColumnFamilyDescriptor)}.
725   */
726  @Deprecated
727  default void modifyColumn(TableName tableName, ColumnFamilyDescriptor columnFamily)
728      throws IOException {
729    modifyColumnFamily(tableName, columnFamily);
730  }
731
732  /**
733   * Modify an existing column family on a table. Synchronous operation.
734   * Use {@link #modifyColumnFamilyAsync(TableName, ColumnFamilyDescriptor)} instead because it
735   * returns a {@link Future} from which you can learn whether success or failure.
736   * @param tableName name of table
737   * @param columnFamily new column family descriptor to use
738   * @throws IOException if a remote or network exception occurs
739   */
740  void modifyColumnFamily(TableName tableName, ColumnFamilyDescriptor columnFamily)
741      throws IOException;
742
743  /**
744   * Modify an existing column family on a table. Asynchronous operation.
745   * You can use Future.get(long, TimeUnit) to wait on the operation to complete.
746   * It may throw ExecutionException if there was an error while executing the operation
747   * or TimeoutException in case the wait timeout was not long enough to allow the
748   * operation to complete.
749   *
750   * @param tableName name of table
751   * @param columnFamily new column family descriptor to use
752   * @throws IOException if a remote or network exception occurs
753   * @return the result of the async modify column family. You can use Future.get(long, TimeUnit) to
754   *         wait on the operation to complete.
755   */
756  Future<Void> modifyColumnFamilyAsync(TableName tableName, ColumnFamilyDescriptor columnFamily)
757      throws IOException;
758
759  /**
760   * Uses {@link #unassign(byte[], boolean)} to unassign the region. For expert-admins.
761   *
762   * @param regionname region name to close
763   * @param serverName Deprecated. Not used.
764   * @throws IOException if a remote or network exception occurs
765   * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
766   *             Use {@link #unassign(byte[], boolean)}.
767   */
768  @Deprecated
769  void closeRegion(String regionname, String serverName) throws IOException;
770
771  /**
772   * Uses {@link #unassign(byte[], boolean)} to unassign the region. For expert-admins.
773   *
774   * @param regionname region name to close
775   * @param serverName Deprecated. Not used.
776   * @throws IOException if a remote or network exception occurs
777   * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
778   *             Use {@link #unassign(byte[], boolean)}.
779   */
780  @Deprecated
781  void closeRegion(byte[] regionname, String serverName) throws IOException;
782
783  /**
784   * Uses {@link #unassign(byte[], boolean)} to unassign the region. For expert-admins.
785   *
786   * @param encodedRegionName The encoded region name; i.e. the hash that makes up the region name
787   * suffix: e.g. if regionname is
788   * <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>,
789   * then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>.
790   * @param serverName Deprecated. Not used.
791   * @return Deprecated. Returns <code>true</code> always.
792   * @throws IOException if a remote or network exception occurs
793   * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
794   *             Use {@link #unassign(byte[], boolean)}.
795   */
796  @Deprecated
797  boolean closeRegionWithEncodedRegionName(String encodedRegionName, String serverName)
798      throws IOException;
799
800  /**
801   * Used {@link #unassign(byte[], boolean)} to unassign the region. For expert-admins.
802   *
803   * @param sn Deprecated. Not used.
804   * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
805   *             (<a href="https://issues.apache.org/jira/browse/HBASE-18231">HBASE-18231</a>).
806   *             Use {@link #unassign(byte[], boolean)}.
807   */
808  @Deprecated
809  void closeRegion(final ServerName sn, final HRegionInfo hri) throws IOException;
810
811  /**
812   * Get all the online regions on a region server.
813   * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
814   *             (<a href="https://issues.apache.org/jira/browse/HBASE-17980">HBASE-17980</a>).
815   *             Use {@link #getRegions(ServerName sn)}.
816   */
817  @Deprecated
818  List<HRegionInfo> getOnlineRegions(ServerName sn) throws IOException;
819
820  /**
821   * Get all the online regions on a region server.
822   *
823   * @return List of {@link RegionInfo}
824   * @throws java.io.IOException
825   */
826  List<RegionInfo> getRegions(ServerName serverName) throws IOException;
827
828  /**
829   * Flush a table. Synchronous operation.
830   *
831   * @param tableName table to flush
832   * @throws IOException if a remote or network exception occurs
833   */
834  void flush(TableName tableName) throws IOException;
835
836  /**
837   * Flush an individual region. Synchronous operation.
838   *
839   * @param regionName region to flush
840   * @throws IOException if a remote or network exception occurs
841   */
842  void flushRegion(byte[] regionName) throws IOException;
843
844  /**
845   * Flush all regions on the region server. Synchronous operation.
846   * @param serverName the region server name to flush
847   * @throws IOException if a remote or network exception occurs
848   */
849  void flushRegionServer(ServerName serverName) throws IOException;
850
851  /**
852   * Compact a table. Asynchronous operation in that this method requests that a
853   * Compaction run and then it returns. It does not wait on the completion of Compaction
854   * (it can take a while).
855   *
856   * @param tableName table to compact
857   * @throws IOException if a remote or network exception occurs
858   */
859  void compact(TableName tableName) throws IOException;
860
861  /**
862   * Compact an individual region. Asynchronous operation in that this method requests that a
863   * Compaction run and then it returns. It does not wait on the completion of Compaction
864   * (it can take a while).
865   *
866   * @param regionName region to compact
867   * @throws IOException if a remote or network exception occurs
868   */
869  void compactRegion(byte[] regionName) throws IOException;
870
871  /**
872   * Compact a column family within a table. Asynchronous operation in that this method requests
873   * that a Compaction run and then it returns. It does not wait on the completion of Compaction
874   * (it can take a while).
875   *
876   * @param tableName table to compact
877   * @param columnFamily column family within a table
878   * @throws IOException if a remote or network exception occurs
879   */
880  void compact(TableName tableName, byte[] columnFamily)
881    throws IOException;
882
883  /**
884   * Compact a column family within a region. Asynchronous operation in that this method requests
885   * that a Compaction run and then it returns. It does not wait on the completion of Compaction
886   * (it can take a while).
887   *
888   * @param regionName region to compact
889   * @param columnFamily column family within a region
890   * @throws IOException if a remote or network exception occurs
891   */
892  void compactRegion(byte[] regionName, byte[] columnFamily)
893    throws IOException;
894
895  /**
896   * Compact a table.  Asynchronous operation in that this method requests that a
897   * Compaction run and then it returns. It does not wait on the completion of Compaction
898   * (it can take a while).
899   *
900   * @param tableName table to compact
901   * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
902   * @throws IOException if a remote or network exception occurs
903   * @throws InterruptedException
904   */
905  void compact(TableName tableName, CompactType compactType)
906    throws IOException, InterruptedException;
907
908  /**
909   * Compact a column family within a table.  Asynchronous operation in that this method
910   * requests that a Compaction run and then it returns. It does not wait on the
911   * completion of Compaction (it can take a while).
912   *
913   * @param tableName table to compact
914   * @param columnFamily column family within a table
915   * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
916   * @throws IOException if not a mob column family or if a remote or network exception occurs
917   * @throws InterruptedException
918   */
919  void compact(TableName tableName, byte[] columnFamily, CompactType compactType)
920    throws IOException, InterruptedException;
921
922  /**
923   * Major compact a table. Asynchronous operation in that this method requests
924   * that a Compaction run and then it returns. It does not wait on the completion of Compaction
925   * (it can take a while).
926   *
927   * @param tableName table to major compact
928   * @throws IOException if a remote or network exception occurs
929   */
930  void majorCompact(TableName tableName) throws IOException;
931
932  /**
933   * Major compact a table or an individual region. Asynchronous operation in that this method requests
934   * that a Compaction run and then it returns. It does not wait on the completion of Compaction
935   * (it can take a while).
936   *
937   * @param regionName region to major compact
938   * @throws IOException if a remote or network exception occurs
939   */
940  void majorCompactRegion(byte[] regionName) throws IOException;
941
942  /**
943   * Major compact a column family within a table. Asynchronous operation in that this method requests
944   * that a Compaction run and then it returns. It does not wait on the completion of Compaction
945   * (it can take a while).
946   *
947   * @param tableName table to major compact
948   * @param columnFamily column family within a table
949   * @throws IOException if a remote or network exception occurs
950   */
951  void majorCompact(TableName tableName, byte[] columnFamily)
952    throws IOException;
953
954  /**
955   * Major compact a column family within region. Asynchronous operation in that this method requests
956   * that a Compaction run and then it returns. It does not wait on the completion of Compaction
957   * (it can take a while).
958   *
959   * @param regionName egion to major compact
960   * @param columnFamily column family within a region
961   * @throws IOException if a remote or network exception occurs
962   */
963  void majorCompactRegion(byte[] regionName, byte[] columnFamily)
964    throws IOException;
965
966  /**
967   * Major compact a table.  Asynchronous operation in that this method requests that a
968   * Compaction run and then it returns. It does not wait on the completion of Compaction
969   * (it can take a while).
970   *
971   * @param tableName table to compact
972   * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
973   * @throws IOException if a remote or network exception occurs
974   * @throws InterruptedException
975   */
976  void majorCompact(TableName tableName, CompactType compactType)
977    throws IOException, InterruptedException;
978
979  /**
980   * Major compact a column family within a table.  Asynchronous operation in that this method requests that a
981   * Compaction run and then it returns. It does not wait on the completion of Compaction
982   * (it can take a while).
983   *
984   * @param tableName table to compact
985   * @param columnFamily column family within a table
986   * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
987   * @throws IOException if not a mob column family or if a remote or network exception occurs
988   * @throws InterruptedException
989   */
990  void majorCompact(TableName tableName, byte[] columnFamily, CompactType compactType)
991    throws IOException, InterruptedException;
992
993  /**
994   * Compact all regions on the region server. Asynchronous operation in that this method requests
995   * that a Compaction run and then it returns. It does not wait on the completion of Compaction (it
996   * can take a while).
997   * @param sn the region server name
998   * @param major if it's major compaction
999   * @throws IOException if a remote or network exception occurs
1000   * @throws InterruptedException
1001   * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. Use
1002   *             {@link #compactRegionServer(ServerName)} or
1003   *             {@link #majorCompactRegionServer(ServerName)}.
1004   */
1005  @Deprecated
1006  default void compactRegionServer(ServerName sn, boolean major) throws IOException,
1007      InterruptedException {
1008    if (major) {
1009      majorCompactRegionServer(sn);
1010    } else {
1011      compactRegionServer(sn);
1012    }
1013  }
1014
1015  /**
1016   * Turn the compaction on or off. Disabling compactions will also interrupt any currently ongoing
1017   * compactions. This state is ephemeral. The setting will be lost on restart. Compaction
1018   * can also be enabled/disabled by modifying configuration hbase.regionserver.compaction.enabled
1019   * in hbase-site.xml.
1020   *
1021   * @param switchState     Set to <code>true</code> to enable, <code>false</code> to disable.
1022   * @param serverNamesList list of region servers.
1023   * @return Previous compaction states for region servers
1024   */
1025  Map<ServerName, Boolean> compactionSwitch(boolean switchState, List<String> serverNamesList)
1026      throws IOException;
1027
1028  /**
1029   * Compact all regions on the region server. Asynchronous operation in that this method requests
1030   * that a Compaction run and then it returns. It does not wait on the completion of Compaction (it
1031   * can take a while).
1032   * @param serverName the region server name
1033   * @throws IOException if a remote or network exception occurs
1034   */
1035  void compactRegionServer(ServerName serverName) throws IOException;
1036
1037  /**
1038   * Major compact all regions on the region server. Asynchronous operation in that this method
1039   * requests that a Compaction run and then it returns. It does not wait on the completion of
1040   * Compaction (it can take a while).
1041   * @param serverName the region server name
1042   * @throws IOException if a remote or network exception occurs
1043   */
1044  void majorCompactRegionServer(ServerName serverName) throws IOException;
1045
1046  /**
1047   * Move the region <code>encodedRegionName</code> to a random server.
1048   * @param encodedRegionName The encoded region name; i.e. the hash that makes up the region name
1049   *          suffix: e.g. if regionname is
1050   *          <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>,
1051   *          then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>.
1052   * @throws IOException if we can't find a region named <code>encodedRegionName</code>
1053   */
1054  void move(byte[] encodedRegionName) throws IOException;
1055
1056  /**
1057   * Move the region <code>rencodedRegionName</code> to <code>destServerName</code>.
1058   * @param encodedRegionName The encoded region name; i.e. the hash that makes up the region name
1059   *          suffix: e.g. if regionname is
1060   *          <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>,
1061   *          then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>.
1062   * @param destServerName The servername of the destination regionserver. If passed the empty byte
1063   *          array we'll assign to a random server. A server name is made of host, port and
1064   *          startcode. Here is an example: <code> host187.example.com,60020,1289493121758</code>
1065   * @throws IOException if we can't find a region named <code>encodedRegionName</code>
1066   * @deprecated Use {@link #move(byte[], ServerName)} instead. And if you want to move the region
1067   *             to a random server, please use {@link #move(byte[])}.
1068   */
1069  @Deprecated
1070  default void move(byte[] encodedRegionName, byte[] destServerName) throws IOException {
1071    if (destServerName == null || destServerName.length == 0) {
1072      move(encodedRegionName);
1073    } else {
1074      move(encodedRegionName, ServerName.valueOf(Bytes.toString(destServerName)));
1075    }
1076  }
1077
1078  /**
1079   * Move the region <code>rencodedRegionName</code> to <code>destServerName</code>.
1080   * @param encodedRegionName The encoded region name; i.e. the hash that makes up the region name
1081   *          suffix: e.g. if regionname is
1082   *          <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>,
1083   *          then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>.
1084   * @param destServerName The servername of the destination regionserver. A server name is made of
1085   *          host, port and startcode. Here is an example:
1086   *          <code> host187.example.com,60020,1289493121758</code>
1087   * @throws IOException if we can't find a region named <code>encodedRegionName</code>
1088   */
1089  void move(byte[] encodedRegionName, ServerName destServerName) throws IOException;
1090
1091  /**
1092   * Assign a Region.
1093   * @param regionName Region name to assign.
1094   */
1095  void assign(byte[] regionName) throws IOException;
1096
1097  /**
1098   * Unassign a region from current hosting regionserver.  Region will then be assigned to a
1099   * regionserver chosen at random.  Region could be reassigned back to the same server.  Use {@link
1100   * #move(byte[], ServerName)} if you want to control the region movement.
1101   *
1102   * @param regionName Region to unassign. Will clear any existing RegionPlan if one found.
1103   * @param force If <code>true</code>, force unassign (Will remove region from regions-in-transition too if
1104   * present. If results in double assignment use hbck -fix to resolve. To be used by experts).
1105   */
1106  void unassign(byte[] regionName, boolean force)
1107      throws IOException;
1108
1109  /**
1110   * Offline specified region from master's in-memory state. It will not attempt to reassign the
1111   * region as in unassign. This API can be used when a region not served by any region server and
1112   * still online as per Master's in memory state. If this API is incorrectly used on active region
1113   * then master will loose track of that region. This is a special method that should be used by
1114   * experts or hbck.
1115   *
1116   * @param regionName Region to offline.
1117   * @throws IOException
1118   */
1119  void offline(byte[] regionName) throws IOException;
1120
1121  /**
1122   * Turn the load balancer on or off.
1123   *
1124   * @param synchronous If <code>true</code>, it waits until current balance() call, if
1125   * outstanding, to return.
1126   * @return Previous balancer value
1127   * @deprecated Since 2.0.0. Will be removed in 3.0.0.
1128   * Use {@link #balancerSwitch(boolean, boolean)} instead.
1129   */
1130  @Deprecated
1131  default boolean setBalancerRunning(boolean on, boolean synchronous) throws IOException {
1132    return balancerSwitch(on, synchronous);
1133  }
1134
1135  /**
1136   * Turn the load balancer on or off.
1137   * @param onOrOff Set to <code>true</code> to enable, <code>false</code> to disable.
1138   * @param synchronous If <code>true</code>, it waits until current balance() call, if
1139   * outstanding, to return.
1140   * @return Previous balancer value
1141   */
1142  boolean balancerSwitch(boolean onOrOff, boolean synchronous)
1143  throws IOException;
1144
1145  /**
1146   * Invoke the balancer.  Will run the balancer and if regions to move, it will go ahead and do the
1147   * reassignments.  Can NOT run for various reasons.  Check logs.
1148   *
1149   * @return <code>true</code> if balancer ran, <code>false</code> otherwise.
1150   * @deprecated Since 2.0.0. Will be removed in 3.0.0.
1151   * Use {@link #balance()} instead.
1152   */
1153  @Deprecated
1154  default boolean balancer() throws IOException {
1155    return balance();
1156  }
1157
1158  /**
1159   * Invoke the balancer.  Will run the balancer and if regions to move, it will go ahead and do the
1160   * reassignments.  Can NOT run for various reasons.  Check logs.
1161   *
1162   * @return <code>true</code> if balancer ran, <code>false</code> otherwise.
1163   */
1164  boolean balance() throws IOException;
1165
1166  /**
1167   * Invoke the balancer.  Will run the balancer and if regions to move, it will
1168   * go ahead and do the reassignments. If there is region in transition, force parameter of true
1169   * would still run balancer. Can *not* run for other reasons.  Check
1170   * logs.
1171   * @param force whether we should force balance even if there is region in transition
1172   * @return <code>true</code> if balancer ran, <code>false</code> otherwise.
1173   * @deprecated Since 2.0.0. Will be removed in 3.0.0.
1174   * Use {@link #balance(boolean)} instead.
1175   */
1176  @Deprecated
1177  default boolean balancer(boolean force) throws IOException {
1178    return balance(force);
1179  }
1180
1181  /**
1182   * Invoke the balancer.  Will run the balancer and if regions to move, it will
1183   * go ahead and do the reassignments. If there is region in transition, force parameter of true
1184   * would still run balancer. Can *not* run for other reasons.  Check
1185   * logs.
1186   * @param force whether we should force balance even if there is region in transition
1187   * @return <code>true</code> if balancer ran, <code>false</code> otherwise.
1188   */
1189  boolean balance(boolean force) throws IOException;
1190
1191  /**
1192   * Query the current state of the balancer.
1193   *
1194   * @return <code>true</code> if the balancer is enabled, <code>false</code> otherwise.
1195   */
1196  boolean isBalancerEnabled() throws IOException;
1197
1198  /**
1199   * Clear all the blocks corresponding to this table from BlockCache. For expert-admins.
1200   * Calling this API will drop all the cached blocks specific to a table from BlockCache.
1201   * This can significantly impact the query performance as the subsequent queries will
1202   * have to retrieve the blocks from underlying filesystem.
1203   *
1204   * @param tableName table to clear block cache
1205   * @return CacheEvictionStats related to the eviction
1206   * @throws IOException if a remote or network exception occurs
1207   */
1208  CacheEvictionStats clearBlockCache(final TableName tableName) throws IOException;
1209
1210  /**
1211   * Invoke region normalizer. Can NOT run for various reasons.  Check logs.
1212   *
1213   * @return <code>true</code> if region normalizer ran, <code>false</code> otherwise.
1214   */
1215  boolean normalize() throws IOException;
1216
1217  /**
1218   * Query the current state of the region normalizer.
1219   *
1220   * @return <code>true</code> if region normalizer is enabled, <code>false</code> otherwise.
1221   */
1222  boolean isNormalizerEnabled() throws IOException;
1223
1224  /**
1225   * Turn region normalizer on or off.
1226   *
1227   * @return Previous normalizer value
1228   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #normalizerSwitch(boolean)}}
1229   * instead.
1230   */
1231  @Deprecated
1232  default boolean setNormalizerRunning(boolean on) throws IOException {
1233    return normalizerSwitch(on);
1234  }
1235
1236  /**
1237   * Turn region normalizer on or off.
1238   *
1239   * @return Previous normalizer value
1240   */
1241  boolean normalizerSwitch (boolean on) throws IOException;
1242
1243  /**
1244   * Enable/Disable the catalog janitor.
1245   *
1246   * @param enable if <code>true</code> enables the catalog janitor
1247   * @return the previous state
1248   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #catalogJanitorSwitch(boolean)}}
1249   * instead.
1250   */
1251  @Deprecated
1252  default boolean enableCatalogJanitor(boolean enable) throws IOException {
1253    return catalogJanitorSwitch(enable);
1254  }
1255
1256  /**
1257   * Enable/Disable the catalog janitor/
1258   *
1259   * @param onOrOff if <code>true</code> enables the catalog janitor
1260   * @return the previous state
1261   */
1262  boolean catalogJanitorSwitch(boolean onOrOff) throws IOException;
1263
1264  /**
1265   * Ask for a scan of the catalog table.
1266   *
1267   * @return the number of entries cleaned
1268   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #runCatalogJanitor()}}
1269   * instead.
1270   */
1271  @Deprecated
1272  default int runCatalogScan() throws IOException {
1273    return runCatalogJanitor();
1274  }
1275
1276  /**
1277   * Ask for a scan of the catalog table.
1278   *
1279   * @return the number of entries cleaned
1280   */
1281  int runCatalogJanitor() throws IOException;
1282
1283  /**
1284   * Query on the catalog janitor state (Enabled/Disabled?).
1285   *
1286   */
1287  boolean isCatalogJanitorEnabled() throws IOException;
1288
1289  /**
1290   * Enable/Disable the cleaner chore.
1291   *
1292   * @param on if <code>true</code> enables the cleaner chore
1293   * @return the previous state
1294   * @throws IOException
1295   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #cleanerChoreSwitch(boolean)}}
1296   * instead.
1297   */
1298  @Deprecated
1299  default boolean setCleanerChoreRunning(boolean on) throws IOException {
1300    return cleanerChoreSwitch(on);
1301  }
1302
1303  /**
1304   * Enable/Disable the cleaner chore.
1305   *
1306   * @param onOrOff if <code>true</code> enables the cleaner chore
1307   * @return the previous state
1308   * @throws IOException
1309   */
1310  boolean cleanerChoreSwitch(boolean onOrOff) throws IOException;
1311
1312  /**
1313   * Ask for cleaner chore to run.
1314   *
1315   * @return <code>true</code> if cleaner chore ran, <code>false</code> otherwise
1316   * @throws IOException
1317   */
1318  boolean runCleanerChore() throws IOException;
1319
1320  /**
1321   * Query on the cleaner chore state (Enabled/Disabled?).
1322   *
1323   * @throws IOException
1324   */
1325  boolean isCleanerChoreEnabled() throws IOException;
1326
1327  /**
1328   * Merge two regions. Asynchronous operation.
1329   *
1330   * @param nameOfRegionA encoded or full name of region a
1331   * @param nameOfRegionB encoded or full name of region b
1332   * @param forcible <code>true</code> if do a compulsory merge, otherwise we will only merge two
1333   * adjacent regions
1334   * @throws IOException
1335   * @deprecated Since 2.0. Will be removed in 3.0. Use
1336   *     {@link #mergeRegionsAsync(byte[], byte[], boolean)} instead.
1337   */
1338  @Deprecated
1339  void mergeRegions(byte[] nameOfRegionA, byte[] nameOfRegionB,
1340      boolean forcible) throws IOException;
1341
1342
1343  /**
1344   * Merge two regions. Asynchronous operation.
1345   * @param nameOfRegionA encoded or full name of region a
1346   * @param nameOfRegionB encoded or full name of region b
1347   * @param forcible <code>true</code> if do a compulsory merge, otherwise we will only merge two
1348   *          adjacent regions
1349   */
1350  default Future<Void> mergeRegionsAsync(byte[] nameOfRegionA, byte[] nameOfRegionB,
1351      boolean forcible) throws IOException {
1352    byte[][] nameofRegionsToMerge = new byte[2][];
1353    nameofRegionsToMerge[0] = nameOfRegionA;
1354    nameofRegionsToMerge[1] = nameOfRegionB;
1355    return mergeRegionsAsync(nameofRegionsToMerge, forcible);
1356  }
1357
1358  /**
1359   * Merge regions. Asynchronous operation.
1360   * <p/>
1361   * You may get a {@code DoNotRetryIOException} if you pass more than two regions in but the master
1362   * does not support merging more than two regions. At least till 2.2.0, we still only support
1363   * merging two regions.
1364   * @param nameofRegionsToMerge encoded or full name of daughter regions
1365   * @param forcible <code>true</code> if do a compulsory merge, otherwise we will only merge
1366   *          adjacent regions
1367   */
1368  Future<Void> mergeRegionsAsync(byte[][] nameofRegionsToMerge, boolean forcible)
1369      throws IOException;
1370
1371  /**
1372   * Split a table. The method will execute split action for each region in table.
1373   * Asynchronous operation.
1374   * @param tableName table to split
1375   * @throws IOException if a remote or network exception occurs
1376   */
1377  void split(TableName tableName) throws IOException;
1378
1379  /**
1380   * Split an individual region. Asynchronous operation.
1381   *
1382   * @param regionName region to split
1383   * @throws IOException if a remote or network exception occurs
1384   * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
1385   *             Use {@link #splitRegionAsync(byte[], byte[])}.
1386   */
1387  @Deprecated
1388  void splitRegion(byte[] regionName) throws IOException;
1389
1390  /**
1391   * Split a table. Asynchronous operation.
1392   *
1393   * @param tableName table to split
1394   * @param splitPoint the explicit position to split on
1395   * @throws IOException if a remote or network exception occurs
1396   */
1397  void split(TableName tableName, byte[] splitPoint)
1398    throws IOException;
1399
1400  /**
1401   * Split an individual region. Asynchronous operation.
1402   *
1403   * @param regionName region to split
1404   * @param splitPoint the explicit position to split on
1405   * @throws IOException if a remote or network exception occurs
1406   * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
1407   *             Use {@link #splitRegionAsync(byte[], byte[])}.
1408   */
1409  @Deprecated
1410  void splitRegion(byte[] regionName, byte[] splitPoint)
1411    throws IOException;
1412
1413  /**
1414   * Split an individual region. Asynchronous operation.
1415   * @param regionName region to split
1416   * @throws IOException if a remote or network exception occurs
1417   */
1418  Future<Void> splitRegionAsync(byte[] regionName) throws IOException;
1419
1420  /**
1421   * Split an individual region. Asynchronous operation.
1422   * @param regionName region to split
1423   * @param splitPoint the explicit position to split on
1424   * @throws IOException if a remote or network exception occurs
1425   */
1426  Future<Void> splitRegionAsync(byte[] regionName, byte[] splitPoint)
1427    throws IOException;
1428
1429  /**
1430   * Modify an existing table, more IRB friendly version.
1431   *
1432   * @param tableName name of table.
1433   * @param td modified description of the table
1434   * @throws IOException if a remote or network exception occurs
1435   * @deprecated since 2.0 version and will be removed in 3.0 version.
1436   *             use {@link #modifyTable(TableDescriptor)}
1437   */
1438  @Deprecated
1439  void modifyTable(TableName tableName, TableDescriptor td)
1440      throws IOException;
1441
1442  /**
1443   * Modify an existing table, more IRB friendly version.
1444   * @param td modified description of the table
1445   * @throws IOException if a remote or network exception occurs
1446   */
1447  void modifyTable(TableDescriptor td) throws IOException;
1448
1449  /**
1450   * Modify an existing table, more IRB friendly version. Asynchronous operation.  This means that
1451   * it may be a while before your schema change is updated across all of the table.
1452   * You can use Future.get(long, TimeUnit) to wait on the operation to complete.
1453   * It may throw ExecutionException if there was an error while executing the operation
1454   * or TimeoutException in case the wait timeout was not long enough to allow the
1455   * operation to complete.
1456   *
1457   * @param tableName name of table.
1458   * @param td modified description of the table
1459   * @throws IOException if a remote or network exception occurs
1460   * @return the result of the async modify. You can use Future.get(long, TimeUnit) to wait on the
1461   *     operation to complete
1462   * @deprecated since 2.0 version and will be removed in 3.0 version.
1463   *             use {@link #modifyTableAsync(TableDescriptor)}
1464   */
1465  @Deprecated
1466  Future<Void> modifyTableAsync(TableName tableName, TableDescriptor td)
1467      throws IOException;
1468
1469  /**
1470   * Modify an existing table, more IRB (ruby) friendly version. Asynchronous operation. This means that
1471   * it may be a while before your schema change is updated across all of the table.
1472   * You can use Future.get(long, TimeUnit) to wait on the operation to complete.
1473   * It may throw ExecutionException if there was an error while executing the operation
1474   * or TimeoutException in case the wait timeout was not long enough to allow the
1475   * operation to complete.
1476   *
1477   * @param td description of the table
1478   * @throws IOException if a remote or network exception occurs
1479   * @return the result of the async modify. You can use Future.get(long, TimeUnit) to wait on the
1480   *     operation to complete
1481   */
1482  Future<Void> modifyTableAsync(TableDescriptor td)
1483      throws IOException;
1484
1485  /**
1486   * <p>
1487   * Shuts down the HBase cluster.
1488   * </p>
1489   * <p>
1490   * Notice that, a success shutdown call may ends with an error since the remote server has already
1491   * been shutdown.
1492   * </p>
1493   * @throws IOException if a remote or network exception occurs
1494   */
1495  void shutdown() throws IOException;
1496
1497  /**
1498   * <p>
1499   * Shuts down the current HBase master only. Does not shutdown the cluster.
1500   * </p>
1501   * <p>
1502   * Notice that, a success stopMaster call may ends with an error since the remote server has
1503   * already been shutdown.
1504   * </p>
1505   * @throws IOException if a remote or network exception occurs
1506   * @see #shutdown()
1507   */
1508  void stopMaster() throws IOException;
1509
1510  /**
1511   * Check whether Master is in maintenance mode.
1512   *
1513   * @throws IOException if a remote or network exception occurs
1514   */
1515  boolean isMasterInMaintenanceMode()  throws IOException;
1516
1517  /**
1518   * Stop the designated regionserver.
1519   *
1520   * @param hostnamePort Hostname and port delimited by a <code>:</code> as in
1521   * <code>example.org:1234</code>
1522   * @throws IOException if a remote or network exception occurs
1523   */
1524  void stopRegionServer(String hostnamePort) throws IOException;
1525
1526  /**
1527   * Get whole cluster status, containing status about:
1528   * <pre>
1529   * hbase version
1530   * cluster id
1531   * primary/backup master(s)
1532   * master's coprocessors
1533   * live/dead regionservers
1534   * balancer
1535   * regions in transition
1536   * </pre>
1537   * @return cluster status
1538   * @throws IOException if a remote or network exception occurs
1539   * @deprecated since 2.0 version and will be removed in 3.0 version.
1540   *             use {@link #getClusterMetrics()}
1541   */
1542  @Deprecated
1543  default ClusterStatus getClusterStatus() throws IOException {
1544    return new ClusterStatus(getClusterMetrics());
1545  }
1546
1547  /**
1548   * Get whole cluster metrics, containing status about:
1549   * <pre>
1550   * hbase version
1551   * cluster id
1552   * primary/backup master(s)
1553   * master's coprocessors
1554   * live/dead regionservers
1555   * balancer
1556   * regions in transition
1557   * </pre>
1558   * @return cluster metrics
1559   * @throws IOException if a remote or network exception occurs
1560   */
1561  default ClusterMetrics getClusterMetrics() throws IOException {
1562    return getClusterMetrics(EnumSet.allOf(ClusterMetrics.Option.class));
1563  }
1564
1565  /**
1566   * Get cluster status with a set of {@link Option} to get desired status.
1567   * @return cluster status
1568   * @throws IOException if a remote or network exception occurs
1569   */
1570  ClusterMetrics getClusterMetrics(EnumSet<Option> options) throws IOException;
1571
1572  /**
1573   * @return current master server name
1574   * @throws IOException if a remote or network exception occurs
1575   */
1576  default ServerName getMaster() throws IOException {
1577    return getClusterMetrics(EnumSet.of(Option.MASTER)).getMasterName();
1578  }
1579
1580  /**
1581   * @return current backup master list
1582   * @throws IOException if a remote or network exception occurs
1583   */
1584  default Collection<ServerName> getBackupMasters() throws IOException {
1585    return getClusterMetrics(EnumSet.of(Option.BACKUP_MASTERS)).getBackupMasterNames();
1586  }
1587
1588  /**
1589   * @return current live region servers list
1590   * @throws IOException if a remote or network exception occurs
1591   */
1592  default Collection<ServerName> getRegionServers() throws IOException {
1593    return getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet();
1594  }
1595
1596  /**
1597   * Get {@link RegionMetrics} of all regions hosted on a regionserver.
1598   *
1599   * @param serverName region server from which {@link RegionMetrics} is required.
1600   * @return a {@link RegionMetrics} list of all regions hosted on a region server
1601   * @throws IOException if a remote or network exception occurs
1602   */
1603  default List<RegionMetrics> getRegionMetrics(ServerName serverName) throws IOException {
1604    return getRegionMetrics(serverName, null);
1605  }
1606
1607  /**
1608   * Get {@link RegionMetrics} of all regions hosted on a regionserver for a table.
1609   *
1610   * @param serverName region server from which {@link RegionMetrics} is required.
1611   * @param tableName get {@link RegionMetrics} of regions belonging to the table
1612   * @return region metrics map of all regions of a table hosted on a region server
1613   * @throws IOException if a remote or network exception occurs
1614   */
1615  List<RegionMetrics> getRegionMetrics(ServerName serverName,
1616    TableName tableName) throws IOException;
1617
1618  /**
1619   * @return Configuration used by the instance.
1620   */
1621  Configuration getConfiguration();
1622
1623  /**
1624   * Create a new namespace. Blocks until namespace has been successfully created or an exception
1625   * is thrown.
1626   *
1627   * @param descriptor descriptor which describes the new namespace.
1628   */
1629  void createNamespace(NamespaceDescriptor descriptor)
1630  throws IOException;
1631
1632  /**
1633   * Create a new namespace.
1634   *
1635   * @param descriptor descriptor which describes the new namespace
1636   * @return the result of the async create namespace operation. Use Future.get(long, TimeUnit) to
1637   *  wait on the operation to complete.
1638   */
1639  Future<Void> createNamespaceAsync(NamespaceDescriptor descriptor)
1640  throws IOException;
1641
1642  /**
1643   * Modify an existing namespace.  Blocks until namespace has been successfully modified or an
1644   * exception is thrown.
1645   *
1646   * @param descriptor descriptor which describes the new namespace
1647   */
1648  void modifyNamespace(NamespaceDescriptor descriptor)
1649  throws IOException;
1650
1651  /**
1652   * Modify an existing namespace.
1653   *
1654   * @param descriptor descriptor which describes the new namespace
1655   * @return the result of the async modify namespace operation. Use Future.get(long, TimeUnit) to
1656   *  wait on the operation to complete.
1657   */
1658  Future<Void> modifyNamespaceAsync(NamespaceDescriptor descriptor)
1659  throws IOException;
1660
1661  /**
1662   * Delete an existing namespace. Only empty namespaces (no tables) can be removed.
1663   * Blocks until namespace has been successfully deleted or an
1664   * exception is thrown.
1665   *
1666   * @param name namespace name
1667   */
1668  void deleteNamespace(String name) throws IOException;
1669
1670  /**
1671   * Delete an existing namespace. Only empty namespaces (no tables) can be removed.
1672   *
1673   * @param name namespace name
1674   * @return the result of the async delete namespace operation. Use Future.get(long, TimeUnit) to
1675   *  wait on the operation to complete.
1676   */
1677  Future<Void> deleteNamespaceAsync(String name) throws IOException;
1678
1679  /**
1680   * Get a namespace descriptor by name.
1681   *
1682   * @param name name of namespace descriptor
1683   * @return A descriptor
1684   * @throws org.apache.hadoop.hbase.NamespaceNotFoundException
1685   * @throws IOException if a remote or network exception occurs
1686   */
1687  NamespaceDescriptor getNamespaceDescriptor(String name)
1688  throws NamespaceNotFoundException, IOException;
1689
1690  /**
1691   * List available namespace descriptors.
1692   *
1693   * @return List of descriptors
1694   */
1695  NamespaceDescriptor[] listNamespaceDescriptors()
1696  throws IOException;
1697
1698  /**
1699   * Get list of table descriptors by namespace.
1700   *
1701   * @param name namespace name
1702   * @return HTD[] the read-only tableDescriptors
1703   * @throws IOException
1704   * @deprecated since 2.0 version and will be removed in 3.0 version.
1705   *             use {@link #listTableDescriptorsByNamespace(byte[])}
1706   */
1707  @Deprecated
1708  HTableDescriptor[] listTableDescriptorsByNamespace(String name)
1709      throws IOException;
1710
1711  /**
1712   * Get list of table descriptors by namespace.
1713   *
1714   * @param name namespace name
1715   * @return returns a list of TableDescriptors
1716   * @throws IOException
1717   */
1718  List<TableDescriptor> listTableDescriptorsByNamespace(byte[] name)
1719      throws IOException;
1720
1721  /**
1722   * Get list of table names by namespace.
1723   *
1724   * @param name namespace name
1725   * @return The list of table names in the namespace
1726   * @throws IOException
1727   */
1728  TableName[] listTableNamesByNamespace(String name)
1729      throws IOException;
1730
1731  /**
1732   * Get the regions of a given table.
1733   *
1734   * @param tableName the name of the table
1735   * @return List of {@link HRegionInfo}.
1736   * @throws IOException
1737   * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
1738   *             (<a href="https://issues.apache.org/jira/browse/HBASE-17980">HBASE-17980</a>).
1739   *             Use {@link #getRegions(TableName)}.
1740   */
1741  @Deprecated
1742  List<HRegionInfo> getTableRegions(TableName tableName)
1743    throws IOException;
1744
1745  /**
1746   * Get the regions of a given table.
1747   *
1748   * @param tableName the name of the table
1749   * @return List of {@link RegionInfo}.
1750   * @throws IOException
1751   */
1752  List<RegionInfo> getRegions(TableName tableName) throws IOException;
1753
1754  @Override
1755  void close() throws IOException;
1756
1757  /**
1758   * Get tableDescriptors.
1759   *
1760   * @param tableNames List of table names
1761   * @return HTD[] the read-only tableDescriptors
1762   * @throws IOException if a remote or network exception occurs
1763   * @deprecated since 2.0 version and will be removed in 3.0 version.
1764   *             use {@link #listTableDescriptors(List)}
1765   */
1766  @Deprecated
1767  HTableDescriptor[] getTableDescriptorsByTableName(List<TableName> tableNames)
1768    throws IOException;
1769
1770  /**
1771   * Get tableDescriptors.
1772   *
1773   * @param tableNames List of table names
1774   * @return returns a list of TableDescriptors
1775   * @throws IOException if a remote or network exception occurs
1776   */
1777  List<TableDescriptor> listTableDescriptors(List<TableName> tableNames)
1778    throws IOException;
1779
1780  /**
1781   * Get tableDescriptors.
1782   *
1783   * @param names List of table names
1784   * @return HTD[] the read-only tableDescriptors
1785   * @throws IOException if a remote or network exception occurs
1786   * @deprecated since 2.0 version and will be removed in 3.0 version.
1787   *             use {@link #listTableDescriptors(List)}
1788   */
1789  @Deprecated
1790  HTableDescriptor[] getTableDescriptors(List<String> names)
1791    throws IOException;
1792
1793  /**
1794   * Abort a procedure.
1795   * Do not use. Usually it is ignored but if not, it can do more damage than good. See hbck2.
1796   * @param procId ID of the procedure to abort
1797   * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
1798   * @return <code>true</code> if aborted, <code>false</code> if procedure already completed or does not exist
1799   * @throws IOException
1800   * @deprecated Since 2.1.1 -- to be removed.
1801   */
1802  @Deprecated
1803  boolean abortProcedure(
1804      long procId,
1805      boolean mayInterruptIfRunning) throws IOException;
1806
1807  /**
1808   * Abort a procedure but does not block and wait for completion.
1809   * You can use Future.get(long, TimeUnit) to wait on the operation to complete.
1810   * It may throw ExecutionException if there was an error while executing the operation
1811   * or TimeoutException in case the wait timeout was not long enough to allow the
1812   * operation to complete.
1813   * Do not use. Usually it is ignored but if not, it can do more damage than good. See hbck2.
1814   *
1815   * @param procId ID of the procedure to abort
1816   * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
1817   * @return <code>true</code> if aborted, <code>false</code> if procedure already completed or does not exist
1818   * @throws IOException
1819   * @deprecated Since 2.1.1 -- to be removed.
1820   */
1821  @Deprecated
1822  Future<Boolean> abortProcedureAsync(
1823    long procId,
1824    boolean mayInterruptIfRunning) throws IOException;
1825
1826  /**
1827   * Get procedures.
1828   * @return procedure list in JSON
1829   * @throws IOException
1830   */
1831  String getProcedures() throws IOException;
1832
1833  /**
1834   * Get locks.
1835   * @return lock list in JSON
1836   * @throws IOException if a remote or network exception occurs
1837   */
1838  String getLocks() throws IOException;
1839
1840  /**
1841   * Roll the log writer. I.e. for filesystem based write ahead logs, start writing to a new file.
1842   *
1843   * Note that the actual rolling of the log writer is asynchronous and may not be complete when
1844   * this method returns. As a side effect of this call, the named region server may schedule
1845   * store flushes at the request of the wal.
1846   *
1847   * @param serverName The servername of the regionserver.
1848   * @throws IOException if a remote or network exception occurs
1849   * @throws org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException
1850   */
1851  void rollWALWriter(ServerName serverName) throws IOException, FailedLogCloseException;
1852
1853  /**
1854   * Helper that delegates to getClusterMetrics().getMasterCoprocessorNames().
1855   * @return an array of master coprocessors
1856   * @see org.apache.hadoop.hbase.ClusterMetrics#getMasterCoprocessorNames()
1857   * @deprecated since 2.0 version and will be removed in 3.0 version.
1858   *             use {@link #getMasterCoprocessorNames()}
1859   */
1860  @Deprecated
1861  default String[] getMasterCoprocessors() throws IOException {
1862    return getMasterCoprocessorNames().stream().toArray(size -> new String[size]);
1863  }
1864
1865  /**
1866   * Helper that delegates to getClusterMetrics().getMasterCoprocessorNames().
1867   * @return an array of master coprocessors
1868   * @see org.apache.hadoop.hbase.ClusterMetrics#getMasterCoprocessorNames()
1869   */
1870  default List<String> getMasterCoprocessorNames() throws IOException {
1871    return getClusterMetrics(EnumSet.of(Option.MASTER_COPROCESSORS))
1872      .getMasterCoprocessorNames();
1873  }
1874
1875  /**
1876   * Get the current compaction state of a table. It could be in a major compaction, a minor
1877   * compaction, both, or none.
1878   *
1879   * @param tableName table to examine
1880   * @return the current compaction state
1881   * @throws IOException if a remote or network exception occurs
1882   */
1883  CompactionState getCompactionState(TableName tableName) throws IOException;
1884
1885  /**
1886   * Get the current compaction state of a table. It could be in a compaction, or none.
1887   *
1888   * @param tableName table to examine
1889   * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
1890   * @return the current compaction state
1891   * @throws IOException if a remote or network exception occurs
1892   */
1893  CompactionState getCompactionState(TableName tableName,
1894    CompactType compactType) throws IOException;
1895
1896  /**
1897   * Get the current compaction state of region. It could be in a major compaction, a minor
1898   * compaction, both, or none.
1899   *
1900   * @param regionName region to examine
1901   * @return the current compaction state
1902   * @throws IOException if a remote or network exception occurs
1903   */
1904  CompactionState getCompactionStateForRegion(byte[] regionName) throws IOException;
1905
1906  /**
1907   * Get the timestamp of the last major compaction for the passed table
1908   *
1909   * The timestamp of the oldest HFile resulting from a major compaction of that table,
1910   * or 0 if no such HFile could be found.
1911   *
1912   * @param tableName table to examine
1913   * @return the last major compaction timestamp or 0
1914   * @throws IOException if a remote or network exception occurs
1915   */
1916  long getLastMajorCompactionTimestamp(TableName tableName) throws IOException;
1917
1918  /**
1919   * Get the timestamp of the last major compaction for the passed region.
1920   *
1921   * The timestamp of the oldest HFile resulting from a major compaction of that region,
1922   * or 0 if no such HFile could be found.
1923   *
1924   * @param regionName region to examine
1925   * @return the last major compaction timestamp or 0
1926   * @throws IOException if a remote or network exception occurs
1927   */
1928  long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException;
1929
1930  /**
1931   * Take a snapshot for the given table. If the table is enabled, a FLUSH-type snapshot will be
1932   * taken. If the table is disabled, an offline snapshot is taken. Snapshots are considered unique
1933   * based on <b>the name of the snapshot</b>. Attempts to take a snapshot with the same name (even
1934   * a different type or with different parameters) will fail with a {@link
1935   * org.apache.hadoop.hbase.snapshot.SnapshotCreationException} indicating the duplicate naming.
1936   * Snapshot names follow the same naming constraints as tables in HBase. See {@link
1937   * org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}.
1938   *
1939   * @param snapshotName name of the snapshot to be created
1940   * @param tableName name of the table for which snapshot is created
1941   * @throws IOException if a remote or network exception occurs
1942   * @throws org.apache.hadoop.hbase.snapshot.SnapshotCreationException if snapshot creation failed
1943   * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
1944   */
1945  void snapshot(String snapshotName, TableName tableName)
1946      throws IOException, SnapshotCreationException, IllegalArgumentException;
1947
1948  /**
1949   * Create a timestamp consistent snapshot for the given table. Snapshots are considered unique
1950   * based on <b>the name of the snapshot</b>. Attempts to take a snapshot with the same name (even
1951   * different type or with different parameters) will fail with a {@link SnapshotCreationException}
1952   * indicating the duplicate naming. Snapshot names follow the same naming constraints as tables in
1953   * HBase.
1954   *
1955   * @param snapshotName name of the snapshot to be created
1956   * @param tableName name of the table for which snapshot is created
1957   * @throws IOException if a remote or network exception occurs
1958   * @throws SnapshotCreationException if snapshot creation failed
1959   * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
1960   */
1961  void snapshot(byte[] snapshotName, TableName tableName)
1962      throws IOException, SnapshotCreationException, IllegalArgumentException;
1963
1964  /**
1965   * Create typed snapshot of the table. Snapshots are considered unique based on <b>the name of the
1966   * snapshot</b>. Attempts to take a snapshot with the same name (even a different type or with
1967   * different parameters) will fail with a {@link SnapshotCreationException} indicating the
1968   * duplicate naming. Snapshot names follow the same naming constraints as tables in HBase. See
1969   * {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}.
1970   *
1971   * @param snapshotName name to give the snapshot on the filesystem. Must be unique from all other
1972   * snapshots stored on the cluster
1973   * @param tableName name of the table to snapshot
1974   * @param type type of snapshot to take
1975   * @throws IOException we fail to reach the master
1976   * @throws SnapshotCreationException if snapshot creation failed
1977   * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
1978   */
1979  void snapshot(String snapshotName,
1980      TableName tableName,
1981      SnapshotType type) throws IOException, SnapshotCreationException,
1982      IllegalArgumentException;
1983
1984  /**
1985   * Take a snapshot and wait for the server to complete that snapshot (blocking). Only a single
1986   * snapshot should be taken at a time for an instance of HBase, or results may be undefined (you
1987   * can tell multiple HBase clusters to snapshot at the same time, but only one at a time for a
1988   * single cluster). Snapshots are considered unique based on <b>the name of the snapshot</b>.
1989   * Attempts to take a snapshot with the same name (even a different type or with different
1990   * parameters) will fail with a {@link SnapshotCreationException} indicating the duplicate naming.
1991   * Snapshot names follow the same naming constraints as tables in HBase. See {@link
1992   * org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}. You should probably
1993   * use {@link #snapshot(String, org.apache.hadoop.hbase.TableName)} or
1994   * {@link #snapshot(byte[], org.apache.hadoop.hbase.TableName)} unless you are sure about the type
1995   * of snapshot that you want to take.
1996   *
1997   * @param snapshot snapshot to take
1998   * @throws IOException or we lose contact with the master.
1999   * @throws SnapshotCreationException if snapshot failed to be taken
2000   * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
2001   */
2002  void snapshot(SnapshotDescription snapshot)
2003      throws IOException, SnapshotCreationException, IllegalArgumentException;
2004
2005  /**
2006   * Take a snapshot without waiting for the server to complete that snapshot (asynchronous) Only a
2007   * single snapshot should be taken at a time, or results may be undefined.
2008   *
2009   * @param snapshot snapshot to take
2010   * @throws IOException if the snapshot did not succeed or we lose contact with the master.
2011   * @throws SnapshotCreationException if snapshot creation failed
2012   * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
2013   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use
2014   * {@link #snapshotAsync(SnapshotDescription)} instead.
2015   */
2016  @Deprecated
2017  default void takeSnapshotAsync(SnapshotDescription snapshot)
2018  throws IOException, SnapshotCreationException {
2019    snapshotAsync(snapshot);
2020  }
2021
2022  /**
2023   * Take a snapshot without waiting for the server to complete that snapshot (asynchronous) Only a
2024   * single snapshot should be taken at a time, or results may be undefined.
2025   *
2026   * @param snapshot snapshot to take
2027   * @throws IOException if the snapshot did not succeed or we lose contact with the master.
2028   * @throws SnapshotCreationException if snapshot creation failed
2029   * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
2030   */
2031  void snapshotAsync(SnapshotDescription snapshot) throws IOException, SnapshotCreationException;
2032
2033  /**
2034   * Check the current state of the passed snapshot. There are three possible states: <ol>
2035   * <li>running - returns <tt>false</tt></li> <li>finished - returns <tt>true</tt></li>
2036   * <li>finished with error - throws the exception that caused the snapshot to fail</li> </ol> The
2037   * cluster only knows about the most recent snapshot. Therefore, if another snapshot has been
2038   * run/started since the snapshot you are checking, you will receive an {@link
2039   * org.apache.hadoop.hbase.snapshot.UnknownSnapshotException}.
2040   *
2041   * @param snapshot description of the snapshot to check
2042   * @return <tt>true</tt> if the snapshot is completed, <tt>false</tt> if the snapshot is still
2043   * running
2044   * @throws IOException if we have a network issue
2045   * @throws org.apache.hadoop.hbase.snapshot.HBaseSnapshotException if the snapshot failed
2046   * @throws org.apache.hadoop.hbase.snapshot.UnknownSnapshotException if the requested snapshot is
2047   * unknown
2048   */
2049  boolean isSnapshotFinished(SnapshotDescription snapshot)
2050      throws IOException, HBaseSnapshotException, UnknownSnapshotException;
2051
2052  /**
2053   * Restore the specified snapshot on the original table. (The table must be disabled) If the
2054   * "hbase.snapshot.restore.take.failsafe.snapshot" configuration property is set to <code>true</code>, a
2055   * snapshot of the current table is taken before executing the restore operation. In case of
2056   * restore failure, the failsafe snapshot will be restored. If the restore completes without
2057   * problem the failsafe snapshot is deleted.
2058   *
2059   * @param snapshotName name of the snapshot to restore
2060   * @throws IOException if a remote or network exception occurs
2061   * @throws org.apache.hadoop.hbase.snapshot.RestoreSnapshotException if snapshot failed to be
2062   * restored
2063   * @throws IllegalArgumentException if the restore request is formatted incorrectly
2064   */
2065  void restoreSnapshot(byte[] snapshotName) throws IOException, RestoreSnapshotException;
2066
2067  /**
2068   * Restore the specified snapshot on the original table. (The table must be disabled) If the
2069   * "hbase.snapshot.restore.take.failsafe.snapshot" configuration property is set to <code>true</code>, a
2070   * snapshot of the current table is taken before executing the restore operation. In case of
2071   * restore failure, the failsafe snapshot will be restored. If the restore completes without
2072   * problem the failsafe snapshot is deleted.
2073   *
2074   * @param snapshotName name of the snapshot to restore
2075   * @throws IOException if a remote or network exception occurs
2076   * @throws RestoreSnapshotException if snapshot failed to be restored
2077   * @throws IllegalArgumentException if the restore request is formatted incorrectly
2078   */
2079  void restoreSnapshot(String snapshotName) throws IOException, RestoreSnapshotException;
2080
2081  /**
2082   * Restore the specified snapshot on the original table. (The table must be disabled) If the
2083   * "hbase.snapshot.restore.take.failsafe.snapshot" configuration property is set to <code>true</code>, a
2084   * snapshot of the current table is taken before executing the restore operation. In case of
2085   * restore failure, the failsafe snapshot will be restored. If the restore completes without
2086   * problem the failsafe snapshot is deleted.
2087   *
2088   * @param snapshotName name of the snapshot to restore
2089   * @throws IOException if a remote or network exception occurs
2090   * @throws RestoreSnapshotException if snapshot failed to be restored
2091   * @return the result of the async restore snapshot. You can use Future.get(long, TimeUnit)
2092   *    to wait on the operation to complete.
2093   */
2094  Future<Void> restoreSnapshotAsync(String snapshotName)
2095      throws IOException, RestoreSnapshotException;
2096
2097  /**
2098   * Restore the specified snapshot on the original table. (The table must be disabled) If
2099   * 'takeFailSafeSnapshot' is set to <code>true</code>, a snapshot of the current table is taken before
2100   * executing the restore operation. In case of restore failure, the failsafe snapshot will be
2101   * restored. If the restore completes without problem the failsafe snapshot is deleted. The
2102   * failsafe snapshot name is configurable by using the property
2103   * "hbase.snapshot.restore.failsafe.name".
2104   *
2105   * @param snapshotName name of the snapshot to restore
2106   * @param takeFailSafeSnapshot <code>true</code> if the failsafe snapshot should be taken
2107   * @throws IOException if a remote or network exception occurs
2108   * @throws RestoreSnapshotException if snapshot failed to be restored
2109   * @throws IllegalArgumentException if the restore request is formatted incorrectly
2110   */
2111  void restoreSnapshot(byte[] snapshotName, boolean takeFailSafeSnapshot)
2112      throws IOException, RestoreSnapshotException;
2113
2114  /**
2115   * Restore the specified snapshot on the original table. (The table must be disabled) If
2116   * 'takeFailSafeSnapshot' is set to <code>true</code>, a snapshot of the current table is taken before
2117   * executing the restore operation. In case of restore failure, the failsafe snapshot will be
2118   * restored. If the restore completes without problem the failsafe snapshot is deleted. The
2119   * failsafe snapshot name is configurable by using the property
2120   * "hbase.snapshot.restore.failsafe.name".
2121   *
2122   * @param snapshotName name of the snapshot to restore
2123   * @param takeFailSafeSnapshot <code>true</code> if the failsafe snapshot should be taken
2124   * @throws IOException if a remote or network exception occurs
2125   * @throws RestoreSnapshotException if snapshot failed to be restored
2126   * @throws IllegalArgumentException if the restore request is formatted incorrectly
2127   */
2128  void restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot)
2129      throws IOException, RestoreSnapshotException;
2130
2131  /**
2132   * Restore the specified snapshot on the original table. (The table must be disabled) If
2133   * 'takeFailSafeSnapshot' is set to <code>true</code>, a snapshot of the current table is taken before
2134   * executing the restore operation. In case of restore failure, the failsafe snapshot will be
2135   * restored. If the restore completes without problem the failsafe snapshot is deleted. The
2136   * failsafe snapshot name is configurable by using the property
2137   * "hbase.snapshot.restore.failsafe.name".
2138   * @param snapshotName name of the snapshot to restore
2139   * @param takeFailSafeSnapshot <code>true</code> if the failsafe snapshot should be taken
2140   * @param restoreAcl <code>true</code> to restore acl of snapshot
2141   * @throws IOException if a remote or network exception occurs
2142   * @throws RestoreSnapshotException if snapshot failed to be restored
2143   * @throws IllegalArgumentException if the restore request is formatted incorrectly
2144   */
2145  void restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot,
2146      boolean restoreAcl) throws IOException, RestoreSnapshotException;
2147
2148  /**
2149   * Create a new table by cloning the snapshot content.
2150   *
2151   * @param snapshotName name of the snapshot to be cloned
2152   * @param tableName name of the table where the snapshot will be restored
2153   * @throws IOException if a remote or network exception occurs
2154   * @throws TableExistsException if table to be created already exists
2155   * @throws RestoreSnapshotException if snapshot failed to be cloned
2156   * @throws IllegalArgumentException if the specified table has not a valid name
2157   */
2158  void cloneSnapshot(byte[] snapshotName, TableName tableName)
2159      throws IOException, TableExistsException, RestoreSnapshotException;
2160
2161  /**
2162   * Create a new table by cloning the snapshot content.
2163   * @param snapshotName name of the snapshot to be cloned
2164   * @param tableName name of the table where the snapshot will be restored
2165   * @param restoreAcl <code>true</code> to clone acl into newly created table
2166   * @throws IOException if a remote or network exception occurs
2167   * @throws TableExistsException if table to be created already exists
2168   * @throws RestoreSnapshotException if snapshot failed to be cloned
2169   * @throws IllegalArgumentException if the specified table has not a valid name
2170   */
2171  void cloneSnapshot(String snapshotName, TableName tableName, boolean restoreAcl)
2172      throws IOException, TableExistsException, RestoreSnapshotException;
2173
2174  /**
2175   * Create a new table by cloning the snapshot content.
2176   *
2177   * @param snapshotName name of the snapshot to be cloned
2178   * @param tableName name of the table where the snapshot will be restored
2179   * @throws IOException if a remote or network exception occurs
2180   * @throws TableExistsException if table to be created already exists
2181   * @throws RestoreSnapshotException if snapshot failed to be cloned
2182   * @throws IllegalArgumentException if the specified table has not a valid name
2183   */
2184  void cloneSnapshot(String snapshotName, TableName tableName)
2185      throws IOException, TableExistsException, RestoreSnapshotException;
2186
2187  /**
2188   * Create a new table by cloning the snapshot content, but does not block
2189   * and wait for it to be completely cloned.
2190   * You can use Future.get(long, TimeUnit) to wait on the operation to complete.
2191   * It may throw ExecutionException if there was an error while executing the operation
2192   * or TimeoutException in case the wait timeout was not long enough to allow the
2193   * operation to complete.
2194   *
2195   * @param snapshotName name of the snapshot to be cloned
2196   * @param tableName name of the table where the snapshot will be restored
2197   * @throws IOException if a remote or network exception occurs
2198   * @throws TableExistsException if table to be cloned already exists
2199   * @return the result of the async clone snapshot. You can use Future.get(long, TimeUnit)
2200   *    to wait on the operation to complete.
2201   */
2202  Future<Void> cloneSnapshotAsync(String snapshotName, TableName tableName)
2203      throws IOException, TableExistsException;
2204
2205  /**
2206   * Execute a distributed procedure on a cluster.
2207   *
2208   * @param signature A distributed procedure is uniquely identified by its signature (default the
2209   * root ZK node name of the procedure).
2210   * @param instance The instance name of the procedure. For some procedures, this parameter is
2211   * optional.
2212   * @param props Property/Value pairs of properties passing to the procedure
2213   * @throws IOException
2214   */
2215  void execProcedure(String signature, String instance, Map<String, String> props)
2216      throws IOException;
2217
2218  /**
2219   * Execute a distributed procedure on a cluster.
2220   *
2221   * @param signature A distributed procedure is uniquely identified by its signature (default the
2222   * root ZK node name of the procedure).
2223   * @param instance The instance name of the procedure. For some procedures, this parameter is
2224   * optional.
2225   * @param props Property/Value pairs of properties passing to the procedure
2226   * @return data returned after procedure execution. null if no return data.
2227   * @throws IOException
2228   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use
2229   * {@link #execProcedureWithReturn(String, String, Map)} } instead.
2230   */
2231  @Deprecated
2232  default byte[] execProcedureWithRet(String signature, String instance, Map<String, String> props)
2233      throws IOException {
2234    return execProcedureWithReturn(signature, instance, props);
2235  }
2236
2237  /**
2238   * Execute a distributed procedure on a cluster.
2239   *
2240   * @param signature A distributed procedure is uniquely identified by its signature (default the
2241   * root ZK node name of the procedure).
2242   * @param instance The instance name of the procedure. For some procedures, this parameter is
2243   * optional.
2244   * @param props Property/Value pairs of properties passing to the procedure
2245   * @return data returned after procedure execution. null if no return data.
2246   * @throws IOException
2247   */
2248  byte[] execProcedureWithReturn(String signature, String instance, Map<String, String> props)
2249  throws IOException;
2250
2251  /**
2252   * Check the current state of the specified procedure. There are three possible states: <ol>
2253   * <li>running - returns <tt>false</tt></li> <li>finished - returns <tt>true</tt></li>
2254   * <li>finished with error - throws the exception that caused the procedure to fail</li> </ol>
2255   *
2256   * @param signature The signature that uniquely identifies a procedure
2257   * @param instance The instance name of the procedure
2258   * @param props Property/Value pairs of properties passing to the procedure
2259   * @return <code>true</code> if the specified procedure is finished successfully, <code>false</code> if it is still running
2260   * @throws IOException if the specified procedure finished with error
2261   */
2262  boolean isProcedureFinished(String signature, String instance, Map<String, String> props)
2263      throws IOException;
2264
2265  /**
2266   * List completed snapshots.
2267   *
2268   * @return a list of snapshot descriptors for completed snapshots
2269   * @throws IOException if a network error occurs
2270   */
2271  List<SnapshotDescription> listSnapshots() throws IOException;
2272
2273  /**
2274   * List all the completed snapshots matching the given regular expression.
2275   *
2276   * @param regex The regular expression to match against
2277   * @return list of SnapshotDescription
2278   * @throws IOException if a remote or network exception occurs
2279   * @deprecated since 2.0 version and will be removed in 3.0 version.
2280   *             Use {@link #listSnapshots(Pattern)} instead.
2281   */
2282  @Deprecated
2283  List<SnapshotDescription> listSnapshots(String regex) throws IOException;
2284
2285  /**
2286   * List all the completed snapshots matching the given pattern.
2287   *
2288   * @param pattern The compiled regular expression to match against
2289   * @return list of SnapshotDescription
2290   * @throws IOException if a remote or network exception occurs
2291   */
2292  List<SnapshotDescription> listSnapshots(Pattern pattern) throws IOException;
2293
2294  /**
2295   * List all the completed snapshots matching the given table name regular expression and snapshot
2296   * name regular expression.
2297   * @param tableNameRegex The table name regular expression to match against
2298   * @param snapshotNameRegex The snapshot name regular expression to match against
2299   * @return list of completed SnapshotDescription
2300   * @throws IOException if a remote or network exception occurs
2301   * @deprecated since 2.0 version and will be removed in 3.0 version.
2302   *             Use {@link #listTableSnapshots(Pattern, Pattern)} instead.
2303   */
2304  @Deprecated
2305  List<SnapshotDescription> listTableSnapshots(String tableNameRegex,
2306      String snapshotNameRegex) throws IOException;
2307
2308  /**
2309   * List all the completed snapshots matching the given table name regular expression and snapshot
2310   * name regular expression.
2311   * @param tableNamePattern The compiled table name regular expression to match against
2312   * @param snapshotNamePattern The compiled snapshot name regular expression to match against
2313   * @return list of completed SnapshotDescription
2314   * @throws IOException if a remote or network exception occurs
2315   */
2316  List<SnapshotDescription> listTableSnapshots(Pattern tableNamePattern,
2317      Pattern snapshotNamePattern) throws IOException;
2318
2319  /**
2320   * Delete an existing snapshot.
2321   *
2322   * @param snapshotName name of the snapshot
2323   * @throws IOException if a remote or network exception occurs
2324   */
2325  void deleteSnapshot(byte[] snapshotName) throws IOException;
2326
2327  /**
2328   * Delete an existing snapshot.
2329   *
2330   * @param snapshotName name of the snapshot
2331   * @throws IOException if a remote or network exception occurs
2332   */
2333  void deleteSnapshot(String snapshotName) throws IOException;
2334
2335  /**
2336   * Delete existing snapshots whose names match the pattern passed.
2337   *
2338   * @param regex The regular expression to match against
2339   * @throws IOException if a remote or network exception occurs
2340   * @deprecated since 2.0 version and will be removed in 3.0 version.
2341   *             Use {@link #deleteSnapshots(Pattern)} instead.
2342   */
2343  @Deprecated
2344  void deleteSnapshots(String regex) throws IOException;
2345
2346  /**
2347   * Delete existing snapshots whose names match the pattern passed.
2348   *
2349   * @param pattern pattern for names of the snapshot to match
2350   * @throws IOException if a remote or network exception occurs
2351   */
2352  void deleteSnapshots(Pattern pattern) throws IOException;
2353
2354  /**
2355   * Delete all existing snapshots matching the given table name regular expression and snapshot
2356   * name regular expression.
2357   * @param tableNameRegex The table name regular expression to match against
2358   * @param snapshotNameRegex The snapshot name regular expression to match against
2359   * @throws IOException if a remote or network exception occurs
2360   * @deprecated since 2.0 version and will be removed in 3.0 version.
2361   *             Use {@link #deleteTableSnapshots(Pattern, Pattern)} instead.
2362   */
2363  @Deprecated
2364  void deleteTableSnapshots(String tableNameRegex, String snapshotNameRegex) throws IOException;
2365
2366  /**
2367   * Delete all existing snapshots matching the given table name regular expression and snapshot
2368   * name regular expression.
2369   * @param tableNamePattern The compiled table name regular expression to match against
2370   * @param snapshotNamePattern The compiled snapshot name regular expression to match against
2371   * @throws IOException if a remote or network exception occurs
2372   */
2373  void deleteTableSnapshots(Pattern tableNamePattern, Pattern snapshotNamePattern)
2374      throws IOException;
2375
2376  /**
2377   * Apply the new quota settings.
2378   *
2379   * @param quota the quota settings
2380   * @throws IOException if a remote or network exception occurs
2381   */
2382  void setQuota(QuotaSettings quota) throws IOException;
2383
2384  /**
2385   * Return a QuotaRetriever to list the quotas based on the filter.
2386   * @param filter the quota settings filter
2387   * @return the quota retriever
2388   * @throws IOException if a remote or network exception occurs
2389   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #getQuota(QuotaFilter)}.
2390   */
2391  @Deprecated
2392  QuotaRetriever getQuotaRetriever(QuotaFilter filter) throws IOException;
2393
2394  /**
2395   * List the quotas based on the filter.
2396   * @param filter the quota settings filter
2397   * @return the QuotaSetting list
2398   * @throws IOException if a remote or network exception occurs
2399   */
2400  List<QuotaSettings> getQuota(QuotaFilter filter) throws IOException;
2401
2402  /**
2403   * Creates and returns a {@link com.google.protobuf.RpcChannel} instance connected to the active
2404   * master. <p> The obtained {@link com.google.protobuf.RpcChannel} instance can be used to access
2405   * a published coprocessor {@link com.google.protobuf.Service} using standard protobuf service
2406   * invocations: </p> <div style="background-color: #cccccc; padding: 2px">
2407   * <blockquote><pre>
2408   * CoprocessorRpcChannel channel = myAdmin.coprocessorService();
2409   * MyService.BlockingInterface service = MyService.newBlockingStub(channel);
2410   * MyCallRequest request = MyCallRequest.newBuilder()
2411   *     ...
2412   *     .build();
2413   * MyCallResponse response = service.myCall(null, request);
2414   * </pre></blockquote></div>
2415   *
2416   * @return A MasterCoprocessorRpcChannel instance
2417   */
2418  CoprocessorRpcChannel coprocessorService();
2419
2420
2421  /**
2422   * Creates and returns a {@link com.google.protobuf.RpcChannel} instance
2423   * connected to the passed region server.
2424   *
2425   * <p>
2426   * The obtained {@link com.google.protobuf.RpcChannel} instance can be used to access a published
2427   * coprocessor {@link com.google.protobuf.Service} using standard protobuf service invocations:
2428   * </p>
2429   *
2430   * <div style="background-color: #cccccc; padding: 2px">
2431   * <blockquote><pre>
2432   * CoprocessorRpcChannel channel = myAdmin.coprocessorService(serverName);
2433   * MyService.BlockingInterface service = MyService.newBlockingStub(channel);
2434   * MyCallRequest request = MyCallRequest.newBuilder()
2435   *     ...
2436   *     .build();
2437   * MyCallResponse response = service.myCall(null, request);
2438   * </pre></blockquote></div>
2439   *
2440   * @param serverName the server name to which the endpoint call is made
2441   * @return A RegionServerCoprocessorRpcChannel instance
2442   */
2443  CoprocessorRpcChannel coprocessorService(ServerName serverName);
2444
2445
2446  /**
2447   * Update the configuration and trigger an online config change
2448   * on the regionserver.
2449   * @param server : The server whose config needs to be updated.
2450   * @throws IOException
2451   */
2452  void updateConfiguration(ServerName server) throws IOException;
2453
2454
2455  /**
2456   * Update the configuration and trigger an online config change
2457   * on all the regionservers.
2458   * @throws IOException
2459   */
2460  void updateConfiguration() throws IOException;
2461
2462  /**
2463   * Get the info port of the current master if one is available.
2464   * @return master info port
2465   * @throws IOException
2466   */
2467  default int getMasterInfoPort() throws IOException {
2468    return getClusterMetrics(EnumSet.of(Option.MASTER_INFO_PORT)).getMasterInfoPort();
2469  }
2470
2471  /**
2472   * Return the set of supported security capabilities.
2473   * @throws IOException
2474   * @throws UnsupportedOperationException
2475   */
2476  List<SecurityCapability> getSecurityCapabilities() throws IOException;
2477
2478  /**
2479   * Turn the Split or Merge switches on or off.
2480   * @param enabled enabled or not
2481   * @param synchronous If <code>true</code>, it waits until current split() call, if outstanding,
2482   *          to return.
2483   * @param switchTypes switchType list {@link MasterSwitchType}
2484   * @return Previous switch value array
2485   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #splitSwitch(boolean, boolean)}
2486   *             or {@link #mergeSwitch(boolean, boolean)} instead.
2487   */
2488  @Deprecated
2489  default boolean[] setSplitOrMergeEnabled(boolean enabled, boolean synchronous,
2490      MasterSwitchType... switchTypes) throws IOException {
2491    boolean[] preValues = new boolean[switchTypes.length];
2492    for (int i = 0; i < switchTypes.length; i++) {
2493      switch (switchTypes[i]) {
2494        case SPLIT:
2495          preValues[i] = splitSwitch(enabled, synchronous);
2496          break;
2497        case MERGE:
2498          preValues[i] = mergeSwitch(enabled, synchronous);
2499          break;
2500        default:
2501          throw new UnsupportedOperationException("Unsupported switch type:" + switchTypes[i]);
2502      }
2503    }
2504    return preValues;
2505  }
2506
2507  /**
2508   * Turn the split switch on or off.
2509   * @param enabled enabled or not
2510   * @param synchronous If <code>true</code>, it waits until current split() call, if outstanding,
2511   *          to return.
2512   * @return Previous switch value
2513   */
2514  boolean splitSwitch(boolean enabled, boolean synchronous) throws IOException;
2515
2516  /**
2517   * Turn the merge switch on or off.
2518   * @param enabled enabled or not
2519   * @param synchronous If <code>true</code>, it waits until current merge() call, if outstanding,
2520   *          to return.
2521   * @return Previous switch value
2522   */
2523  boolean mergeSwitch(boolean enabled, boolean synchronous) throws IOException;
2524
2525  /**
2526   * Query the current state of the switch.
2527   *
2528   * @return <code>true</code> if the switch is enabled, <code>false</code> otherwise.
2529   * @deprecated Since 2.0.0. Will be removed in 3.0.0. Use
2530   * {@link #isSplitEnabled()} or {@link #isMergeEnabled()} instead.
2531   */
2532  @Deprecated
2533  default boolean isSplitOrMergeEnabled(MasterSwitchType switchType) throws IOException {
2534    switch (switchType) {
2535      case SPLIT:
2536        return isSplitEnabled();
2537      case MERGE:
2538        return isMergeEnabled();
2539      default:
2540        break;
2541    }
2542    throw new UnsupportedOperationException("Unsupported switch type:" + switchType);
2543  }
2544
2545  /**
2546   * Query the current state of the split switch.
2547   * @return <code>true</code> if the switch is enabled, <code>false</code> otherwise.
2548   */
2549  boolean isSplitEnabled() throws IOException;
2550
2551  /**
2552   * Query the current state of the merge switch.
2553   * @return <code>true</code> if the switch is enabled, <code>false</code> otherwise.
2554   */
2555  boolean isMergeEnabled() throws IOException;
2556
2557  /**
2558   * Add a new replication peer for replicating data to slave cluster.
2559   * @param peerId a short name that identifies the peer
2560   * @param peerConfig configuration for the replication peer
2561   * @throws IOException if a remote or network exception occurs
2562   */
2563  default void addReplicationPeer(String peerId, ReplicationPeerConfig peerConfig)
2564      throws IOException {
2565    addReplicationPeer(peerId, peerConfig, true);
2566  }
2567
2568  /**
2569   * Add a new replication peer for replicating data to slave cluster.
2570   * @param peerId a short name that identifies the peer
2571   * @param peerConfig configuration for the replication peer
2572   * @param enabled peer state, true if ENABLED and false if DISABLED
2573   * @throws IOException if a remote or network exception occurs
2574   */
2575  void addReplicationPeer(String peerId, ReplicationPeerConfig peerConfig, boolean enabled)
2576      throws IOException;
2577
2578  /**
2579   * Add a new replication peer but does not block and wait for it.
2580   * <p>
2581   * You can use Future.get(long, TimeUnit) to wait on the operation to complete. It may throw
2582   * ExecutionException if there was an error while executing the operation or TimeoutException in
2583   * case the wait timeout was not long enough to allow the operation to complete.
2584   * @param peerId a short name that identifies the peer
2585   * @param peerConfig configuration for the replication peer
2586   * @return the result of the async operation
2587   * @throws IOException IOException if a remote or network exception occurs
2588   */
2589  default Future<Void> addReplicationPeerAsync(String peerId, ReplicationPeerConfig peerConfig)
2590      throws IOException {
2591    return addReplicationPeerAsync(peerId, peerConfig, true);
2592  }
2593
2594  /**
2595   * Add a new replication peer but does not block and wait for it.
2596   * <p>
2597   * You can use Future.get(long, TimeUnit) to wait on the operation to complete. It may throw
2598   * ExecutionException if there was an error while executing the operation or TimeoutException in
2599   * case the wait timeout was not long enough to allow the operation to complete.
2600   * @param peerId a short name that identifies the peer
2601   * @param peerConfig configuration for the replication peer
2602   * @param enabled peer state, true if ENABLED and false if DISABLED
2603   * @return the result of the async operation
2604   * @throws IOException IOException if a remote or network exception occurs
2605   */
2606  Future<Void> addReplicationPeerAsync(String peerId, ReplicationPeerConfig peerConfig,
2607      boolean enabled) throws IOException;
2608
2609  /**
2610   * Remove a peer and stop the replication.
2611   * @param peerId a short name that identifies the peer
2612   * @throws IOException if a remote or network exception occurs
2613   */
2614  void removeReplicationPeer(String peerId) throws IOException;
2615
2616  /**
2617   * Remove a replication peer but does not block and wait for it.
2618   * <p>
2619   * You can use Future.get(long, TimeUnit) to wait on the operation to complete. It may throw
2620   * ExecutionException if there was an error while executing the operation or TimeoutException in
2621   * case the wait timeout was not long enough to allow the operation to complete.
2622   * @param peerId a short name that identifies the peer
2623   * @return the result of the async operation
2624   * @throws IOException IOException if a remote or network exception occurs
2625   */
2626  Future<Void> removeReplicationPeerAsync(String peerId) throws IOException;
2627
2628  /**
2629   * Restart the replication stream to the specified peer.
2630   * @param peerId a short name that identifies the peer
2631   * @throws IOException if a remote or network exception occurs
2632   */
2633  void enableReplicationPeer(String peerId) throws IOException;
2634
2635  /**
2636   * Enable a replication peer but does not block and wait for it.
2637   * <p>
2638   * You can use Future.get(long, TimeUnit) to wait on the operation to complete. It may throw
2639   * ExecutionException if there was an error while executing the operation or TimeoutException in
2640   * case the wait timeout was not long enough to allow the operation to complete.
2641   * @param peerId a short name that identifies the peer
2642   * @return the result of the async operation
2643   * @throws IOException IOException if a remote or network exception occurs
2644   */
2645  Future<Void> enableReplicationPeerAsync(String peerId) throws IOException;
2646
2647  /**
2648   * Stop the replication stream to the specified peer.
2649   * @param peerId a short name that identifies the peer
2650   * @throws IOException if a remote or network exception occurs
2651   */
2652  void disableReplicationPeer(String peerId) throws IOException;
2653
2654  /**
2655   * Disable a replication peer but does not block and wait for it.
2656   * <p>
2657   * You can use Future.get(long, TimeUnit) to wait on the operation to complete. It may throw
2658   * ExecutionException if there was an error while executing the operation or TimeoutException in
2659   * case the wait timeout was not long enough to allow the operation to complete.
2660   * @param peerId a short name that identifies the peer
2661   * @return the result of the async operation
2662   * @throws IOException IOException if a remote or network exception occurs
2663   */
2664  Future<Void> disableReplicationPeerAsync(String peerId) throws IOException;
2665
2666  /**
2667   * Returns the configured ReplicationPeerConfig for the specified peer.
2668   * @param peerId a short name that identifies the peer
2669   * @return ReplicationPeerConfig for the peer
2670   * @throws IOException if a remote or network exception occurs
2671   */
2672  ReplicationPeerConfig getReplicationPeerConfig(String peerId) throws IOException;
2673
2674  /**
2675   * Update the peerConfig for the specified peer.
2676   * @param peerId a short name that identifies the peer
2677   * @param peerConfig new config for the replication peer
2678   * @throws IOException if a remote or network exception occurs
2679   */
2680  void updateReplicationPeerConfig(String peerId,
2681      ReplicationPeerConfig peerConfig) throws IOException;
2682
2683  /**
2684   * Update the peerConfig for the specified peer but does not block and wait for it.
2685   * <p>
2686   * You can use Future.get(long, TimeUnit) to wait on the operation to complete. It may throw
2687   * ExecutionException if there was an error while executing the operation or TimeoutException in
2688   * case the wait timeout was not long enough to allow the operation to complete.
2689   * @param peerId a short name that identifies the peer
2690   * @param peerConfig new config for the replication peer
2691   * @return the result of the async operation
2692   * @throws IOException IOException if a remote or network exception occurs
2693   */
2694  Future<Void> updateReplicationPeerConfigAsync(String peerId, ReplicationPeerConfig peerConfig)
2695      throws IOException;
2696
2697  /**
2698   * Append the replicable table column family config from the specified peer.
2699   * @param id a short that identifies the cluster
2700   * @param tableCfs A map from tableName to column family names
2701   * @throws ReplicationException if tableCfs has conflict with existing config
2702   * @throws IOException if a remote or network exception occurs
2703   */
2704  void appendReplicationPeerTableCFs(String id,
2705      Map<TableName, List<String>> tableCfs)
2706      throws ReplicationException, IOException;
2707
2708  /**
2709   * Remove some table-cfs from config of the specified peer.
2710   * @param id a short name that identifies the cluster
2711   * @param tableCfs A map from tableName to column family names
2712   * @throws ReplicationException if tableCfs has conflict with existing config
2713   * @throws IOException if a remote or network exception occurs
2714   */
2715  void removeReplicationPeerTableCFs(String id,
2716      Map<TableName, List<String>> tableCfs)
2717      throws ReplicationException, IOException;
2718
2719  /**
2720   * Return a list of replication peers.
2721   * @return a list of replication peers description
2722   * @throws IOException if a remote or network exception occurs
2723   */
2724  List<ReplicationPeerDescription> listReplicationPeers() throws IOException;
2725
2726  /**
2727   * Return a list of replication peers.
2728   * @param pattern The compiled regular expression to match peer id
2729   * @return a list of replication peers description
2730   * @throws IOException if a remote or network exception occurs
2731   */
2732  List<ReplicationPeerDescription> listReplicationPeers(Pattern pattern) throws IOException;
2733
2734  /**
2735   * Mark region server(s) as decommissioned to prevent additional regions from getting
2736   * assigned to them. Optionally unload the regions on the servers. If there are multiple servers
2737   * to be decommissioned, decommissioning them at the same time can prevent wasteful region
2738   * movements. Region unloading is asynchronous.
2739   * @param servers The list of servers to decommission.
2740   * @param offload True to offload the regions from the decommissioned servers
2741   */
2742  void decommissionRegionServers(List<ServerName> servers, boolean offload) throws IOException;
2743
2744  /**
2745   * List region servers marked as decommissioned, which can not be assigned regions.
2746   * @return List of decommissioned region servers.
2747   */
2748  List<ServerName> listDecommissionedRegionServers() throws IOException;
2749
2750  /**
2751   * Remove decommission marker from a region server to allow regions assignments.
2752   * Load regions onto the server if a list of regions is given. Region loading is
2753   * asynchronous.
2754   * @param server The server to recommission.
2755   * @param encodedRegionNames Regions to load onto the server.
2756   */
2757  void recommissionRegionServer(ServerName server, List<byte[]> encodedRegionNames)
2758      throws IOException;
2759
2760  /**
2761   * Find all table and column families that are replicated from this cluster
2762   * @return the replicated table-cfs list of this cluster.
2763   */
2764  List<TableCFs> listReplicatedTableCFs() throws IOException;
2765
2766  /**
2767   * Enable a table's replication switch.
2768   * @param tableName name of the table
2769   * @throws IOException if a remote or network exception occurs
2770   */
2771  void enableTableReplication(TableName tableName) throws IOException;
2772
2773  /**
2774   * Disable a table's replication switch.
2775   * @param tableName name of the table
2776   * @throws IOException if a remote or network exception occurs
2777   */
2778  void disableTableReplication(TableName tableName) throws IOException;
2779
2780  /**
2781   * Clear compacting queues on a regionserver.
2782   * @param serverName the region server name
2783   * @param queues the set of queue name
2784   * @throws IOException if a remote or network exception occurs
2785   * @throws InterruptedException
2786   */
2787  void clearCompactionQueues(ServerName serverName, Set<String> queues)
2788    throws IOException, InterruptedException;
2789
2790  /**
2791   * List dead region servers.
2792   * @return List of dead region servers.
2793   */
2794  default List<ServerName> listDeadServers() throws IOException {
2795    return getClusterMetrics(EnumSet.of(Option.DEAD_SERVERS)).getDeadServerNames();
2796  }
2797
2798  /**
2799   * Clear dead region servers from master.
2800   * @param servers list of dead region servers.
2801   * @throws IOException if a remote or network exception occurs
2802   * @return List of servers that are not cleared
2803   */
2804  List<ServerName> clearDeadServers(final List<ServerName> servers) throws IOException;
2805
2806  /**
2807   * Create a new table by cloning the existent table schema.
2808   *
2809   * @param tableName name of the table to be cloned
2810   * @param newTableName name of the new table where the table will be created
2811   * @param preserveSplits True if the splits should be preserved
2812   * @throws IOException if a remote or network exception occurs
2813   */
2814  void cloneTableSchema(final TableName tableName, final TableName newTableName,
2815      final boolean preserveSplits) throws IOException;
2816
2817  /**
2818   * Switch the rpc throttle enable state.
2819   * @param enable Set to <code>true</code> to enable, <code>false</code> to disable.
2820   * @return Previous rpc throttle enabled value
2821   */
2822  boolean switchRpcThrottle(final boolean enable) throws IOException;
2823
2824  /**
2825   * Get if the rpc throttle is enabled.
2826   * @return True if rpc throttle is enabled
2827   */
2828  boolean isRpcThrottleEnabled() throws IOException;
2829
2830  /**
2831   * Switch the exceed throttle quota. If enabled, user/table/namespace throttle quota
2832   * can be exceeded if region server has availble quota.
2833   * @param enable Set to <code>true</code> to enable, <code>false</code> to disable.
2834   * @return Previous exceed throttle enabled value
2835   */
2836  boolean exceedThrottleQuotaSwitch(final boolean enable) throws IOException;
2837
2838  /**
2839   * Fetches the table sizes on the filesystem as tracked by the HBase Master.
2840   */
2841  Map<TableName, Long> getSpaceQuotaTableSizes() throws IOException;
2842
2843  /**
2844   * Fetches the observed {@link SpaceQuotaSnapshotView}s observed by a RegionServer.
2845   */
2846  Map<TableName, ? extends SpaceQuotaSnapshotView> getRegionServerSpaceQuotaSnapshots(
2847      ServerName serverName) throws IOException;
2848
2849  /**
2850   * Returns the Master's view of a quota on the given {@code namespace} or null if the Master has
2851   * no quota information on that namespace.
2852   */
2853  SpaceQuotaSnapshotView getCurrentSpaceQuotaSnapshot(String namespace) throws IOException;
2854
2855  /**
2856   * Returns the Master's view of a quota on the given {@code tableName} or null if the Master has
2857   * no quota information on that table.
2858   */
2859  SpaceQuotaSnapshotView getCurrentSpaceQuotaSnapshot(TableName tableName) throws IOException;
2860
2861  /**
2862   * Grants user specific permissions
2863   * @param userPermission user name and the specific permission
2864   * @param mergeExistingPermissions If set to false, later granted permissions will override
2865   *          previous granted permissions. otherwise, it'll merge with previous granted
2866   *          permissions.
2867   * @throws IOException if a remote or network exception occurs
2868   */
2869  void grant(UserPermission userPermission, boolean mergeExistingPermissions) throws IOException;
2870
2871  /**
2872   * Revokes user specific permissions
2873   * @param userPermission user name and the specific permission
2874   * @throws IOException if a remote or network exception occurs
2875   */
2876  void revoke(UserPermission userPermission) throws IOException;
2877
2878  /**
2879   * Get the global/namespace/table permissions for user
2880   * @param getUserPermissionsRequest A request contains which user, global, namespace or table
2881   *          permissions needed
2882   * @return The user and permission list
2883   * @throws IOException if a remote or network exception occurs
2884   */
2885  List<UserPermission> getUserPermissions(GetUserPermissionsRequest getUserPermissionsRequest)
2886      throws IOException;
2887
2888  /**
2889   * Check if the user has specific permissions
2890   * @param userName the user name
2891   * @param permissions the specific permission list
2892   * @return True if user has the specific permissions
2893   * @throws IOException if a remote or network exception occurs
2894   */
2895  List<Boolean> hasUserPermissions(String userName, List<Permission> permissions)
2896      throws IOException;
2897
2898  /**
2899   * Check if call user has specific permissions
2900   * @param permissions the specific permission list
2901   * @return True if user has the specific permissions
2902   * @throws IOException if a remote or network exception occurs
2903   */
2904  default List<Boolean> hasUserPermissions(List<Permission> permissions) throws IOException {
2905    return hasUserPermissions(null, permissions);
2906  }
2907}