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 static org.apache.hadoop.hbase.util.FutureUtils.addListener;
021
022import com.google.protobuf.RpcChannel;
023import java.util.Arrays;
024import java.util.Collection;
025import java.util.EnumSet;
026import java.util.HashMap;
027import java.util.List;
028import java.util.Map;
029import java.util.Optional;
030import java.util.Set;
031import java.util.concurrent.CompletableFuture;
032import java.util.function.Function;
033import java.util.regex.Pattern;
034import java.util.stream.Collectors;
035import org.apache.hadoop.hbase.CacheEvictionStats;
036import org.apache.hadoop.hbase.ClusterMetrics;
037import org.apache.hadoop.hbase.ClusterMetrics.Option;
038import org.apache.hadoop.hbase.NamespaceDescriptor;
039import org.apache.hadoop.hbase.RegionMetrics;
040import org.apache.hadoop.hbase.ServerName;
041import org.apache.hadoop.hbase.TableName;
042import org.apache.hadoop.hbase.client.replication.TableCFs;
043import org.apache.hadoop.hbase.client.security.SecurityCapability;
044import org.apache.hadoop.hbase.quotas.QuotaFilter;
045import org.apache.hadoop.hbase.quotas.QuotaSettings;
046import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshotView;
047import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
048import org.apache.hadoop.hbase.replication.ReplicationPeerDescription;
049import org.apache.hadoop.hbase.security.access.GetUserPermissionsRequest;
050import org.apache.hadoop.hbase.security.access.Permission;
051import org.apache.hadoop.hbase.security.access.UserPermission;
052import org.apache.yetus.audience.InterfaceAudience;
053
054import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList;
055
056/**
057 * The asynchronous administrative API for HBase.
058 * @since 2.0.0
059 */
060@InterfaceAudience.Public
061public interface AsyncAdmin {
062
063  /**
064   * @param tableName Table to check.
065   * @return True if table exists already. The return value will be wrapped by a
066   *         {@link CompletableFuture}.
067   */
068  CompletableFuture<Boolean> tableExists(TableName tableName);
069
070  /**
071   * List all the userspace tables.
072   * @return - returns a list of TableDescriptors wrapped by a {@link CompletableFuture}.
073   */
074  default CompletableFuture<List<TableDescriptor>> listTableDescriptors() {
075    return listTableDescriptors(false);
076  }
077
078  /**
079   * List all the tables.
080   * @param includeSysTables False to match only against userspace tables
081   * @return - returns a list of TableDescriptors wrapped by a {@link CompletableFuture}.
082   */
083  CompletableFuture<List<TableDescriptor>> listTableDescriptors(boolean includeSysTables);
084
085  /**
086   * List all the tables matching the given pattern.
087   * @param pattern The compiled regular expression to match against
088   * @param includeSysTables False to match only against userspace tables
089   * @return - returns a list of TableDescriptors wrapped by a {@link CompletableFuture}.
090   */
091  CompletableFuture<List<TableDescriptor>> listTableDescriptors(Pattern pattern,
092      boolean includeSysTables);
093
094  /**
095   * List specific tables including system tables.
096   * @param tableNames the table list to match against
097   * @return - returns a list of TableDescriptors wrapped by a {@link CompletableFuture}.
098   */
099  CompletableFuture<List<TableDescriptor>> listTableDescriptors(List<TableName> tableNames);
100
101  /**
102   * Get list of table descriptors by namespace.
103   * @param name namespace name
104   * @return returns a list of TableDescriptors wrapped by a {@link CompletableFuture}.
105   */
106  CompletableFuture<List<TableDescriptor>> listTableDescriptorsByNamespace(String name);
107
108  /**
109   * List all of the names of userspace tables.
110   * @return a list of table names wrapped by a {@link CompletableFuture}.
111   * @see #listTableNames(Pattern, boolean)
112   */
113  default CompletableFuture<List<TableName>> listTableNames() {
114    return listTableNames(false);
115  }
116
117  /**
118   * List all of the names of tables.
119   * @param includeSysTables False to match only against userspace tables
120   * @return a list of table names wrapped by a {@link CompletableFuture}.
121   */
122  CompletableFuture<List<TableName>> listTableNames(boolean includeSysTables);
123
124  /**
125   * List all of the names of userspace tables.
126   * @param pattern The regular expression to match against
127   * @param includeSysTables False to match only against userspace tables
128   * @return a list of table names wrapped by a {@link CompletableFuture}.
129   */
130  CompletableFuture<List<TableName>> listTableNames(Pattern pattern, boolean includeSysTables);
131
132  /**
133   * Get list of table names by namespace.
134   * @param name namespace name
135   * @return The list of table names in the namespace wrapped by a {@link CompletableFuture}.
136   */
137  CompletableFuture<List<TableName>> listTableNamesByNamespace(String name);
138
139  /**
140   * Method for getting the tableDescriptor
141   * @param tableName as a {@link TableName}
142   * @return the read-only tableDescriptor wrapped by a {@link CompletableFuture}.
143   */
144  CompletableFuture<TableDescriptor> getDescriptor(TableName tableName);
145
146  /**
147   * Creates a new table.
148   * @param desc table descriptor for table
149   */
150  CompletableFuture<Void> createTable(TableDescriptor desc);
151
152  /**
153   * Creates a new table with the specified number of regions. The start key specified will become
154   * the end key of the first region of the table, and the end key specified will become the start
155   * key of the last region of the table (the first region has a null start key and the last region
156   * has a null end key). BigInteger math will be used to divide the key range specified into enough
157   * segments to make the required number of total regions.
158   * @param desc table descriptor for table
159   * @param startKey beginning of key range
160   * @param endKey end of key range
161   * @param numRegions the total number of regions to create
162   */
163  CompletableFuture<Void> createTable(TableDescriptor desc, byte[] startKey, byte[] endKey,
164      int numRegions);
165
166  /**
167   * Creates a new table with an initial set of empty regions defined by the specified split keys.
168   * The total number of regions created will be the number of split keys plus one.
169   * Note : Avoid passing empty split key.
170   * @param desc table descriptor for table
171   * @param splitKeys array of split keys for the initial regions of the table
172   */
173  CompletableFuture<Void> createTable(TableDescriptor desc, byte[][] splitKeys);
174
175  /**
176   * Modify an existing table, more IRB friendly version.
177   * @param desc modified description of the table
178   */
179  CompletableFuture<Void> modifyTable(TableDescriptor desc);
180
181  /**
182   * Deletes a table.
183   * @param tableName name of table to delete
184   */
185  CompletableFuture<Void> deleteTable(TableName tableName);
186
187  /**
188   * Truncate a table.
189   * @param tableName name of table to truncate
190   * @param preserveSplits True if the splits should be preserved
191   */
192  CompletableFuture<Void> truncateTable(TableName tableName, boolean preserveSplits);
193
194  /**
195   * Enable a table. The table has to be in disabled state for it to be enabled.
196   * @param tableName name of the table
197   */
198  CompletableFuture<Void> enableTable(TableName tableName);
199
200  /**
201   * Disable a table. The table has to be in enabled state for it to be disabled.
202   * @param tableName
203   */
204  CompletableFuture<Void> disableTable(TableName tableName);
205
206  /**
207   * @param tableName name of table to check
208   * @return true if table is on-line. The return value will be wrapped by a
209   *         {@link CompletableFuture}.
210   */
211  CompletableFuture<Boolean> isTableEnabled(TableName tableName);
212
213  /**
214   * @param tableName name of table to check
215   * @return true if table is off-line. The return value will be wrapped by a
216   *         {@link CompletableFuture}.
217   */
218  CompletableFuture<Boolean> isTableDisabled(TableName tableName);
219
220  /**
221   * @param tableName name of table to check
222   * @return true if all regions of the table are available. The return value will be wrapped by a
223   *         {@link CompletableFuture}.
224   */
225  CompletableFuture<Boolean> isTableAvailable(TableName tableName);
226
227  /**
228   * Use this api to check if the table has been created with the specified number of splitkeys
229   * which was used while creating the given table. Note : If this api is used after a table's
230   * region gets splitted, the api may return false. The return value will be wrapped by a
231   * {@link CompletableFuture}.
232   * @param tableName name of table to check
233   * @param splitKeys keys to check if the table has been created with all split keys
234   * @deprecated Since 2.2.0. Will be removed in 3.0.0. Use {@link #isTableAvailable(TableName)}
235   */
236  @Deprecated
237  CompletableFuture<Boolean> isTableAvailable(TableName tableName, byte[][] splitKeys);
238
239  /**
240   * Add a column family to an existing table.
241   * @param tableName name of the table to add column family to
242   * @param columnFamily column family descriptor of column family to be added
243   */
244  CompletableFuture<Void> addColumnFamily(TableName tableName,
245      ColumnFamilyDescriptor columnFamily);
246
247  /**
248   * Delete a column family from a table.
249   * @param tableName name of table
250   * @param columnFamily name of column family to be deleted
251   */
252  CompletableFuture<Void> deleteColumnFamily(TableName tableName, byte[] columnFamily);
253
254  /**
255   * Modify an existing column family on a table.
256   * @param tableName name of table
257   * @param columnFamily new column family descriptor to use
258   */
259  CompletableFuture<Void> modifyColumnFamily(TableName tableName,
260      ColumnFamilyDescriptor columnFamily);
261
262  /**
263   * Create a new namespace.
264   * @param descriptor descriptor which describes the new namespace
265   */
266  CompletableFuture<Void> createNamespace(NamespaceDescriptor descriptor);
267
268  /**
269   * Modify an existing namespace.
270   * @param descriptor descriptor which describes the new namespace
271   */
272  CompletableFuture<Void> modifyNamespace(NamespaceDescriptor descriptor);
273
274  /**
275   * Delete an existing namespace. Only empty namespaces (no tables) can be removed.
276   * @param name namespace name
277   */
278  CompletableFuture<Void> deleteNamespace(String name);
279
280  /**
281   * Get a namespace descriptor by name
282   * @param name name of namespace descriptor
283   * @return A descriptor wrapped by a {@link CompletableFuture}.
284   */
285  CompletableFuture<NamespaceDescriptor> getNamespaceDescriptor(String name);
286
287  /**
288   * List available namespaces
289   * @return List of namespaces wrapped by a {@link CompletableFuture}.
290   */
291  CompletableFuture<List<String>> listNamespaces();
292
293  /**
294   * List available namespace descriptors
295   * @return List of descriptors wrapped by a {@link CompletableFuture}.
296   */
297  CompletableFuture<List<NamespaceDescriptor>> listNamespaceDescriptors();
298
299  /**
300   * Get all the online regions on a region server.
301   */
302  CompletableFuture<List<RegionInfo>> getRegions(ServerName serverName);
303
304  /**
305   * Get the regions of a given table.
306   */
307  CompletableFuture<List<RegionInfo>> getRegions(TableName tableName);
308
309  /**
310   * Flush a table.
311   * @param tableName table to flush
312   */
313  CompletableFuture<Void> flush(TableName tableName);
314
315  /**
316   * Flush the specified column family stores on all regions of the passed table.
317   * This runs as a synchronous operation.
318   * @param tableName table to flush
319   * @param columnFamily column family within a table
320   */
321  CompletableFuture<Void> flush(TableName tableName, byte[] columnFamily);
322
323  /**
324   * Flush an individual region.
325   * @param regionName region to flush
326   */
327  CompletableFuture<Void> flushRegion(byte[] regionName);
328
329  /**
330   * Flush a column family within a region.
331   * @param regionName region to flush
332   * @param columnFamily column family within a region. If not present, flush the region's all
333   *          column families.
334   */
335  CompletableFuture<Void> flushRegion(byte[] regionName, byte[] columnFamily);
336
337  /**
338   * Flush all region on the region server.
339   * @param serverName server to flush
340   */
341  CompletableFuture<Void> flushRegionServer(ServerName serverName);
342
343  /**
344   * Compact a table. When the returned CompletableFuture is done, it only means the compact request
345   * was sent to HBase and may need some time to finish the compact operation.
346   * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found.
347   * @param tableName table to compact
348   */
349  default CompletableFuture<Void> compact(TableName tableName) {
350    return compact(tableName, CompactType.NORMAL);
351  }
352
353  /**
354   * Compact a column family within a table. When the returned CompletableFuture is done, it only
355   * means the compact request was sent to HBase and may need some time to finish the compact
356   * operation.
357   * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found.
358   * @param tableName table to compact
359   * @param columnFamily column family within a table. If not present, compact the table's all
360   *          column families.
361   */
362  default CompletableFuture<Void> compact(TableName tableName, byte[] columnFamily) {
363    return compact(tableName, columnFamily, CompactType.NORMAL);
364  }
365
366  /**
367   * Compact a table. When the returned CompletableFuture is done, it only means the compact request
368   * was sent to HBase and may need some time to finish the compact operation.
369   * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found for
370   * normal compaction type.
371   * @param tableName table to compact
372   * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
373   */
374  CompletableFuture<Void> compact(TableName tableName, CompactType compactType);
375
376  /**
377   * Compact a column family within a table. When the returned CompletableFuture is done, it only
378   * means the compact request was sent to HBase and may need some time to finish the compact
379   * operation.
380   * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found for
381   * normal compaction type.
382   * @param tableName table to compact
383   * @param columnFamily column family within a table
384   * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
385   */
386  CompletableFuture<Void> compact(TableName tableName, byte[] columnFamily,
387      CompactType compactType);
388
389  /**
390   * Compact an individual region. When the returned CompletableFuture is done, it only means the
391   * compact request was sent to HBase and may need some time to finish the compact operation.
392   * @param regionName region to compact
393   */
394  CompletableFuture<Void> compactRegion(byte[] regionName);
395
396  /**
397   * Compact a column family within a region. When the returned CompletableFuture is done, it only
398   * means the compact request was sent to HBase and may need some time to finish the compact
399   * operation.
400   * @param regionName region to compact
401   * @param columnFamily column family within a region. If not present, compact the region's all
402   *          column families.
403   */
404  CompletableFuture<Void> compactRegion(byte[] regionName, byte[] columnFamily);
405
406  /**
407   * Major compact a table. When the returned CompletableFuture is done, it only means the compact
408   * request was sent to HBase and may need some time to finish the compact operation.
409   * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found.
410   * @param tableName table to major compact
411   */
412  default CompletableFuture<Void> majorCompact(TableName tableName) {
413    return majorCompact(tableName, CompactType.NORMAL);
414  }
415
416  /**
417   * Major compact a column family within a table. When the returned CompletableFuture is done, it
418   * only means the compact request was sent to HBase and may need some time to finish the compact
419   * operation.
420   * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found for
421   * normal compaction. type.
422   * @param tableName table to major compact
423   * @param columnFamily column family within a table. If not present, major compact the table's all
424   *          column families.
425   */
426  default CompletableFuture<Void> majorCompact(TableName tableName, byte[] columnFamily) {
427    return majorCompact(tableName, columnFamily, CompactType.NORMAL);
428  }
429
430  /**
431   * Major compact a table. When the returned CompletableFuture is done, it only means the compact
432   * request was sent to HBase and may need some time to finish the compact operation.
433   * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found for
434   * normal compaction type.
435   * @param tableName table to major compact
436   * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
437   */
438  CompletableFuture<Void> majorCompact(TableName tableName, CompactType compactType);
439
440  /**
441   * Major compact a column family within a table. When the returned CompletableFuture is done, it
442   * only means the compact request was sent to HBase and may need some time to finish the compact
443   * operation.
444   * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found.
445   * @param tableName table to major compact
446   * @param columnFamily column family within a table. If not present, major compact the table's all
447   *          column families.
448   * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
449   */
450  CompletableFuture<Void> majorCompact(TableName tableName, byte[] columnFamily,
451      CompactType compactType);
452
453  /**
454   * Major compact a region. When the returned CompletableFuture is done, it only means the compact
455   * request was sent to HBase and may need some time to finish the compact operation.
456   * @param regionName region to major compact
457   */
458  CompletableFuture<Void> majorCompactRegion(byte[] regionName);
459
460  /**
461   * Major compact a column family within region. When the returned CompletableFuture is done, it
462   * only means the compact request was sent to HBase and may need some time to finish the compact
463   * operation.
464   * @param regionName region to major compact
465   * @param columnFamily column family within a region. If not present, major compact the region's
466   *          all column families.
467   */
468  CompletableFuture<Void> majorCompactRegion(byte[] regionName, byte[] columnFamily);
469
470  /**
471   * Compact all regions on the region server.
472   * @param serverName the region server name
473   */
474  CompletableFuture<Void> compactRegionServer(ServerName serverName);
475
476  /**
477   * Compact all regions on the region server.
478   * @param serverName the region server name
479   */
480  CompletableFuture<Void> majorCompactRegionServer(ServerName serverName);
481
482  /**
483   * Turn the Merge switch on or off.
484   * @param enabled enabled or not
485   * @return Previous switch value wrapped by a {@link CompletableFuture}
486   */
487  default CompletableFuture<Boolean> mergeSwitch(boolean enabled) {
488    return mergeSwitch(enabled, false);
489  }
490
491  /**
492   * Turn the Merge switch on or off.
493   * <p/>
494   * Notice that, the method itself is always non-blocking, which means it will always return
495   * immediately. The {@code drainMerges} parameter only effects when will we complete the returned
496   * {@link CompletableFuture}.
497   * @param enabled enabled or not
498   * @param drainMerges If <code>true</code>, it waits until current merge() call, if outstanding,
499   *          to return.
500   * @return Previous switch value wrapped by a {@link CompletableFuture}
501   */
502  CompletableFuture<Boolean> mergeSwitch(boolean enabled, boolean drainMerges);
503
504  /**
505   * Query the current state of the Merge switch.
506   * @return true if the switch is on, false otherwise. The return value will be wrapped by a
507   *         {@link CompletableFuture}
508   */
509  CompletableFuture<Boolean> isMergeEnabled();
510
511  /**
512   * Turn the Split switch on or off.
513   * @param enabled enabled or not
514   * @return Previous switch value wrapped by a {@link CompletableFuture}
515   */
516  default CompletableFuture<Boolean> splitSwitch(boolean enabled) {
517    return splitSwitch(enabled, false);
518  }
519
520  /**
521   * Turn the Split switch on or off.
522   * <p/>
523   * Notice that, the method itself is always non-blocking, which means it will always return
524   * immediately. The {@code drainSplits} parameter only effects when will we complete the returned
525   * {@link CompletableFuture}.
526   * @param enabled enabled or not
527   * @param drainSplits If <code>true</code>, it waits until current split() call, if outstanding,
528   *          to return.
529   * @return Previous switch value wrapped by a {@link CompletableFuture}
530   */
531  CompletableFuture<Boolean> splitSwitch(boolean enabled, boolean drainSplits);
532
533  /**
534   * Query the current state of the Split switch.
535   * @return true if the switch is on, false otherwise. The return value will be wrapped by a
536   *         {@link CompletableFuture}
537   */
538  CompletableFuture<Boolean> isSplitEnabled();
539
540  /**
541   * Merge two regions.
542   * @param nameOfRegionA encoded or full name of region a
543   * @param nameOfRegionB encoded or full name of region b
544   * @param forcible true if do a compulsory merge, otherwise we will only merge two adjacent
545   *          regions
546   * @deprecated since 2.3.0 and will be removed in 4.0.0.Use {@link #mergeRegions(List, boolean)}
547   *             instead.
548   */
549  @Deprecated
550  default CompletableFuture<Void> mergeRegions(byte[] nameOfRegionA, byte[] nameOfRegionB,
551      boolean forcible) {
552    return mergeRegions(Arrays.asList(nameOfRegionA, nameOfRegionB), forcible);
553  }
554
555  /**
556   * Merge multiple regions (>=2).
557   * @param nameOfRegionsToMerge encoded or full name of daughter regions
558   * @param forcible true if do a compulsory merge, otherwise we will only merge two adjacent
559   *          regions
560   */
561  CompletableFuture<Void> mergeRegions(List<byte[]> nameOfRegionsToMerge, boolean forcible);
562
563  /**
564   * Split a table. The method will execute split action for each region in table.
565   * @param tableName table to split
566   */
567  CompletableFuture<Void> split(TableName tableName);
568
569  /**
570   * Split an individual region.
571   * @param regionName region to split
572   */
573  CompletableFuture<Void> splitRegion(byte[] regionName);
574
575  /**
576   * Split a table.
577   * @param tableName table to split
578   * @param splitPoint the explicit position to split on
579   */
580  CompletableFuture<Void> split(TableName tableName, byte[] splitPoint);
581
582  /**
583   * Split an individual region.
584   * @param regionName region to split
585   * @param splitPoint the explicit position to split on. If not present, it will decide by region
586   *          server.
587   */
588  CompletableFuture<Void> splitRegion(byte[] regionName, byte[] splitPoint);
589
590  /**
591   * @param regionName Encoded or full name of region to assign.
592   */
593  CompletableFuture<Void> assign(byte[] regionName);
594
595  /**
596   * @param regionName Encoded or full name of region to unassign.
597   */
598  CompletableFuture<Void> unassign(byte[] regionName);
599
600  /**
601   * Unassign a region from current hosting regionserver. Region will then be assigned to a
602   * regionserver chosen at random. Region could be reassigned back to the same server. Use
603   * {@link #move(byte[], ServerName)} if you want to control the region movement.
604   * @param regionName Encoded or full name of region to unassign. Will clear any existing
605   *          RegionPlan if one found.
606   * @param forcible If true, force unassign (Will remove region from regions-in-transition too if
607   *          present. If results in double assignment use hbck -fix to resolve. To be used by
608   *          experts).
609   * @deprecated since 2.4.0 and will be removed in 4.0.0. Use {@link #unassign(byte[])}
610   *   instead.
611   * @see <a href="https://issues.apache.org/jira/browse/HBASE-24875">HBASE-24875</a>
612   */
613  @Deprecated
614  default CompletableFuture<Void> unassign(byte[] regionName, boolean forcible) {
615    return unassign(regionName);
616  }
617
618  /**
619   * Offline specified region from master's in-memory state. It will not attempt to reassign the
620   * region as in unassign. This API can be used when a region not served by any region server and
621   * still online as per Master's in memory state. If this API is incorrectly used on active region
622   * then master will loose track of that region. This is a special method that should be used by
623   * experts or hbck.
624   * @param regionName Encoded or full name of region to offline
625   */
626  CompletableFuture<Void> offline(byte[] regionName);
627
628  /**
629   * Move the region <code>r</code> to a random server.
630   * @param regionName Encoded or full name of region to move.
631   */
632  CompletableFuture<Void> move(byte[] regionName);
633
634  /**
635   * Move the region <code>r</code> to <code>dest</code>.
636   * @param regionName Encoded or full name of region to move.
637   * @param destServerName The servername of the destination regionserver. If not present, we'll
638   *          assign to a random server. A server name is made of host, port and startcode. Here is
639   *          an example: <code> host187.example.com,60020,1289493121758</code>
640   */
641  CompletableFuture<Void> move(byte[] regionName, ServerName destServerName);
642
643  /**
644   * Apply the new quota settings.
645   * @param quota the quota settings
646   */
647  CompletableFuture<Void> setQuota(QuotaSettings quota);
648
649  /**
650   * List the quotas based on the filter.
651   * @param filter the quota settings filter
652   * @return the QuotaSetting list, which wrapped by a CompletableFuture.
653   */
654  CompletableFuture<List<QuotaSettings>> getQuota(QuotaFilter filter);
655
656  /**
657   * Add a new replication peer for replicating data to slave cluster
658   * @param peerId a short name that identifies the peer
659   * @param peerConfig configuration for the replication slave cluster
660   */
661  default CompletableFuture<Void> addReplicationPeer(String peerId,
662      ReplicationPeerConfig peerConfig) {
663    return addReplicationPeer(peerId, peerConfig, true);
664  }
665
666  /**
667   * Add a new replication peer for replicating data to slave cluster
668   * @param peerId a short name that identifies the peer
669   * @param peerConfig configuration for the replication slave cluster
670   * @param enabled peer state, true if ENABLED and false if DISABLED
671   */
672  CompletableFuture<Void> addReplicationPeer(String peerId,
673      ReplicationPeerConfig peerConfig, boolean enabled);
674
675  /**
676   * Remove a peer and stop the replication
677   * @param peerId a short name that identifies the peer
678   */
679  CompletableFuture<Void> removeReplicationPeer(String peerId);
680
681  /**
682   * Restart the replication stream to the specified peer
683   * @param peerId a short name that identifies the peer
684   */
685  CompletableFuture<Void> enableReplicationPeer(String peerId);
686
687  /**
688   * Stop the replication stream to the specified peer
689   * @param peerId a short name that identifies the peer
690   */
691  CompletableFuture<Void> disableReplicationPeer(String peerId);
692
693  /**
694   * Returns the configured ReplicationPeerConfig for the specified peer
695   * @param peerId a short name that identifies the peer
696   * @return ReplicationPeerConfig for the peer wrapped by a {@link CompletableFuture}.
697   */
698  CompletableFuture<ReplicationPeerConfig> getReplicationPeerConfig(String peerId);
699
700  /**
701   * Update the peerConfig for the specified peer
702   * @param peerId a short name that identifies the peer
703   * @param peerConfig new config for the peer
704   */
705  CompletableFuture<Void> updateReplicationPeerConfig(String peerId,
706      ReplicationPeerConfig peerConfig);
707
708  /**
709   * Append the replicable table-cf config of the specified peer
710   * @param peerId a short that identifies the cluster
711   * @param tableCfs A map from tableName to column family names
712   */
713  CompletableFuture<Void> appendReplicationPeerTableCFs(String peerId,
714      Map<TableName, List<String>> tableCfs);
715
716  /**
717   * Remove some table-cfs from config of the specified peer
718   * @param peerId a short name that identifies the cluster
719   * @param tableCfs A map from tableName to column family names
720   */
721  CompletableFuture<Void> removeReplicationPeerTableCFs(String peerId,
722      Map<TableName, List<String>> tableCfs);
723
724  /**
725   * Return a list of replication peers.
726   * @return a list of replication peers description. The return value will be wrapped by a
727   *         {@link CompletableFuture}.
728   */
729  CompletableFuture<List<ReplicationPeerDescription>> listReplicationPeers();
730
731  /**
732   * Return a list of replication peers.
733   * @param pattern The compiled regular expression to match peer id
734   * @return a list of replication peers description. The return value will be wrapped by a
735   *         {@link CompletableFuture}.
736   */
737  CompletableFuture<List<ReplicationPeerDescription>> listReplicationPeers(Pattern pattern);
738
739  /**
740   * Find all table and column families that are replicated from this cluster
741   * @return the replicated table-cfs list of this cluster. The return value will be wrapped by a
742   *         {@link CompletableFuture}.
743   */
744  CompletableFuture<List<TableCFs>> listReplicatedTableCFs();
745
746  /**
747   * Enable a table's replication switch.
748   * @param tableName name of the table
749   */
750  CompletableFuture<Void> enableTableReplication(TableName tableName);
751
752  /**
753   * Disable a table's replication switch.
754   * @param tableName name of the table
755   */
756  CompletableFuture<Void> disableTableReplication(TableName tableName);
757
758  /**
759   * Take a snapshot for the given table. If the table is enabled, a FLUSH-type snapshot will be
760   * taken. If the table is disabled, an offline snapshot is taken. Snapshots are considered unique
761   * based on <b>the name of the snapshot</b>. Attempts to take a snapshot with the same name (even
762   * a different type or with different parameters) will fail with a
763   * {@link org.apache.hadoop.hbase.snapshot.SnapshotCreationException} indicating the duplicate
764   * naming. Snapshot names follow the same naming constraints as tables in HBase. See
765   * {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}.
766   * @param snapshotName name of the snapshot to be created
767   * @param tableName name of the table for which snapshot is created
768   */
769  default CompletableFuture<Void> snapshot(String snapshotName, TableName tableName) {
770    return snapshot(snapshotName, tableName, SnapshotType.FLUSH);
771  }
772
773  /**
774   * Create typed snapshot of the table. Snapshots are considered unique based on <b>the name of the
775   * snapshot</b>. Attempts to take a snapshot with the same name (even a different type or with
776   * different parameters) will fail with a
777   * {@link org.apache.hadoop.hbase.snapshot.SnapshotCreationException} indicating the duplicate
778   * naming. Snapshot names follow the same naming constraints as tables in HBase. See
779   * {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}.
780   * @param snapshotName name to give the snapshot on the filesystem. Must be unique from all other
781   *          snapshots stored on the cluster
782   * @param tableName name of the table to snapshot
783   * @param type type of snapshot to take
784   */
785  default CompletableFuture<Void> snapshot(String snapshotName, TableName tableName,
786      SnapshotType type) {
787    return snapshot(new SnapshotDescription(snapshotName, tableName, type));
788  }
789
790  /**
791   * Take a snapshot and wait for the server to complete that snapshot asynchronously. Only a single
792   * snapshot should be taken at a time for an instance of HBase, or results may be undefined (you
793   * can tell multiple HBase clusters to snapshot at the same time, but only one at a time for a
794   * single cluster). Snapshots are considered unique based on <b>the name of the snapshot</b>.
795   * Attempts to take a snapshot with the same name (even a different type or with different
796   * parameters) will fail with a {@link org.apache.hadoop.hbase.snapshot.SnapshotCreationException}
797   * indicating the duplicate naming. Snapshot names follow the same naming constraints as tables in
798   * HBase. See {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}.
799   * You should probably use {@link #snapshot(String, org.apache.hadoop.hbase.TableName)} unless you
800   * are sure about the type of snapshot that you want to take.
801   * @param snapshot snapshot to take
802   */
803  CompletableFuture<Void> snapshot(SnapshotDescription snapshot);
804
805  /**
806   * Check the current state of the passed snapshot. There are three possible states:
807   * <ol>
808   * <li>running - returns <tt>false</tt></li>
809   * <li>finished - returns <tt>true</tt></li>
810   * <li>finished with error - throws the exception that caused the snapshot to fail</li>
811   * </ol>
812   * The cluster only knows about the most recent snapshot. Therefore, if another snapshot has been
813   * run/started since the snapshot you are checking, you will receive an
814   * {@link org.apache.hadoop.hbase.snapshot.UnknownSnapshotException}.
815   * @param snapshot description of the snapshot to check
816   * @return <tt>true</tt> if the snapshot is completed, <tt>false</tt> if the snapshot is still
817   *         running
818   */
819  CompletableFuture<Boolean> isSnapshotFinished(SnapshotDescription snapshot);
820
821  /**
822   * Restore the specified snapshot on the original table. (The table must be disabled) If the
823   * "hbase.snapshot.restore.take.failsafe.snapshot" configuration property is set to true, a
824   * snapshot of the current table is taken before executing the restore operation. In case of
825   * restore failure, the failsafe snapshot will be restored. If the restore completes without
826   * problem the failsafe snapshot is deleted.
827   * @param snapshotName name of the snapshot to restore
828   */
829  CompletableFuture<Void> restoreSnapshot(String snapshotName);
830
831  /**
832   * Restore the specified snapshot on the original table. (The table must be disabled) If
833   * 'takeFailSafeSnapshot' is set to true, a snapshot of the current table is taken before
834   * executing the restore operation. In case of restore failure, the failsafe snapshot will be
835   * restored. If the restore completes without problem the failsafe snapshot is deleted. The
836   * failsafe snapshot name is configurable by using the property
837   * "hbase.snapshot.restore.failsafe.name".
838   * @param snapshotName name of the snapshot to restore
839   * @param takeFailSafeSnapshot true if the failsafe snapshot should be taken
840   */
841  default CompletableFuture<Void> restoreSnapshot(String snapshotName,
842      boolean takeFailSafeSnapshot) {
843    return restoreSnapshot(snapshotName, takeFailSafeSnapshot, false);
844  }
845
846  /**
847   * Restore the specified snapshot on the original table. (The table must be disabled) If
848   * 'takeFailSafeSnapshot' is set to true, a snapshot of the current table is taken before
849   * executing the restore operation. In case of restore failure, the failsafe snapshot will be
850   * restored. If the restore completes without problem the failsafe snapshot is deleted. The
851   * failsafe snapshot name is configurable by using the property
852   * "hbase.snapshot.restore.failsafe.name".
853   * @param snapshotName name of the snapshot to restore
854   * @param takeFailSafeSnapshot true if the failsafe snapshot should be taken
855   * @param restoreAcl <code>true</code> to restore acl of snapshot
856   */
857  CompletableFuture<Void> restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot,
858      boolean restoreAcl);
859
860  /**
861   * Create a new table by cloning the snapshot content.
862   * @param snapshotName name of the snapshot to be cloned
863   * @param tableName name of the table where the snapshot will be restored
864   */
865  default CompletableFuture<Void> cloneSnapshot(String snapshotName, TableName tableName) {
866    return cloneSnapshot(snapshotName, tableName, false);
867  }
868
869  /**
870   * Create a new table by cloning the snapshot content.
871   * @param snapshotName name of the snapshot to be cloned
872   * @param tableName name of the table where the snapshot will be restored
873   * @param restoreAcl <code>true</code> to restore acl of snapshot
874   */
875  CompletableFuture<Void> cloneSnapshot(String snapshotName, TableName tableName,
876      boolean restoreAcl);
877
878  /**
879   * List completed snapshots.
880   * @return a list of snapshot descriptors for completed snapshots wrapped by a
881   *         {@link CompletableFuture}
882   */
883  CompletableFuture<List<SnapshotDescription>> listSnapshots();
884
885  /**
886   * List all the completed snapshots matching the given pattern.
887   * @param pattern The compiled regular expression to match against
888   * @return - returns a List of SnapshotDescription wrapped by a {@link CompletableFuture}
889   */
890  CompletableFuture<List<SnapshotDescription>> listSnapshots(Pattern pattern);
891
892  /**
893   * List all the completed snapshots matching the given table name pattern.
894   * @param tableNamePattern The compiled table name regular expression to match against
895   * @return - returns a List of completed SnapshotDescription wrapped by a
896   *         {@link CompletableFuture}
897   */
898  CompletableFuture<List<SnapshotDescription>> listTableSnapshots(Pattern tableNamePattern);
899
900  /**
901   * List all the completed snapshots matching the given table name regular expression and snapshot
902   * name regular expression.
903   * @param tableNamePattern The compiled table name regular expression to match against
904   * @param snapshotNamePattern The compiled snapshot name regular expression to match against
905   * @return - returns a List of completed SnapshotDescription wrapped by a
906   *         {@link CompletableFuture}
907   */
908  CompletableFuture<List<SnapshotDescription>> listTableSnapshots(Pattern tableNamePattern,
909      Pattern snapshotNamePattern);
910
911  /**
912   * Delete an existing snapshot.
913   * @param snapshotName name of the snapshot
914   */
915  CompletableFuture<Void> deleteSnapshot(String snapshotName);
916
917  /**
918   * Delete all existing snapshots.
919   */
920  CompletableFuture<Void> deleteSnapshots();
921
922  /**
923   * Delete existing snapshots whose names match the pattern passed.
924   * @param pattern pattern for names of the snapshot to match
925   */
926  CompletableFuture<Void> deleteSnapshots(Pattern pattern);
927
928  /**
929   * Delete all existing snapshots matching the given table name pattern.
930   * @param tableNamePattern The compiled table name regular expression to match against
931   */
932  CompletableFuture<Void> deleteTableSnapshots(Pattern tableNamePattern);
933
934  /**
935   * Delete all existing snapshots matching the given table name regular expression and snapshot
936   * name regular expression.
937   * @param tableNamePattern The compiled table name regular expression to match against
938   * @param snapshotNamePattern The compiled snapshot name regular expression to match against
939   */
940  CompletableFuture<Void> deleteTableSnapshots(Pattern tableNamePattern,
941      Pattern snapshotNamePattern);
942
943  /**
944   * Execute a distributed procedure on a cluster.
945   * @param signature A distributed procedure is uniquely identified by its signature (default the
946   *          root ZK node name of the procedure).
947   * @param instance The instance name of the procedure. For some procedures, this parameter is
948   *          optional.
949   * @param props Property/Value pairs of properties passing to the procedure
950   */
951  CompletableFuture<Void> execProcedure(String signature, String instance,
952      Map<String, String> props);
953
954  /**
955   * Execute a distributed procedure on a cluster.
956   * @param signature A distributed procedure is uniquely identified by its signature (default the
957   *          root ZK node name of the procedure).
958   * @param instance The instance name of the procedure. For some procedures, this parameter is
959   *          optional.
960   * @param props Property/Value pairs of properties passing to the procedure
961   * @return data returned after procedure execution. null if no return data.
962   */
963  CompletableFuture<byte[]> execProcedureWithReturn(String signature, String instance,
964      Map<String, String> props);
965
966  /**
967   * Check the current state of the specified procedure. There are three possible states:
968   * <ol>
969   * <li>running - returns <tt>false</tt></li>
970   * <li>finished - returns <tt>true</tt></li>
971   * <li>finished with error - throws the exception that caused the procedure to fail</li>
972   * </ol>
973   * @param signature The signature that uniquely identifies a procedure
974   * @param instance The instance name of the procedure
975   * @param props Property/Value pairs of properties passing to the procedure
976   * @return true if the specified procedure is finished successfully, false if it is still running.
977   *         The value is wrapped by {@link CompletableFuture}
978   */
979  CompletableFuture<Boolean> isProcedureFinished(String signature, String instance,
980      Map<String, String> props);
981
982  /**
983   * Abort a procedure
984   * Do not use. Usually it is ignored but if not, it can do more damage than good. See hbck2.
985   * @param procId ID of the procedure to abort
986   * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
987   * @return true if aborted, false if procedure already completed or does not exist. the value is
988   *         wrapped by {@link CompletableFuture}
989   * @deprecated since 2.1.1 and will be removed in 4.0.0.
990   * @see <a href="https://issues.apache.org/jira/browse/HBASE-21223">HBASE-21223</a>
991   */
992  @Deprecated
993  CompletableFuture<Boolean> abortProcedure(long procId, boolean mayInterruptIfRunning);
994
995  /**
996   * List procedures
997   * @return procedure list JSON wrapped by {@link CompletableFuture}
998   */
999  CompletableFuture<String> getProcedures();
1000
1001  /**
1002   * List locks.
1003   * @return lock list JSON wrapped by {@link CompletableFuture}
1004   */
1005  CompletableFuture<String> getLocks();
1006
1007  /**
1008   * Mark region server(s) as decommissioned to prevent additional regions from getting
1009   * assigned to them. Optionally unload the regions on the servers. If there are multiple servers
1010   * to be decommissioned, decommissioning them at the same time can prevent wasteful region
1011   * movements. Region unloading is asynchronous.
1012   * @param servers The list of servers to decommission.
1013   * @param offload True to offload the regions from the decommissioned servers
1014   */
1015  CompletableFuture<Void> decommissionRegionServers(List<ServerName> servers, boolean offload);
1016
1017  /**
1018   * List region servers marked as decommissioned, which can not be assigned regions.
1019   * @return List of decommissioned region servers wrapped by {@link CompletableFuture}
1020   */
1021  CompletableFuture<List<ServerName>> listDecommissionedRegionServers();
1022
1023  /**
1024   * Remove decommission marker from a region server to allow regions assignments. Load regions onto
1025   * the server if a list of regions is given. Region loading is asynchronous.
1026   * @param server The server to recommission.
1027   * @param encodedRegionNames Regions to load onto the server.
1028   */
1029  CompletableFuture<Void> recommissionRegionServer(ServerName server,
1030      List<byte[]> encodedRegionNames);
1031
1032  /**
1033   * @return cluster status wrapped by {@link CompletableFuture}
1034   */
1035  CompletableFuture<ClusterMetrics> getClusterMetrics();
1036
1037  /**
1038   * @return cluster status wrapped by {@link CompletableFuture}
1039   */
1040  CompletableFuture<ClusterMetrics> getClusterMetrics(EnumSet<Option> options);
1041
1042  /**
1043   * @return current master server name wrapped by {@link CompletableFuture}
1044   */
1045  default CompletableFuture<ServerName> getMaster() {
1046    return getClusterMetrics(EnumSet.of(Option.MASTER)).thenApply(ClusterMetrics::getMasterName);
1047  }
1048
1049  /**
1050   * @return current backup master list wrapped by {@link CompletableFuture}
1051   */
1052  default CompletableFuture<Collection<ServerName>> getBackupMasters() {
1053    return getClusterMetrics(EnumSet.of(Option.BACKUP_MASTERS))
1054      .thenApply(ClusterMetrics::getBackupMasterNames);
1055  }
1056
1057  /**
1058   * @return current live region servers list wrapped by {@link CompletableFuture}
1059   */
1060  default CompletableFuture<Collection<ServerName>> getRegionServers() {
1061    return getClusterMetrics(EnumSet.of(Option.SERVERS_NAME))
1062        .thenApply(ClusterMetrics::getServersName);
1063  }
1064
1065  default CompletableFuture<Collection<ServerName>> getRegionServers(
1066    boolean excludeDecommissionedRS) {
1067    CompletableFuture<Collection<ServerName>> future = new CompletableFuture<>();
1068    addListener(
1069      getClusterMetrics(EnumSet.of(Option.SERVERS_NAME)).thenApply(ClusterMetrics::getServersName),
1070      (allServers, err) -> {
1071        if (err != null) {
1072          future.completeExceptionally(err);
1073        } else {
1074          if (!excludeDecommissionedRS) {
1075            future.complete(allServers);
1076          } else {
1077            addListener(listDecommissionedRegionServers(), (decomServers, decomErr) -> {
1078              if (decomErr != null) {
1079                future.completeExceptionally(decomErr);
1080              } else {
1081                future.complete(allServers.stream().filter(s -> !decomServers.contains(s))
1082                  .collect(ImmutableList.toImmutableList()));
1083              }
1084            });
1085          }
1086        }
1087      });
1088    return future;
1089  }
1090
1091  /**
1092   * @return a list of master coprocessors wrapped by {@link CompletableFuture}
1093   */
1094  default CompletableFuture<List<String>> getMasterCoprocessorNames() {
1095    return getClusterMetrics(EnumSet.of(Option.MASTER_COPROCESSORS))
1096        .thenApply(ClusterMetrics::getMasterCoprocessorNames);
1097  }
1098
1099  /**
1100   * Get the info port of the current master if one is available.
1101   * @return master info port
1102   */
1103  default CompletableFuture<Integer> getMasterInfoPort() {
1104    return getClusterMetrics(EnumSet.of(Option.MASTER_INFO_PORT)).thenApply(
1105      ClusterMetrics::getMasterInfoPort);
1106  }
1107
1108  /**
1109   * Shuts down the HBase cluster.
1110   */
1111  CompletableFuture<Void> shutdown();
1112
1113  /**
1114   * Shuts down the current HBase master only.
1115   */
1116  CompletableFuture<Void> stopMaster();
1117
1118  /**
1119   * Stop the designated regionserver.
1120   * @param serverName
1121   */
1122  CompletableFuture<Void> stopRegionServer(ServerName serverName);
1123
1124  /**
1125   * Update the configuration and trigger an online config change on the regionserver.
1126   * @param serverName : The server whose config needs to be updated.
1127   */
1128  CompletableFuture<Void> updateConfiguration(ServerName serverName);
1129
1130  /**
1131   * Update the configuration and trigger an online config change on all the masters and
1132   * regionservers.
1133   */
1134  CompletableFuture<Void> updateConfiguration();
1135
1136  /**
1137   * Roll the log writer. I.e. for filesystem based write ahead logs, start writing to a new file.
1138   * <p>
1139   * When the returned CompletableFuture is done, it only means the rollWALWriter request was sent
1140   * to the region server and may need some time to finish the rollWALWriter operation. As a side
1141   * effect of this call, the named region server may schedule store flushes at the request of the
1142   * wal.
1143   * @param serverName The servername of the region server.
1144   */
1145  CompletableFuture<Void> rollWALWriter(ServerName serverName);
1146
1147  /**
1148   * Clear compacting queues on a region server.
1149   * @param serverName
1150   * @param queues the set of queue name
1151   */
1152  CompletableFuture<Void> clearCompactionQueues(ServerName serverName, Set<String> queues);
1153
1154  /**
1155   * Get a list of {@link RegionMetrics} of all regions hosted on a region seerver.
1156   * @param serverName
1157   * @return a list of {@link RegionMetrics} wrapped by {@link CompletableFuture}
1158   */
1159  CompletableFuture<List<RegionMetrics>> getRegionMetrics(ServerName serverName);
1160
1161  /**
1162   * Get a list of {@link RegionMetrics} of all regions hosted on a region seerver for a table.
1163   * @param serverName
1164   * @param tableName
1165   * @return a list of {@link RegionMetrics} wrapped by {@link CompletableFuture}
1166   */
1167  CompletableFuture<List<RegionMetrics>> getRegionMetrics(ServerName serverName,
1168    TableName tableName);
1169
1170  /**
1171   * Check whether master is in maintenance mode
1172   * @return true if master is in maintenance mode, false otherwise. The return value will be
1173   *         wrapped by a {@link CompletableFuture}
1174   */
1175  CompletableFuture<Boolean> isMasterInMaintenanceMode();
1176
1177  /**
1178   * Get the current compaction state of a table. It could be in a major compaction, a minor
1179   * compaction, both, or none.
1180   * @param tableName table to examine
1181   * @return the current compaction state wrapped by a {@link CompletableFuture}
1182   */
1183  default CompletableFuture<CompactionState> getCompactionState(TableName tableName) {
1184    return getCompactionState(tableName, CompactType.NORMAL);
1185  }
1186
1187  /**
1188   * Get the current compaction state of a table. It could be in a major compaction, a minor
1189   * compaction, both, or none.
1190   * @param tableName table to examine
1191   * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
1192   * @return the current compaction state wrapped by a {@link CompletableFuture}
1193   */
1194  CompletableFuture<CompactionState> getCompactionState(TableName tableName,
1195      CompactType compactType);
1196
1197  /**
1198   * Get the current compaction state of region. It could be in a major compaction, a minor
1199   * compaction, both, or none.
1200   * @param regionName region to examine
1201   * @return the current compaction state wrapped by a {@link CompletableFuture}
1202   */
1203  CompletableFuture<CompactionState> getCompactionStateForRegion(byte[] regionName);
1204
1205  /**
1206   * Get the timestamp of the last major compaction for the passed table.
1207   * <p>
1208   * The timestamp of the oldest HFile resulting from a major compaction of that table, or not
1209   * present if no such HFile could be found.
1210   * @param tableName table to examine
1211   * @return the last major compaction timestamp wrapped by a {@link CompletableFuture}
1212   */
1213  CompletableFuture<Optional<Long>> getLastMajorCompactionTimestamp(TableName tableName);
1214
1215  /**
1216   * Get the timestamp of the last major compaction for the passed region.
1217   * <p>
1218   * The timestamp of the oldest HFile resulting from a major compaction of that region, or not
1219   * present if no such HFile could be found.
1220   * @param regionName region to examine
1221   * @return the last major compaction timestamp wrapped by a {@link CompletableFuture}
1222   */
1223  CompletableFuture<Optional<Long>> getLastMajorCompactionTimestampForRegion(byte[] regionName);
1224
1225  /**
1226   * @return the list of supported security capabilities. The return value will be wrapped by a
1227   *         {@link CompletableFuture}.
1228   */
1229  CompletableFuture<List<SecurityCapability>> getSecurityCapabilities();
1230
1231  /**
1232   * Turn the load balancer on or off.
1233   * @param on Set to <code>true</code> to enable, <code>false</code> to disable.
1234   * @return Previous balancer value wrapped by a {@link CompletableFuture}.
1235   */
1236  default CompletableFuture<Boolean> balancerSwitch(boolean on) {
1237    return balancerSwitch(on, false);
1238  }
1239
1240  /**
1241   * Turn the load balancer on or off.
1242   * <p/>
1243   * Notice that, the method itself is always non-blocking, which means it will always return
1244   * immediately. The {@code drainRITs} parameter only effects when will we complete the returned
1245   * {@link CompletableFuture}.
1246   * @param on Set to <code>true</code> to enable, <code>false</code> to disable.
1247   * @param drainRITs If <code>true</code>, it waits until current balance() call, if outstanding,
1248   *          to return.
1249   * @return Previous balancer value wrapped by a {@link CompletableFuture}.
1250   */
1251  CompletableFuture<Boolean> balancerSwitch(boolean on, boolean drainRITs);
1252
1253  /**
1254   * Invoke the balancer. Will run the balancer and if regions to move, it will go ahead and do the
1255   * reassignments. Can NOT run for various reasons. Check logs.
1256   * @return True if balancer ran, false otherwise. The return value will be wrapped by a
1257   *         {@link CompletableFuture}.
1258   */
1259  default CompletableFuture<Boolean> balance() {
1260    return balance(false);
1261  }
1262
1263  /**
1264   * Invoke the balancer. Will run the balancer and if regions to move, it will go ahead and do the
1265   * reassignments. If there is region in transition, force parameter of true would still run
1266   * balancer. Can *not* run for other reasons. Check logs.
1267   * @param forcible whether we should force balance even if there is region in transition.
1268   * @return True if balancer ran, false otherwise. The return value will be wrapped by a
1269   *         {@link CompletableFuture}.
1270   */
1271  CompletableFuture<Boolean> balance(boolean forcible);
1272
1273  /**
1274   * Query the current state of the balancer.
1275   * @return true if the balance switch is on, false otherwise. The return value will be wrapped by a
1276   *         {@link CompletableFuture}.
1277   */
1278  CompletableFuture<Boolean> isBalancerEnabled();
1279
1280  /**
1281   * Set region normalizer on/off.
1282   * @param on whether normalizer should be on or off
1283   * @return Previous normalizer value wrapped by a {@link CompletableFuture}
1284   */
1285  CompletableFuture<Boolean> normalizerSwitch(boolean on);
1286
1287  /**
1288   * Query the current state of the region normalizer
1289   * @return true if region normalizer is on, false otherwise. The return value will be wrapped by a
1290   *         {@link CompletableFuture}
1291   */
1292  CompletableFuture<Boolean> isNormalizerEnabled();
1293
1294  /**
1295   * Invoke region normalizer. Can NOT run for various reasons. Check logs.
1296   * @return true if region normalizer ran, false otherwise. The return value will be wrapped by a
1297   *         {@link CompletableFuture}
1298   */
1299  default CompletableFuture<Boolean> normalize() {
1300    return normalize(new NormalizeTableFilterParams.Builder().build());
1301  }
1302
1303  /**
1304   * Invoke region normalizer. Can NOT run for various reasons. Check logs.
1305   * @param ntfp limit to tables matching the specified filter.
1306   * @return true if region normalizer ran, false otherwise. The return value will be wrapped by a
1307   *         {@link CompletableFuture}
1308   */
1309  CompletableFuture<Boolean> normalize(NormalizeTableFilterParams ntfp);
1310
1311  /**
1312   * Turn the cleaner chore on/off.
1313   * @param on
1314   * @return Previous cleaner state wrapped by a {@link CompletableFuture}
1315   */
1316  CompletableFuture<Boolean> cleanerChoreSwitch(boolean on);
1317
1318  /**
1319   * Query the current state of the cleaner chore.
1320   * @return true if cleaner chore is on, false otherwise. The return value will be wrapped by
1321   *         a {@link CompletableFuture}
1322   */
1323  CompletableFuture<Boolean> isCleanerChoreEnabled();
1324
1325  /**
1326   * Ask for cleaner chore to run.
1327   * @return true if cleaner chore ran, false otherwise. The return value will be wrapped by a
1328   *         {@link CompletableFuture}
1329   */
1330  CompletableFuture<Boolean> runCleanerChore();
1331
1332  /**
1333   * Turn the catalog janitor on/off.
1334   * @param on
1335   * @return the previous state wrapped by a {@link CompletableFuture}
1336   */
1337  CompletableFuture<Boolean> catalogJanitorSwitch(boolean on);
1338
1339  /**
1340   * Query on the catalog janitor state.
1341   * @return true if the catalog janitor is on, false otherwise. The return value will be
1342   *         wrapped by a {@link CompletableFuture}
1343   */
1344  CompletableFuture<Boolean> isCatalogJanitorEnabled();
1345
1346  /**
1347   * Ask for a scan of the catalog table.
1348   * @return the number of entries cleaned. The return value will be wrapped by a
1349   *         {@link CompletableFuture}
1350   */
1351  CompletableFuture<Integer> runCatalogJanitor();
1352
1353  /**
1354   * Execute the given coprocessor call on the master.
1355   * <p>
1356   * The {@code stubMaker} is just a delegation to the {@code newStub} call. Usually it is only a
1357   * one line lambda expression, like:
1358   *
1359   * <pre>
1360   * <code>
1361   * channel -> xxxService.newStub(channel)
1362   * </code>
1363   * </pre>
1364   * @param stubMaker a delegation to the actual {@code newStub} call.
1365   * @param callable a delegation to the actual protobuf rpc call. See the comment of
1366   *          {@link ServiceCaller} for more details.
1367   * @param <S> the type of the asynchronous stub
1368   * @param <R> the type of the return value
1369   * @return the return value of the protobuf rpc call, wrapped by a {@link CompletableFuture}.
1370   * @see ServiceCaller
1371   */
1372  <S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker,
1373      ServiceCaller<S, R> callable);
1374
1375  /**
1376   * Execute the given coprocessor call on the given region server.
1377   * <p>
1378   * The {@code stubMaker} is just a delegation to the {@code newStub} call. Usually it is only a
1379   * one line lambda expression, like:
1380   *
1381   * <pre>
1382   * <code>
1383   * channel -> xxxService.newStub(channel)
1384   * </code>
1385   * </pre>
1386   * @param stubMaker a delegation to the actual {@code newStub} call.
1387   * @param callable a delegation to the actual protobuf rpc call. See the comment of
1388   *          {@link ServiceCaller} for more details.
1389   * @param serverName the given region server
1390   * @param <S> the type of the asynchronous stub
1391   * @param <R> the type of the return value
1392   * @return the return value of the protobuf rpc call, wrapped by a {@link CompletableFuture}.
1393   * @see ServiceCaller
1394   */
1395  <S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker,
1396    ServiceCaller<S, R> callable, ServerName serverName);
1397
1398  /**
1399   * List all the dead region servers.
1400   */
1401  default CompletableFuture<List<ServerName>> listDeadServers() {
1402    return this.getClusterMetrics(EnumSet.of(Option.DEAD_SERVERS))
1403        .thenApply(ClusterMetrics::getDeadServerNames);
1404  }
1405
1406  /**
1407   * Clear dead region servers from master.
1408   * @param servers list of dead region servers.
1409   * @return - returns a list of servers that not cleared wrapped by a {@link CompletableFuture}.
1410   */
1411  CompletableFuture<List<ServerName>> clearDeadServers(final List<ServerName> servers);
1412
1413  /**
1414   * Clear all the blocks corresponding to this table from BlockCache. For expert-admins. Calling
1415   * this API will drop all the cached blocks specific to a table from BlockCache. This can
1416   * significantly impact the query performance as the subsequent queries will have to retrieve the
1417   * blocks from underlying filesystem.
1418   * @param tableName table to clear block cache
1419   * @return CacheEvictionStats related to the eviction wrapped by a {@link CompletableFuture}.
1420   */
1421  CompletableFuture<CacheEvictionStats> clearBlockCache(final TableName tableName);
1422
1423  /**
1424   * Create a new table by cloning the existent table schema.
1425   *
1426   * @param tableName name of the table to be cloned
1427   * @param newTableName name of the new table where the table will be created
1428   * @param preserveSplits True if the splits should be preserved
1429   */
1430  CompletableFuture<Void>  cloneTableSchema(final TableName tableName,
1431      final TableName newTableName, final boolean preserveSplits);
1432
1433  /**
1434   * Turn the compaction on or off. Disabling compactions will also interrupt any currently ongoing
1435   * compactions. This state is ephemeral. The setting will be lost on restart. Compaction
1436   * can also be enabled/disabled by modifying configuration hbase.regionserver.compaction.enabled
1437   * in hbase-site.xml.
1438   *
1439   * @param switchState     Set to <code>true</code> to enable, <code>false</code> to disable.
1440   * @param serverNamesList list of region servers.
1441   * @return Previous compaction states for region servers
1442   */
1443  CompletableFuture<Map<ServerName, Boolean>> compactionSwitch(boolean switchState,
1444      List<String> serverNamesList);
1445
1446  /**
1447   * Switch the rpc throttle enabled state.
1448   * @param enable Set to <code>true</code> to enable, <code>false</code> to disable.
1449   * @return Previous rpc throttle enabled value
1450   */
1451  CompletableFuture<Boolean> switchRpcThrottle(boolean enable);
1452
1453  /**
1454   * Get if the rpc throttle is enabled.
1455   * @return True if rpc throttle is enabled
1456   */
1457  CompletableFuture<Boolean> isRpcThrottleEnabled();
1458
1459  /**
1460   * Switch the exceed throttle quota. If enabled, user/table/namespace throttle quota
1461   * can be exceeded if region server has availble quota.
1462   * @param enable Set to <code>true</code> to enable, <code>false</code> to disable.
1463   * @return Previous exceed throttle enabled value
1464   */
1465  CompletableFuture<Boolean> exceedThrottleQuotaSwitch(boolean enable);
1466
1467  /**
1468   * Fetches the table sizes on the filesystem as tracked by the HBase Master.
1469   */
1470  CompletableFuture<Map<TableName, Long>> getSpaceQuotaTableSizes();
1471
1472  /**
1473   * Fetches the observed {@link SpaceQuotaSnapshotView}s observed by a RegionServer.
1474   */
1475  CompletableFuture<? extends Map<TableName, ? extends SpaceQuotaSnapshotView>>
1476      getRegionServerSpaceQuotaSnapshots(ServerName serverName);
1477
1478  /**
1479   * Returns the Master's view of a quota on the given {@code namespace} or null if the Master has
1480   * no quota information on that namespace.
1481   */
1482  CompletableFuture<? extends SpaceQuotaSnapshotView>
1483      getCurrentSpaceQuotaSnapshot(String namespace);
1484
1485  /**
1486   * Returns the Master's view of a quota on the given {@code tableName} or null if the Master has
1487   * no quota information on that table.
1488   */
1489  CompletableFuture<? extends SpaceQuotaSnapshotView> getCurrentSpaceQuotaSnapshot(
1490      TableName tableName);
1491
1492  /**
1493   * Grants user specific permissions
1494   * @param userPermission user name and the specific permission
1495   * @param mergeExistingPermissions If set to false, later granted permissions will override
1496   *          previous granted permissions. otherwise, it'll merge with previous granted
1497   *          permissions.
1498   */
1499  CompletableFuture<Void> grant(UserPermission userPermission, boolean mergeExistingPermissions);
1500
1501  /**
1502   * Revokes user specific permissions
1503   * @param userPermission user name and the specific permission
1504   */
1505  CompletableFuture<Void> revoke(UserPermission userPermission);
1506
1507  /**
1508   * Get the global/namespace/table permissions for user
1509   * @param getUserPermissionsRequest A request contains which user, global, namespace or table
1510   *          permissions needed
1511   * @return The user and permission list
1512   */
1513  CompletableFuture<List<UserPermission>>
1514      getUserPermissions(GetUserPermissionsRequest getUserPermissionsRequest);
1515
1516  /**
1517   * Check if the user has specific permissions
1518   * @param userName the user name
1519   * @param permissions the specific permission list
1520   * @return True if user has the specific permissions
1521   */
1522  CompletableFuture<List<Boolean>> hasUserPermissions(String userName,
1523      List<Permission> permissions);
1524
1525  /**
1526   * Check if call user has specific permissions
1527   * @param permissions the specific permission list
1528   * @return True if user has the specific permissions
1529   */
1530  default CompletableFuture<List<Boolean>> hasUserPermissions(List<Permission> permissions) {
1531    return hasUserPermissions(null, permissions);
1532  }
1533
1534  /**
1535   * Turn on or off the auto snapshot cleanup based on TTL.
1536   * <p/>
1537   * Notice that, the method itself is always non-blocking, which means it will always return
1538   * immediately. The {@code sync} parameter only effects when will we complete the returned
1539   * {@link CompletableFuture}.
1540   *
1541   * @param on Set to <code>true</code> to enable, <code>false</code> to disable.
1542   * @param sync If <code>true</code>, it waits until current snapshot cleanup is completed,
1543   *   if outstanding.
1544   * @return Previous auto snapshot cleanup value wrapped by a {@link CompletableFuture}.
1545   */
1546  CompletableFuture<Boolean> snapshotCleanupSwitch(boolean on, boolean sync);
1547
1548  /**
1549   * Query the current state of the auto snapshot cleanup based on TTL.
1550   *
1551   * @return true if the auto snapshot cleanup is enabled, false otherwise.
1552   *   The return value will be wrapped by a {@link CompletableFuture}.
1553   */
1554  CompletableFuture<Boolean> isSnapshotCleanupEnabled();
1555
1556  /**
1557   * Retrieves online slow RPC logs from the provided list of
1558   * RegionServers
1559   *
1560   * @param serverNames Server names to get slowlog responses from
1561   * @param logQueryFilter filter to be used if provided
1562   * @return Online slowlog response list. The return value wrapped by a {@link CompletableFuture}
1563   * @deprecated since 2.4.0 and will be removed in 4.0.0.
1564   *   Use {@link #getLogEntries(Set, String, ServerType, int, Map)} instead.
1565   */
1566  @Deprecated
1567  default CompletableFuture<List<OnlineLogRecord>> getSlowLogResponses(
1568      final Set<ServerName> serverNames, final LogQueryFilter logQueryFilter) {
1569    String logType;
1570    if (LogQueryFilter.Type.LARGE_LOG.equals(logQueryFilter.getType())) {
1571      logType = "LARGE_LOG";
1572    } else {
1573      logType = "SLOW_LOG";
1574    }
1575    Map<String, Object> filterParams = new HashMap<>();
1576    filterParams.put("regionName", logQueryFilter.getRegionName());
1577    filterParams.put("clientAddress", logQueryFilter.getClientAddress());
1578    filterParams.put("tableName", logQueryFilter.getTableName());
1579    filterParams.put("userName", logQueryFilter.getUserName());
1580    filterParams.put("filterByOperator", logQueryFilter.getFilterByOperator().toString());
1581    CompletableFuture<List<LogEntry>> logEntries =
1582      getLogEntries(serverNames, logType, ServerType.REGION_SERVER, logQueryFilter.getLimit(),
1583        filterParams);
1584    return logEntries.thenApply(
1585      logEntryList -> logEntryList.stream().map(logEntry -> (OnlineLogRecord) logEntry)
1586        .collect(Collectors.toList()));
1587  }
1588
1589  /**
1590   * Clears online slow RPC logs from the provided list of
1591   * RegionServers
1592   *
1593   * @param serverNames Set of Server names to clean slowlog responses from
1594   * @return List of booleans representing if online slowlog response buffer is cleaned
1595   *   from each RegionServer. The return value wrapped by a {@link CompletableFuture}
1596   */
1597  CompletableFuture<List<Boolean>> clearSlowLogResponses(final Set<ServerName> serverNames);
1598
1599  /**
1600   * Retrieve recent online records from HMaster / RegionServers.
1601   * Examples include slow/large RPC logs, balancer decisions by master.
1602   *
1603   * @param serverNames servers to retrieve records from, useful in case of records maintained
1604   *   by RegionServer as we can select specific server. In case of servertype=MASTER, logs will
1605   *   only come from the currently active master.
1606   * @param logType string representing type of log records
1607   * @param serverType enum for server type: HMaster or RegionServer
1608   * @param limit put a limit to list of records that server should send in response
1609   * @param filterParams additional filter params
1610   * @return Log entries representing online records from servers
1611   */
1612  CompletableFuture<List<LogEntry>> getLogEntries(Set<ServerName> serverNames, String logType,
1613    ServerType serverType, int limit, Map<String, Object> filterParams);
1614}