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