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