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