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