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