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