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 taken
750   * sequentially even when requested concurrently, across all tables. Snapshots are considered
751   * unique based on <b>the name of the snapshot</b>. Attempts to take a snapshot with the same
752   * name (even a different type or with different parameters) will fail with a
753   * {@link org.apache.hadoop.hbase.snapshot.SnapshotCreationException} indicating the duplicate
754   * naming. Snapshot names follow the same naming constraints as tables in HBase. See
755   * {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}.
756   * @param snapshotName name of the snapshot to be created
757   * @param tableName name of the table for which snapshot is created
758   */
759  default CompletableFuture<Void> snapshot(String snapshotName, TableName tableName) {
760    return snapshot(snapshotName, tableName, SnapshotType.FLUSH);
761  }
762
763  /**
764   * Create typed snapshot of the table. Snapshots are considered unique based on <b>the name of the
765   * snapshot</b>. Snapshots are taken sequentially even when requested concurrently, across all
766   * tables. Attempts to take a snapshot with the same name (even a different type or with
767   * different parameters) will fail with a
768   * {@link org.apache.hadoop.hbase.snapshot.SnapshotCreationException} indicating the duplicate
769   * naming. Snapshot names follow the same naming constraints as tables in HBase. See
770   * {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}.
771   * @param snapshotName name to give the snapshot on the filesystem. Must be unique from all other
772   *          snapshots stored on the cluster
773   * @param tableName name of the table to snapshot
774   * @param type type of snapshot to take
775   */
776  default CompletableFuture<Void> snapshot(String snapshotName, TableName tableName,
777      SnapshotType type) {
778    return snapshot(new SnapshotDescription(snapshotName, tableName, type));
779  }
780
781  /**
782   * Take a snapshot and wait for the server to complete that snapshot asynchronously. Snapshots
783   * are taken sequentially even when requested concurrently, across all tables. Snapshots are
784   * considered unique based on <b>the name of the snapshot</b>.
785   * Attempts to take a snapshot with the same name (even a different type or with different
786   * parameters) will fail with a {@link org.apache.hadoop.hbase.snapshot.SnapshotCreationException}
787   * indicating the duplicate naming. Snapshot names follow the same naming constraints as tables in
788   * HBase. See {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}.
789   * You should probably use {@link #snapshot(String, org.apache.hadoop.hbase.TableName)} unless you
790   * are sure about the type of snapshot that you want to take.
791   * @param snapshot snapshot to take
792   */
793  CompletableFuture<Void> snapshot(SnapshotDescription snapshot);
794
795  /**
796   * Check the current state of the passed snapshot. There are three possible states:
797   * <ol>
798   * <li>running - returns <tt>false</tt></li>
799   * <li>finished - returns <tt>true</tt></li>
800   * <li>finished with error - throws the exception that caused the snapshot to fail</li>
801   * </ol>
802   * The cluster only knows about the most recent snapshot. Therefore, if another snapshot has been
803   * run/started since the snapshot you are checking, you will receive an
804   * {@link org.apache.hadoop.hbase.snapshot.UnknownSnapshotException}.
805   * @param snapshot description of the snapshot to check
806   * @return <tt>true</tt> if the snapshot is completed, <tt>false</tt> if the snapshot is still
807   *         running
808   */
809  CompletableFuture<Boolean> isSnapshotFinished(SnapshotDescription snapshot);
810
811  /**
812   * Restore the specified snapshot on the original table. (The table must be disabled) If the
813   * "hbase.snapshot.restore.take.failsafe.snapshot" configuration property is set to true, a
814   * snapshot of the current table is taken before executing the restore operation. In case of
815   * restore failure, the failsafe snapshot will be restored. If the restore completes without
816   * problem the failsafe snapshot is deleted.
817   * @param snapshotName name of the snapshot to restore
818   */
819  CompletableFuture<Void> restoreSnapshot(String snapshotName);
820
821  /**
822   * Restore the specified snapshot on the original table. (The table must be disabled) If
823   * 'takeFailSafeSnapshot' is set to true, a snapshot of the current table is taken before
824   * executing the restore operation. In case of restore failure, the failsafe snapshot will be
825   * restored. If the restore completes without problem the failsafe snapshot is deleted. The
826   * failsafe snapshot name is configurable by using the property
827   * "hbase.snapshot.restore.failsafe.name".
828   * @param snapshotName name of the snapshot to restore
829   * @param takeFailSafeSnapshot true if the failsafe snapshot should be taken
830   */
831  default CompletableFuture<Void> restoreSnapshot(String snapshotName,
832      boolean takeFailSafeSnapshot) {
833    return restoreSnapshot(snapshotName, takeFailSafeSnapshot, false);
834  }
835
836  /**
837   * Restore the specified snapshot on the original table. (The table must be disabled) If
838   * 'takeFailSafeSnapshot' is set to true, a snapshot of the current table is taken before
839   * executing the restore operation. In case of restore failure, the failsafe snapshot will be
840   * restored. If the restore completes without problem the failsafe snapshot is deleted. The
841   * failsafe snapshot name is configurable by using the property
842   * "hbase.snapshot.restore.failsafe.name".
843   * @param snapshotName name of the snapshot to restore
844   * @param takeFailSafeSnapshot true if the failsafe snapshot should be taken
845   * @param restoreAcl <code>true</code> to restore acl of snapshot
846   */
847  CompletableFuture<Void> restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot,
848      boolean restoreAcl);
849
850  /**
851   * Create a new table by cloning the snapshot content.
852   * @param snapshotName name of the snapshot to be cloned
853   * @param tableName name of the table where the snapshot will be restored
854   */
855  default CompletableFuture<Void> cloneSnapshot(String snapshotName, TableName tableName) {
856    return cloneSnapshot(snapshotName, tableName, false);
857  }
858
859  /**
860   * Create a new table by cloning the snapshot content.
861   * @param snapshotName name of the snapshot to be cloned
862   * @param tableName name of the table where the snapshot will be restored
863   * @param restoreAcl <code>true</code> to restore acl of snapshot
864   */
865  CompletableFuture<Void> cloneSnapshot(String snapshotName, TableName tableName,
866      boolean restoreAcl);
867
868  /**
869   * List completed snapshots.
870   * @return a list of snapshot descriptors for completed snapshots wrapped by a
871   *         {@link CompletableFuture}
872   */
873  CompletableFuture<List<SnapshotDescription>> listSnapshots();
874
875  /**
876   * List all the completed snapshots matching the given pattern.
877   * @param pattern The compiled regular expression to match against
878   * @return - returns a List of SnapshotDescription wrapped by a {@link CompletableFuture}
879   */
880  CompletableFuture<List<SnapshotDescription>> listSnapshots(Pattern pattern);
881
882  /**
883   * List all the completed snapshots matching the given table name pattern.
884   * @param tableNamePattern The compiled table name regular expression to match against
885   * @return - returns a List of completed SnapshotDescription wrapped by a
886   *         {@link CompletableFuture}
887   */
888  CompletableFuture<List<SnapshotDescription>> listTableSnapshots(Pattern tableNamePattern);
889
890  /**
891   * List all the completed snapshots matching the given table name regular expression and snapshot
892   * name regular expression.
893   * @param tableNamePattern The compiled table name regular expression to match against
894   * @param snapshotNamePattern The compiled snapshot name regular expression to match against
895   * @return - returns a List of completed SnapshotDescription wrapped by a
896   *         {@link CompletableFuture}
897   */
898  CompletableFuture<List<SnapshotDescription>> listTableSnapshots(Pattern tableNamePattern,
899      Pattern snapshotNamePattern);
900
901  /**
902   * Delete an existing snapshot.
903   * @param snapshotName name of the snapshot
904   */
905  CompletableFuture<Void> deleteSnapshot(String snapshotName);
906
907  /**
908   * Delete all existing snapshots.
909   */
910  CompletableFuture<Void> deleteSnapshots();
911
912  /**
913   * Delete existing snapshots whose names match the pattern passed.
914   * @param pattern pattern for names of the snapshot to match
915   */
916  CompletableFuture<Void> deleteSnapshots(Pattern pattern);
917
918  /**
919   * Delete all existing snapshots matching the given table name pattern.
920   * @param tableNamePattern The compiled table name regular expression to match against
921   */
922  CompletableFuture<Void> deleteTableSnapshots(Pattern tableNamePattern);
923
924  /**
925   * Delete all existing snapshots matching the given table name regular expression and snapshot
926   * name regular expression.
927   * @param tableNamePattern The compiled table name regular expression to match against
928   * @param snapshotNamePattern The compiled snapshot name regular expression to match against
929   */
930  CompletableFuture<Void> deleteTableSnapshots(Pattern tableNamePattern,
931      Pattern snapshotNamePattern);
932
933  /**
934   * Execute a distributed procedure on a cluster.
935   * @param signature A distributed procedure is uniquely identified by its signature (default the
936   *          root ZK node name of the procedure).
937   * @param instance The instance name of the procedure. For some procedures, this parameter is
938   *          optional.
939   * @param props Property/Value pairs of properties passing to the procedure
940   */
941  CompletableFuture<Void> execProcedure(String signature, String instance,
942      Map<String, String> props);
943
944  /**
945   * Execute a distributed procedure on a cluster.
946   * @param signature A distributed procedure is uniquely identified by its signature (default the
947   *          root ZK node name of the procedure).
948   * @param instance The instance name of the procedure. For some procedures, this parameter is
949   *          optional.
950   * @param props Property/Value pairs of properties passing to the procedure
951   * @return data returned after procedure execution. null if no return data.
952   */
953  CompletableFuture<byte[]> execProcedureWithReturn(String signature, String instance,
954      Map<String, String> props);
955
956  /**
957   * Check the current state of the specified procedure. There are three possible states:
958   * <ol>
959   * <li>running - returns <tt>false</tt></li>
960   * <li>finished - returns <tt>true</tt></li>
961   * <li>finished with error - throws the exception that caused the procedure to fail</li>
962   * </ol>
963   * @param signature The signature that uniquely identifies a procedure
964   * @param instance The instance name of the procedure
965   * @param props Property/Value pairs of properties passing to the procedure
966   * @return true if the specified procedure is finished successfully, false if it is still running.
967   *         The value is wrapped by {@link CompletableFuture}
968   */
969  CompletableFuture<Boolean> isProcedureFinished(String signature, String instance,
970      Map<String, String> props);
971
972  /**
973   * Abort a procedure
974   * Do not use. Usually it is ignored but if not, it can do more damage than good. See hbck2.
975   * @param procId ID of the procedure to abort
976   * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
977   * @return true if aborted, false if procedure already completed or does not exist. the value is
978   *         wrapped by {@link CompletableFuture}
979   * @deprecated since 2.1.1 and will be removed in 4.0.0.
980   * @see <a href="https://issues.apache.org/jira/browse/HBASE-21223">HBASE-21223</a>
981   */
982  @Deprecated
983  CompletableFuture<Boolean> abortProcedure(long procId, boolean mayInterruptIfRunning);
984
985  /**
986   * List procedures
987   * @return procedure list JSON wrapped by {@link CompletableFuture}
988   */
989  CompletableFuture<String> getProcedures();
990
991  /**
992   * List locks.
993   * @return lock list JSON wrapped by {@link CompletableFuture}
994   */
995  CompletableFuture<String> getLocks();
996
997  /**
998   * Mark region server(s) as decommissioned to prevent additional regions from getting
999   * assigned to them. Optionally unload the regions on the servers. If there are multiple servers
1000   * to be decommissioned, decommissioning them at the same time can prevent wasteful region
1001   * movements. Region unloading is asynchronous.
1002   * @param servers The list of servers to decommission.
1003   * @param offload True to offload the regions from the decommissioned servers
1004   */
1005  CompletableFuture<Void> decommissionRegionServers(List<ServerName> servers, boolean offload);
1006
1007  /**
1008   * List region servers marked as decommissioned, which can not be assigned regions.
1009   * @return List of decommissioned region servers wrapped by {@link CompletableFuture}
1010   */
1011  CompletableFuture<List<ServerName>> listDecommissionedRegionServers();
1012
1013  /**
1014   * Remove decommission marker from a region server to allow regions assignments. Load regions onto
1015   * the server if a list of regions is given. Region loading is asynchronous.
1016   * @param server The server to recommission.
1017   * @param encodedRegionNames Regions to load onto the server.
1018   */
1019  CompletableFuture<Void> recommissionRegionServer(ServerName server,
1020      List<byte[]> encodedRegionNames);
1021
1022  /**
1023   * @return cluster status wrapped by {@link CompletableFuture}
1024   */
1025  CompletableFuture<ClusterMetrics> getClusterMetrics();
1026
1027  /**
1028   * @return cluster status wrapped by {@link CompletableFuture}
1029   */
1030  CompletableFuture<ClusterMetrics> getClusterMetrics(EnumSet<Option> options);
1031
1032  /**
1033   * @return current master server name wrapped by {@link CompletableFuture}
1034   */
1035  default CompletableFuture<ServerName> getMaster() {
1036    return getClusterMetrics(EnumSet.of(Option.MASTER)).thenApply(ClusterMetrics::getMasterName);
1037  }
1038
1039  /**
1040   * @return current backup master list wrapped by {@link CompletableFuture}
1041   */
1042  default CompletableFuture<Collection<ServerName>> getBackupMasters() {
1043    return getClusterMetrics(EnumSet.of(Option.BACKUP_MASTERS))
1044      .thenApply(ClusterMetrics::getBackupMasterNames);
1045  }
1046
1047  /**
1048   * @return current live region servers list wrapped by {@link CompletableFuture}
1049   */
1050  default CompletableFuture<Collection<ServerName>> getRegionServers() {
1051    return getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS))
1052      .thenApply(cm -> cm.getLiveServerMetrics().keySet());
1053  }
1054
1055  /**
1056   * @return a list of master coprocessors wrapped by {@link CompletableFuture}
1057   */
1058  default CompletableFuture<List<String>> getMasterCoprocessorNames() {
1059    return getClusterMetrics(EnumSet.of(Option.MASTER_COPROCESSORS))
1060        .thenApply(ClusterMetrics::getMasterCoprocessorNames);
1061  }
1062
1063  /**
1064   * Get the info port of the current master if one is available.
1065   * @return master info port
1066   */
1067  default CompletableFuture<Integer> getMasterInfoPort() {
1068    return getClusterMetrics(EnumSet.of(Option.MASTER_INFO_PORT)).thenApply(
1069      ClusterMetrics::getMasterInfoPort);
1070  }
1071
1072  /**
1073   * Shuts down the HBase cluster.
1074   */
1075  CompletableFuture<Void> shutdown();
1076
1077  /**
1078   * Shuts down the current HBase master only.
1079   */
1080  CompletableFuture<Void> stopMaster();
1081
1082  /**
1083   * Stop the designated regionserver.
1084   * @param serverName
1085   */
1086  CompletableFuture<Void> stopRegionServer(ServerName serverName);
1087
1088  /**
1089   * Update the configuration and trigger an online config change on the regionserver.
1090   * @param serverName : The server whose config needs to be updated.
1091   */
1092  CompletableFuture<Void> updateConfiguration(ServerName serverName);
1093
1094  /**
1095   * Update the configuration and trigger an online config change on all the masters and
1096   * regionservers.
1097   */
1098  CompletableFuture<Void> updateConfiguration();
1099
1100  /**
1101   * Roll the log writer. I.e. for filesystem based write ahead logs, start writing to a new file.
1102   * <p>
1103   * When the returned CompletableFuture is done, it only means the rollWALWriter request was sent
1104   * to the region server and may need some time to finish the rollWALWriter operation. As a side
1105   * effect of this call, the named region server may schedule store flushes at the request of the
1106   * wal.
1107   * @param serverName The servername of the region server.
1108   */
1109  CompletableFuture<Void> rollWALWriter(ServerName serverName);
1110
1111  /**
1112   * Clear compacting queues on a region server.
1113   * @param serverName
1114   * @param queues the set of queue name
1115   */
1116  CompletableFuture<Void> clearCompactionQueues(ServerName serverName, Set<String> queues);
1117
1118  /**
1119   * Get a list of {@link RegionMetrics} of all regions hosted on a region seerver.
1120   * @param serverName
1121   * @return a list of {@link RegionMetrics} wrapped by {@link CompletableFuture}
1122   */
1123  CompletableFuture<List<RegionMetrics>> getRegionMetrics(ServerName serverName);
1124
1125  /**
1126   * Get a list of {@link RegionMetrics} of all regions hosted on a region seerver for a table.
1127   * @param serverName
1128   * @param tableName
1129   * @return a list of {@link RegionMetrics} wrapped by {@link CompletableFuture}
1130   */
1131  CompletableFuture<List<RegionMetrics>> getRegionMetrics(ServerName serverName,
1132    TableName tableName);
1133
1134  /**
1135   * Check whether master is in maintenance mode
1136   * @return true if master is in maintenance mode, false otherwise. The return value will be
1137   *         wrapped by a {@link CompletableFuture}
1138   */
1139  CompletableFuture<Boolean> isMasterInMaintenanceMode();
1140
1141  /**
1142   * Get the current compaction state of a table. It could be in a major compaction, a minor
1143   * compaction, both, or none.
1144   * @param tableName table to examine
1145   * @return the current compaction state wrapped by a {@link CompletableFuture}
1146   */
1147  default CompletableFuture<CompactionState> getCompactionState(TableName tableName) {
1148    return getCompactionState(tableName, CompactType.NORMAL);
1149  }
1150
1151  /**
1152   * Get the current compaction state of a table. It could be in a major compaction, a minor
1153   * compaction, both, or none.
1154   * @param tableName table to examine
1155   * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
1156   * @return the current compaction state wrapped by a {@link CompletableFuture}
1157   */
1158  CompletableFuture<CompactionState> getCompactionState(TableName tableName,
1159      CompactType compactType);
1160
1161  /**
1162   * Get the current compaction state of region. It could be in a major compaction, a minor
1163   * compaction, both, or none.
1164   * @param regionName region to examine
1165   * @return the current compaction state wrapped by a {@link CompletableFuture}
1166   */
1167  CompletableFuture<CompactionState> getCompactionStateForRegion(byte[] regionName);
1168
1169  /**
1170   * Get the timestamp of the last major compaction for the passed table.
1171   * <p>
1172   * The timestamp of the oldest HFile resulting from a major compaction of that table, or not
1173   * present if no such HFile could be found.
1174   * @param tableName table to examine
1175   * @return the last major compaction timestamp wrapped by a {@link CompletableFuture}
1176   */
1177  CompletableFuture<Optional<Long>> getLastMajorCompactionTimestamp(TableName tableName);
1178
1179  /**
1180   * Get the timestamp of the last major compaction for the passed region.
1181   * <p>
1182   * The timestamp of the oldest HFile resulting from a major compaction of that region, or not
1183   * present if no such HFile could be found.
1184   * @param regionName region to examine
1185   * @return the last major compaction timestamp wrapped by a {@link CompletableFuture}
1186   */
1187  CompletableFuture<Optional<Long>> getLastMajorCompactionTimestampForRegion(byte[] regionName);
1188
1189  /**
1190   * @return the list of supported security capabilities. The return value will be wrapped by a
1191   *         {@link CompletableFuture}.
1192   */
1193  CompletableFuture<List<SecurityCapability>> getSecurityCapabilities();
1194
1195  /**
1196   * Turn the load balancer on or off.
1197   * @param on Set to <code>true</code> to enable, <code>false</code> to disable.
1198   * @return Previous balancer value wrapped by a {@link CompletableFuture}.
1199   */
1200  default CompletableFuture<Boolean> balancerSwitch(boolean on) {
1201    return balancerSwitch(on, false);
1202  }
1203
1204  /**
1205   * Turn the load balancer on or off.
1206   * <p/>
1207   * Notice that, the method itself is always non-blocking, which means it will always return
1208   * immediately. The {@code drainRITs} parameter only effects when will we complete the returned
1209   * {@link CompletableFuture}.
1210   * @param on Set to <code>true</code> to enable, <code>false</code> to disable.
1211   * @param drainRITs If <code>true</code>, it waits until current balance() call, if outstanding,
1212   *          to return.
1213   * @return Previous balancer value wrapped by a {@link CompletableFuture}.
1214   */
1215  CompletableFuture<Boolean> balancerSwitch(boolean on, boolean drainRITs);
1216
1217  /**
1218   * Invoke the balancer. Will run the balancer and if regions to move, it will go ahead and do the
1219   * reassignments. Can NOT run for various reasons. Check logs.
1220   * @return True if balancer ran, false otherwise. The return value will be wrapped by a
1221   *         {@link CompletableFuture}.
1222   */
1223  default CompletableFuture<Boolean> balance() {
1224    return balance(false);
1225  }
1226
1227  /**
1228   * Invoke the balancer. Will run the balancer and if regions to move, it will go ahead and do the
1229   * reassignments. If there is region in transition, force parameter of true would still run
1230   * balancer. Can *not* run for other reasons. Check logs.
1231   * @param forcible whether we should force balance even if there is region in transition.
1232   * @return True if balancer ran, false otherwise. The return value will be wrapped by a
1233   *         {@link CompletableFuture}.
1234   */
1235  CompletableFuture<Boolean> balance(boolean forcible);
1236
1237  /**
1238   * Query the current state of the balancer.
1239   * @return true if the balance switch is on, false otherwise. The return value will be wrapped by a
1240   *         {@link CompletableFuture}.
1241   */
1242  CompletableFuture<Boolean> isBalancerEnabled();
1243
1244  /**
1245   * Set region normalizer on/off.
1246   * @param on whether normalizer should be on or off
1247   * @return Previous normalizer value wrapped by a {@link CompletableFuture}
1248   */
1249  CompletableFuture<Boolean> normalizerSwitch(boolean on);
1250
1251  /**
1252   * Query the current state of the region normalizer
1253   * @return true if region normalizer is on, false otherwise. The return value will be wrapped by a
1254   *         {@link CompletableFuture}
1255   */
1256  CompletableFuture<Boolean> isNormalizerEnabled();
1257
1258  /**
1259   * Invoke region normalizer. Can NOT run for various reasons. Check logs.
1260   * @return true if region normalizer ran, false otherwise. The return value will be wrapped by a
1261   *         {@link CompletableFuture}
1262   */
1263  CompletableFuture<Boolean> normalize();
1264
1265  /**
1266   * Turn the cleaner chore on/off.
1267   * @param on
1268   * @return Previous cleaner state wrapped by a {@link CompletableFuture}
1269   */
1270  CompletableFuture<Boolean> cleanerChoreSwitch(boolean on);
1271
1272  /**
1273   * Query the current state of the cleaner chore.
1274   * @return true if cleaner chore is on, false otherwise. The return value will be wrapped by
1275   *         a {@link CompletableFuture}
1276   */
1277  CompletableFuture<Boolean> isCleanerChoreEnabled();
1278
1279  /**
1280   * Ask for cleaner chore to run.
1281   * @return true if cleaner chore ran, false otherwise. The return value will be wrapped by a
1282   *         {@link CompletableFuture}
1283   */
1284  CompletableFuture<Boolean> runCleanerChore();
1285
1286  /**
1287   * Turn the catalog janitor on/off.
1288   * @param on
1289   * @return the previous state wrapped by a {@link CompletableFuture}
1290   */
1291  CompletableFuture<Boolean> catalogJanitorSwitch(boolean on);
1292
1293  /**
1294   * Query on the catalog janitor state.
1295   * @return true if the catalog janitor is on, false otherwise. The return value will be
1296   *         wrapped by a {@link CompletableFuture}
1297   */
1298  CompletableFuture<Boolean> isCatalogJanitorEnabled();
1299
1300  /**
1301   * Ask for a scan of the catalog table.
1302   * @return the number of entries cleaned. The return value will be wrapped by a
1303   *         {@link CompletableFuture}
1304   */
1305  CompletableFuture<Integer> runCatalogJanitor();
1306
1307  /**
1308   * Execute the given coprocessor call on the master.
1309   * <p>
1310   * The {@code stubMaker} is just a delegation to the {@code newStub} call. Usually it is only a
1311   * one line lambda expression, like:
1312   *
1313   * <pre>
1314   * <code>
1315   * channel -> xxxService.newStub(channel)
1316   * </code>
1317   * </pre>
1318   * @param stubMaker a delegation to the actual {@code newStub} call.
1319   * @param callable a delegation to the actual protobuf rpc call. See the comment of
1320   *          {@link ServiceCaller} for more details.
1321   * @param <S> the type of the asynchronous stub
1322   * @param <R> the type of the return value
1323   * @return the return value of the protobuf rpc call, wrapped by a {@link CompletableFuture}.
1324   * @see ServiceCaller
1325   */
1326  <S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker,
1327      ServiceCaller<S, R> callable);
1328
1329  /**
1330   * Execute the given coprocessor call on the given region server.
1331   * <p>
1332   * The {@code stubMaker} is just a delegation to the {@code newStub} call. Usually it is only a
1333   * one line lambda expression, like:
1334   *
1335   * <pre>
1336   * <code>
1337   * channel -> xxxService.newStub(channel)
1338   * </code>
1339   * </pre>
1340   * @param stubMaker a delegation to the actual {@code newStub} call.
1341   * @param callable a delegation to the actual protobuf rpc call. See the comment of
1342   *          {@link ServiceCaller} for more details.
1343   * @param serverName the given region server
1344   * @param <S> the type of the asynchronous stub
1345   * @param <R> the type of the return value
1346   * @return the return value of the protobuf rpc call, wrapped by a {@link CompletableFuture}.
1347   * @see ServiceCaller
1348   */
1349  <S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker,
1350    ServiceCaller<S, R> callable, ServerName serverName);
1351
1352  /**
1353   * List all the dead region servers.
1354   */
1355  default CompletableFuture<List<ServerName>> listDeadServers() {
1356    return this.getClusterMetrics(EnumSet.of(Option.DEAD_SERVERS))
1357        .thenApply(ClusterMetrics::getDeadServerNames);
1358  }
1359
1360  /**
1361   * Clear dead region servers from master.
1362   * @param servers list of dead region servers.
1363   * @return - returns a list of servers that not cleared wrapped by a {@link CompletableFuture}.
1364   */
1365  CompletableFuture<List<ServerName>> clearDeadServers(final List<ServerName> servers);
1366
1367  /**
1368   * Clear all the blocks corresponding to this table from BlockCache. For expert-admins. Calling
1369   * this API will drop all the cached blocks specific to a table from BlockCache. This can
1370   * significantly impact the query performance as the subsequent queries will have to retrieve the
1371   * blocks from underlying filesystem.
1372   * @param tableName table to clear block cache
1373   * @return CacheEvictionStats related to the eviction wrapped by a {@link CompletableFuture}.
1374   */
1375  CompletableFuture<CacheEvictionStats> clearBlockCache(final TableName tableName);
1376
1377  /**
1378   * Create a new table by cloning the existent table schema.
1379   *
1380   * @param tableName name of the table to be cloned
1381   * @param newTableName name of the new table where the table will be created
1382   * @param preserveSplits True if the splits should be preserved
1383   */
1384  CompletableFuture<Void>  cloneTableSchema(final TableName tableName,
1385      final TableName newTableName, final boolean preserveSplits);
1386
1387  /**
1388   * Turn the compaction on or off. Disabling compactions will also interrupt any currently ongoing
1389   * compactions. This state is ephemeral. The setting will be lost on restart. Compaction
1390   * can also be enabled/disabled by modifying configuration hbase.regionserver.compaction.enabled
1391   * in hbase-site.xml.
1392   *
1393   * @param switchState     Set to <code>true</code> to enable, <code>false</code> to disable.
1394   * @param serverNamesList list of region servers.
1395   * @return Previous compaction states for region servers
1396   */
1397  CompletableFuture<Map<ServerName, Boolean>> compactionSwitch(boolean switchState,
1398      List<String> serverNamesList);
1399
1400  /**
1401   * Switch the rpc throttle enabled state.
1402   * @param enable Set to <code>true</code> to enable, <code>false</code> to disable.
1403   * @return Previous rpc throttle enabled value
1404   */
1405  CompletableFuture<Boolean> switchRpcThrottle(boolean enable);
1406
1407  /**
1408   * Get if the rpc throttle is enabled.
1409   * @return True if rpc throttle is enabled
1410   */
1411  CompletableFuture<Boolean> isRpcThrottleEnabled();
1412
1413  /**
1414   * Switch the exceed throttle quota. If enabled, user/table/namespace throttle quota
1415   * can be exceeded if region server has availble quota.
1416   * @param enable Set to <code>true</code> to enable, <code>false</code> to disable.
1417   * @return Previous exceed throttle enabled value
1418   */
1419  CompletableFuture<Boolean> exceedThrottleQuotaSwitch(boolean enable);
1420
1421  /**
1422   * Fetches the table sizes on the filesystem as tracked by the HBase Master.
1423   */
1424  CompletableFuture<Map<TableName, Long>> getSpaceQuotaTableSizes();
1425
1426  /**
1427   * Fetches the observed {@link SpaceQuotaSnapshotView}s observed by a RegionServer.
1428   */
1429  CompletableFuture<? extends Map<TableName, ? extends SpaceQuotaSnapshotView>>
1430      getRegionServerSpaceQuotaSnapshots(ServerName serverName);
1431
1432  /**
1433   * Returns the Master's view of a quota on the given {@code namespace} or null if the Master has
1434   * no quota information on that namespace.
1435   */
1436  CompletableFuture<? extends SpaceQuotaSnapshotView>
1437      getCurrentSpaceQuotaSnapshot(String namespace);
1438
1439  /**
1440   * Returns the Master's view of a quota on the given {@code tableName} or null if the Master has
1441   * no quota information on that table.
1442   */
1443  CompletableFuture<? extends SpaceQuotaSnapshotView> getCurrentSpaceQuotaSnapshot(
1444      TableName tableName);
1445
1446  /**
1447   * Grants user specific permissions
1448   * @param userPermission user name and the specific permission
1449   * @param mergeExistingPermissions If set to false, later granted permissions will override
1450   *          previous granted permissions. otherwise, it'll merge with previous granted
1451   *          permissions.
1452   */
1453  CompletableFuture<Void> grant(UserPermission userPermission, boolean mergeExistingPermissions);
1454
1455  /**
1456   * Revokes user specific permissions
1457   * @param userPermission user name and the specific permission
1458   */
1459  CompletableFuture<Void> revoke(UserPermission userPermission);
1460
1461  /**
1462   * Get the global/namespace/table permissions for user
1463   * @param getUserPermissionsRequest A request contains which user, global, namespace or table
1464   *          permissions needed
1465   * @return The user and permission list
1466   */
1467  CompletableFuture<List<UserPermission>>
1468      getUserPermissions(GetUserPermissionsRequest getUserPermissionsRequest);
1469
1470  /**
1471   * Check if the user has specific permissions
1472   * @param userName the user name
1473   * @param permissions the specific permission list
1474   * @return True if user has the specific permissions
1475   */
1476  CompletableFuture<List<Boolean>> hasUserPermissions(String userName,
1477      List<Permission> permissions);
1478
1479  /**
1480   * Check if call user has specific permissions
1481   * @param permissions the specific permission list
1482   * @return True if user has the specific permissions
1483   */
1484  default CompletableFuture<List<Boolean>> hasUserPermissions(List<Permission> permissions) {
1485    return hasUserPermissions(null, permissions);
1486  }
1487}