HBASE-26474 Implement connection-level attributes (addendum)
[hbase.git] / hbase-client / src / main / java / org / apache / hadoop / hbase / client / AsyncAdmin.java
blobba54bb73f7b81388e7b4416b0789d4e784dfa582
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.client;
20 import static org.apache.hadoop.hbase.util.FutureUtils.addListener;
22 import java.io.IOException;
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.EnumSet;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Optional;
30 import java.util.Set;
31 import java.util.concurrent.CompletableFuture;
32 import java.util.function.Function;
33 import java.util.regex.Pattern;
34 import java.util.stream.Collectors;
35 import org.apache.hadoop.hbase.CacheEvictionStats;
36 import org.apache.hadoop.hbase.ClusterMetrics;
37 import org.apache.hadoop.hbase.ClusterMetrics.Option;
38 import org.apache.hadoop.hbase.NamespaceDescriptor;
39 import org.apache.hadoop.hbase.RegionMetrics;
40 import org.apache.hadoop.hbase.ServerName;
41 import org.apache.hadoop.hbase.TableName;
42 import org.apache.hadoop.hbase.client.replication.TableCFs;
43 import org.apache.hadoop.hbase.client.security.SecurityCapability;
44 import org.apache.hadoop.hbase.net.Address;
45 import org.apache.hadoop.hbase.quotas.QuotaFilter;
46 import org.apache.hadoop.hbase.quotas.QuotaSettings;
47 import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshotView;
48 import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
49 import org.apache.hadoop.hbase.replication.ReplicationPeerDescription;
50 import org.apache.hadoop.hbase.replication.SyncReplicationState;
51 import org.apache.hadoop.hbase.rsgroup.RSGroupInfo;
52 import org.apache.hadoop.hbase.security.access.GetUserPermissionsRequest;
53 import org.apache.hadoop.hbase.security.access.Permission;
54 import org.apache.hadoop.hbase.security.access.UserPermission;
55 import org.apache.hadoop.hbase.util.Pair;
56 import org.apache.yetus.audience.InterfaceAudience;
58 import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList;
59 import org.apache.hbase.thirdparty.com.google.protobuf.RpcChannel;
61 /**
62 * The asynchronous administrative API for HBase.
63 * @since 2.0.0
65 @InterfaceAudience.Public
66 public interface AsyncAdmin {
68 /**
69 * @param tableName Table to check.
70 * @return True if table exists already. The return value will be wrapped by a
71 * {@link CompletableFuture}.
73 CompletableFuture<Boolean> tableExists(TableName tableName);
75 /**
76 * List all the userspace tables.
77 * @return - returns a list of TableDescriptors wrapped by a {@link CompletableFuture}.
79 default CompletableFuture<List<TableDescriptor>> listTableDescriptors() {
80 return listTableDescriptors(false);
83 /**
84 * List all the tables.
85 * @param includeSysTables False to match only against userspace tables
86 * @return - returns a list of TableDescriptors wrapped by a {@link CompletableFuture}.
88 CompletableFuture<List<TableDescriptor>> listTableDescriptors(boolean includeSysTables);
90 /**
91 * List all the tables matching the given pattern.
92 * @param pattern The compiled regular expression to match against
93 * @param includeSysTables False to match only against userspace tables
94 * @return - returns a list of TableDescriptors wrapped by a {@link CompletableFuture}.
96 CompletableFuture<List<TableDescriptor>> listTableDescriptors(Pattern pattern,
97 boolean includeSysTables);
99 /**
100 * List specific tables including system tables.
101 * @param tableNames the table list to match against
102 * @return - returns a list of TableDescriptors wrapped by a {@link CompletableFuture}.
104 CompletableFuture<List<TableDescriptor>> listTableDescriptors(List<TableName> tableNames);
107 * Get list of table descriptors by namespace.
108 * @param name namespace name
109 * @return returns a list of TableDescriptors wrapped by a {@link CompletableFuture}.
111 CompletableFuture<List<TableDescriptor>> listTableDescriptorsByNamespace(String name);
114 * List all of the names of userspace tables.
115 * @return a list of table names wrapped by a {@link CompletableFuture}.
116 * @see #listTableNames(Pattern, boolean)
118 default CompletableFuture<List<TableName>> listTableNames() {
119 return listTableNames(false);
123 * List all of the names of tables.
124 * @param includeSysTables False to match only against userspace tables
125 * @return a list of table names wrapped by a {@link CompletableFuture}.
127 CompletableFuture<List<TableName>> listTableNames(boolean includeSysTables);
130 * List all of the names of userspace tables.
131 * @param pattern The regular expression to match against
132 * @param includeSysTables False to match only against userspace tables
133 * @return a list of table names wrapped by a {@link CompletableFuture}.
135 CompletableFuture<List<TableName>> listTableNames(Pattern pattern, boolean includeSysTables);
138 * Get list of table names by namespace.
139 * @param name namespace name
140 * @return The list of table names in the namespace wrapped by a {@link CompletableFuture}.
142 CompletableFuture<List<TableName>> listTableNamesByNamespace(String name);
145 * Method for getting the tableDescriptor
146 * @param tableName as a {@link TableName}
147 * @return the read-only tableDescriptor wrapped by a {@link CompletableFuture}.
149 CompletableFuture<TableDescriptor> getDescriptor(TableName tableName);
152 * Creates a new table.
153 * @param desc table descriptor for table
155 CompletableFuture<Void> createTable(TableDescriptor desc);
158 * Creates a new table with the specified number of regions. The start key specified will become
159 * the end key of the first region of the table, and the end key specified will become the start
160 * key of the last region of the table (the first region has a null start key and the last region
161 * has a null end key). BigInteger math will be used to divide the key range specified into enough
162 * segments to make the required number of total regions.
163 * @param desc table descriptor for table
164 * @param startKey beginning of key range
165 * @param endKey end of key range
166 * @param numRegions the total number of regions to create
168 CompletableFuture<Void> createTable(TableDescriptor desc, byte[] startKey, byte[] endKey,
169 int numRegions);
172 * Creates a new table with an initial set of empty regions defined by the specified split keys.
173 * The total number of regions created will be the number of split keys plus one.
174 * Note : Avoid passing empty split key.
175 * @param desc table descriptor for table
176 * @param splitKeys array of split keys for the initial regions of the table
178 CompletableFuture<Void> createTable(TableDescriptor desc, byte[][] splitKeys);
181 * Modify an existing table, more IRB friendly version.
182 * @param desc modified description of the table
184 CompletableFuture<Void> modifyTable(TableDescriptor desc);
187 * Deletes a table.
188 * @param tableName name of table to delete
190 CompletableFuture<Void> deleteTable(TableName tableName);
193 * Truncate a table.
194 * @param tableName name of table to truncate
195 * @param preserveSplits True if the splits should be preserved
197 CompletableFuture<Void> truncateTable(TableName tableName, boolean preserveSplits);
200 * Enable a table. The table has to be in disabled state for it to be enabled.
201 * @param tableName name of the table
203 CompletableFuture<Void> enableTable(TableName tableName);
206 * Disable a table. The table has to be in enabled state for it to be disabled.
207 * @param tableName
209 CompletableFuture<Void> disableTable(TableName tableName);
212 * @param tableName name of table to check
213 * @return true if table is on-line. The return value will be wrapped by a
214 * {@link CompletableFuture}.
216 CompletableFuture<Boolean> isTableEnabled(TableName tableName);
219 * @param tableName name of table to check
220 * @return true if table is off-line. The return value will be wrapped by a
221 * {@link CompletableFuture}.
223 CompletableFuture<Boolean> isTableDisabled(TableName tableName);
226 * @param tableName name of table to check
227 * @return true if all regions of the table are available. The return value will be wrapped by a
228 * {@link CompletableFuture}.
230 CompletableFuture<Boolean> isTableAvailable(TableName tableName);
233 * Add a column family to an existing table.
234 * @param tableName name of the table to add column family to
235 * @param columnFamily column family descriptor of column family to be added
237 CompletableFuture<Void> addColumnFamily(TableName tableName,
238 ColumnFamilyDescriptor columnFamily);
241 * Delete a column family from a table.
242 * @param tableName name of table
243 * @param columnFamily name of column family to be deleted
245 CompletableFuture<Void> deleteColumnFamily(TableName tableName, byte[] columnFamily);
248 * Modify an existing column family on a table.
249 * @param tableName name of table
250 * @param columnFamily new column family descriptor to use
252 CompletableFuture<Void> modifyColumnFamily(TableName tableName,
253 ColumnFamilyDescriptor columnFamily);
256 * Create a new namespace.
257 * @param descriptor descriptor which describes the new namespace
259 CompletableFuture<Void> createNamespace(NamespaceDescriptor descriptor);
262 * Modify an existing namespace.
263 * @param descriptor descriptor which describes the new namespace
265 CompletableFuture<Void> modifyNamespace(NamespaceDescriptor descriptor);
268 * Delete an existing namespace. Only empty namespaces (no tables) can be removed.
269 * @param name namespace name
271 CompletableFuture<Void> deleteNamespace(String name);
274 * Get a namespace descriptor by name
275 * @param name name of namespace descriptor
276 * @return A descriptor wrapped by a {@link CompletableFuture}.
278 CompletableFuture<NamespaceDescriptor> getNamespaceDescriptor(String name);
281 * List available namespaces
282 * @return List of namespaces wrapped by a {@link CompletableFuture}.
284 CompletableFuture<List<String>> listNamespaces();
287 * List available namespace descriptors
288 * @return List of descriptors wrapped by a {@link CompletableFuture}.
290 CompletableFuture<List<NamespaceDescriptor>> listNamespaceDescriptors();
293 * Get all the online regions on a region server.
295 CompletableFuture<List<RegionInfo>> getRegions(ServerName serverName);
298 * Get the regions of a given table.
300 CompletableFuture<List<RegionInfo>> getRegions(TableName tableName);
303 * Flush a table.
304 * @param tableName table to flush
306 CompletableFuture<Void> flush(TableName tableName);
309 * Flush the specified column family stores on all regions of the passed table.
310 * This runs as a synchronous operation.
311 * @param tableName table to flush
312 * @param columnFamily column family within a table
314 CompletableFuture<Void> flush(TableName tableName, byte[] columnFamily);
317 * Flush an individual region.
318 * @param regionName region to flush
320 CompletableFuture<Void> flushRegion(byte[] regionName);
323 * Flush a column family within a region.
324 * @param regionName region to flush
325 * @param columnFamily column family within a region. If not present, flush the region's all
326 * column families.
328 CompletableFuture<Void> flushRegion(byte[] regionName, byte[] columnFamily);
331 * Flush all region on the region server.
332 * @param serverName server to flush
334 CompletableFuture<Void> flushRegionServer(ServerName serverName);
337 * Compact a table. When the returned CompletableFuture is done, it only means the compact request
338 * was sent to HBase and may need some time to finish the compact operation.
339 * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found.
340 * @param tableName table to compact
342 default CompletableFuture<Void> compact(TableName tableName) {
343 return compact(tableName, CompactType.NORMAL);
347 * Compact a column family within a table. When the returned CompletableFuture is done, it only
348 * means the compact request was sent to HBase and may need some time to finish the compact
349 * operation.
350 * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found.
351 * @param tableName table to compact
352 * @param columnFamily column family within a table. If not present, compact the table's all
353 * column families.
355 default CompletableFuture<Void> compact(TableName tableName, byte[] columnFamily) {
356 return compact(tableName, columnFamily, CompactType.NORMAL);
360 * Compact a table. When the returned CompletableFuture is done, it only means the compact request
361 * was sent to HBase and may need some time to finish the compact 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 compactType {@link org.apache.hadoop.hbase.client.CompactType}
367 CompletableFuture<Void> compact(TableName tableName, CompactType compactType);
370 * Compact a column family within a table. When the returned CompletableFuture is done, it only
371 * means the compact request was sent to HBase and may need some time to finish the compact
372 * operation.
373 * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found for
374 * normal compaction type.
375 * @param tableName table to compact
376 * @param columnFamily column family within a table
377 * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
379 CompletableFuture<Void> compact(TableName tableName, byte[] columnFamily,
380 CompactType compactType);
383 * Compact an individual region. When the returned CompletableFuture is done, it only means the
384 * compact request was sent to HBase and may need some time to finish the compact operation.
385 * @param regionName region to compact
387 CompletableFuture<Void> compactRegion(byte[] regionName);
390 * Compact a column family within a region. When the returned CompletableFuture is done, it only
391 * means the compact request was sent to HBase and may need some time to finish the compact
392 * operation.
393 * @param regionName region to compact
394 * @param columnFamily column family within a region. If not present, compact the region's all
395 * column families.
397 CompletableFuture<Void> compactRegion(byte[] regionName, byte[] columnFamily);
400 * Major compact a table. When the returned CompletableFuture is done, it only means the compact
401 * request was sent to HBase and may need some time to finish the compact operation.
402 * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found.
403 * @param tableName table to major compact
405 default CompletableFuture<Void> majorCompact(TableName tableName) {
406 return majorCompact(tableName, CompactType.NORMAL);
410 * Major compact a column family within a table. When the returned CompletableFuture is done, it
411 * only means the compact request was sent to HBase and may need some time to finish the compact
412 * operation.
413 * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found for
414 * normal compaction. type.
415 * @param tableName table to major compact
416 * @param columnFamily column family within a table. If not present, major compact the table's all
417 * column families.
419 default CompletableFuture<Void> majorCompact(TableName tableName, byte[] columnFamily) {
420 return majorCompact(tableName, columnFamily, CompactType.NORMAL);
424 * Major compact a table. When the returned CompletableFuture is done, it only means the compact
425 * request was sent to HBase and may need some time to finish the compact operation.
426 * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found for
427 * normal compaction type.
428 * @param tableName table to major compact
429 * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
431 CompletableFuture<Void> majorCompact(TableName tableName, CompactType compactType);
434 * Major compact a column family within a table. When the returned CompletableFuture is done, it
435 * only means the compact request was sent to HBase and may need some time to finish the compact
436 * operation.
437 * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found.
438 * @param tableName table to major compact
439 * @param columnFamily column family within a table. If not present, major compact the table's all
440 * column families.
441 * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
443 CompletableFuture<Void> majorCompact(TableName tableName, byte[] columnFamily,
444 CompactType compactType);
447 * Major compact a region. When the returned CompletableFuture is done, it only means the compact
448 * request was sent to HBase and may need some time to finish the compact operation.
449 * @param regionName region to major compact
451 CompletableFuture<Void> majorCompactRegion(byte[] regionName);
454 * Major compact a column family within region. When the returned CompletableFuture is done, it
455 * only means the compact request was sent to HBase and may need some time to finish the compact
456 * operation.
457 * @param regionName region to major compact
458 * @param columnFamily column family within a region. If not present, major compact the region's
459 * all column families.
461 CompletableFuture<Void> majorCompactRegion(byte[] regionName, byte[] columnFamily);
464 * Compact all regions on the region server.
465 * @param serverName the region server name
467 CompletableFuture<Void> compactRegionServer(ServerName serverName);
470 * Compact all regions on the region server.
471 * @param serverName the region server name
473 CompletableFuture<Void> majorCompactRegionServer(ServerName serverName);
476 * Turn the Merge switch on or off.
477 * @param enabled enabled or not
478 * @return Previous switch value wrapped by a {@link CompletableFuture}
480 default CompletableFuture<Boolean> mergeSwitch(boolean enabled) {
481 return mergeSwitch(enabled, false);
485 * Turn the Merge switch on or off.
486 * <p/>
487 * Notice that, the method itself is always non-blocking, which means it will always return
488 * immediately. The {@code drainMerges} parameter only effects when will we complete the returned
489 * {@link CompletableFuture}.
490 * @param enabled enabled or not
491 * @param drainMerges If <code>true</code>, it waits until current merge() call, if outstanding,
492 * to return.
493 * @return Previous switch value wrapped by a {@link CompletableFuture}
495 CompletableFuture<Boolean> mergeSwitch(boolean enabled, boolean drainMerges);
498 * Query the current state of the Merge switch.
499 * @return true if the switch is on, false otherwise. The return value will be wrapped by a
500 * {@link CompletableFuture}
502 CompletableFuture<Boolean> isMergeEnabled();
505 * Turn the Split switch on or off.
506 * @param enabled enabled or not
507 * @return Previous switch value wrapped by a {@link CompletableFuture}
509 default CompletableFuture<Boolean> splitSwitch(boolean enabled) {
510 return splitSwitch(enabled, false);
514 * Turn the Split switch on or off.
515 * <p/>
516 * Notice that, the method itself is always non-blocking, which means it will always return
517 * immediately. The {@code drainSplits} parameter only effects when will we complete the returned
518 * {@link CompletableFuture}.
519 * @param enabled enabled or not
520 * @param drainSplits If <code>true</code>, it waits until current split() call, if outstanding,
521 * to return.
522 * @return Previous switch value wrapped by a {@link CompletableFuture}
524 CompletableFuture<Boolean> splitSwitch(boolean enabled, boolean drainSplits);
527 * Query the current state of the Split switch.
528 * @return true if the switch is on, false otherwise. The return value will be wrapped by a
529 * {@link CompletableFuture}
531 CompletableFuture<Boolean> isSplitEnabled();
534 * Merge two regions.
535 * @param nameOfRegionA encoded or full name of region a
536 * @param nameOfRegionB encoded or full name of region b
537 * @param forcible true if do a compulsory merge, otherwise we will only merge two adjacent
538 * regions
539 * @deprecated since 2.3.0 and will be removed in 4.0.0.Use {@link #mergeRegions(List, boolean)}
540 * instead.
542 @Deprecated
543 default CompletableFuture<Void> mergeRegions(byte[] nameOfRegionA, byte[] nameOfRegionB,
544 boolean forcible) {
545 return mergeRegions(Arrays.asList(nameOfRegionA, nameOfRegionB), forcible);
549 * Merge multiple regions (>=2).
550 * @param nameOfRegionsToMerge encoded or full name of daughter regions
551 * @param forcible true if do a compulsory merge, otherwise we will only merge two adjacent
552 * regions
554 CompletableFuture<Void> mergeRegions(List<byte[]> nameOfRegionsToMerge, boolean forcible);
557 * Split a table. The method will execute split action for each region in table.
558 * @param tableName table to split
560 CompletableFuture<Void> split(TableName tableName);
563 * Split an individual region.
564 * @param regionName region to split
566 CompletableFuture<Void> splitRegion(byte[] regionName);
569 * Split a table.
570 * @param tableName table to split
571 * @param splitPoint the explicit position to split on
573 CompletableFuture<Void> split(TableName tableName, byte[] splitPoint);
576 * Split an individual region.
577 * @param regionName region to split
578 * @param splitPoint the explicit position to split on. If not present, it will decide by region
579 * server.
581 CompletableFuture<Void> splitRegion(byte[] regionName, byte[] splitPoint);
584 * @param regionName Encoded or full name of region to assign.
586 CompletableFuture<Void> assign(byte[] regionName);
589 * @param regionName Encoded or full name of region to unassign.
591 CompletableFuture<Void> unassign(byte[] regionName);
594 * Unassign a region from current hosting regionserver. Region will then be assigned to a
595 * regionserver chosen at random. Region could be reassigned back to the same server. Use
596 * {@link #move(byte[], ServerName)} if you want to control the region movement.
597 * @param regionName Encoded or full name of region to unassign. Will clear any existing
598 * RegionPlan if one found.
599 * @param forcible If true, force unassign (Will remove region from regions-in-transition too if
600 * present. If results in double assignment use hbck -fix to resolve. To be used by
601 * experts).
602 * @deprecated since 2.4.0 and will be removed in 4.0.0. Use {@link #unassign(byte[])}
603 * instead.
604 * @see <a href="https://issues.apache.org/jira/browse/HBASE-24875">HBASE-24875</a>
606 @Deprecated
607 default CompletableFuture<Void> unassign(byte[] regionName, boolean forcible) {
608 return unassign(regionName);
612 * Offline specified region from master's in-memory state. It will not attempt to reassign the
613 * region as in unassign. This API can be used when a region not served by any region server and
614 * still online as per Master's in memory state. If this API is incorrectly used on active region
615 * then master will loose track of that region. This is a special method that should be used by
616 * experts or hbck.
617 * @param regionName Encoded or full name of region to offline
619 CompletableFuture<Void> offline(byte[] regionName);
622 * Move the region <code>r</code> to a random server.
623 * @param regionName Encoded or full name of region to move.
625 CompletableFuture<Void> move(byte[] regionName);
628 * Move the region <code>r</code> to <code>dest</code>.
629 * @param regionName Encoded or full name of region to move.
630 * @param destServerName The servername of the destination regionserver. If not present, we'll
631 * assign to a random server. A server name is made of host, port and startcode. Here is
632 * an example: <code> host187.example.com,60020,1289493121758</code>
634 CompletableFuture<Void> move(byte[] regionName, ServerName destServerName);
637 * Apply the new quota settings.
638 * @param quota the quota settings
640 CompletableFuture<Void> setQuota(QuotaSettings quota);
643 * List the quotas based on the filter.
644 * @param filter the quota settings filter
645 * @return the QuotaSetting list, which wrapped by a CompletableFuture.
647 CompletableFuture<List<QuotaSettings>> getQuota(QuotaFilter filter);
650 * Add a new replication peer for replicating data to slave cluster
651 * @param peerId a short name that identifies the peer
652 * @param peerConfig configuration for the replication slave cluster
654 default CompletableFuture<Void> addReplicationPeer(String peerId,
655 ReplicationPeerConfig peerConfig) {
656 return addReplicationPeer(peerId, peerConfig, true);
660 * Add a new replication peer for replicating data to slave cluster
661 * @param peerId a short name that identifies the peer
662 * @param peerConfig configuration for the replication slave cluster
663 * @param enabled peer state, true if ENABLED and false if DISABLED
665 CompletableFuture<Void> addReplicationPeer(String peerId,
666 ReplicationPeerConfig peerConfig, boolean enabled);
669 * Remove a peer and stop the replication
670 * @param peerId a short name that identifies the peer
672 CompletableFuture<Void> removeReplicationPeer(String peerId);
675 * Restart the replication stream to the specified peer
676 * @param peerId a short name that identifies the peer
678 CompletableFuture<Void> enableReplicationPeer(String peerId);
681 * Stop the replication stream to the specified peer
682 * @param peerId a short name that identifies the peer
684 CompletableFuture<Void> disableReplicationPeer(String peerId);
687 * Returns the configured ReplicationPeerConfig for the specified peer
688 * @param peerId a short name that identifies the peer
689 * @return ReplicationPeerConfig for the peer wrapped by a {@link CompletableFuture}.
691 CompletableFuture<ReplicationPeerConfig> getReplicationPeerConfig(String peerId);
694 * Update the peerConfig for the specified peer
695 * @param peerId a short name that identifies the peer
696 * @param peerConfig new config for the peer
698 CompletableFuture<Void> updateReplicationPeerConfig(String peerId,
699 ReplicationPeerConfig peerConfig);
702 * Transit current cluster to a new state in a synchronous replication peer.
703 * @param peerId a short name that identifies the peer
704 * @param state a new state of current cluster
706 CompletableFuture<Void> transitReplicationPeerSyncReplicationState(String peerId,
707 SyncReplicationState state);
710 * Get the current cluster state in a synchronous replication peer.
711 * @param peerId a short name that identifies the peer
712 * @return the current cluster state wrapped by a {@link CompletableFuture}.
714 default CompletableFuture<SyncReplicationState> getReplicationPeerSyncReplicationState(
715 String peerId) {
716 CompletableFuture<SyncReplicationState> future = new CompletableFuture<>();
717 addListener(listReplicationPeers(Pattern.compile(peerId)), (peers, error) -> {
718 if (error != null) {
719 future.completeExceptionally(error);
720 } else if (peers.isEmpty() || !peers.get(0).getPeerId().equals(peerId)) {
721 future
722 .completeExceptionally(new IOException("Replication peer " + peerId + " does not exist"));
723 } else {
724 future.complete(peers.get(0).getSyncReplicationState());
727 return future;
731 * Append the replicable table-cf config of the specified peer
732 * @param peerId a short that identifies the cluster
733 * @param tableCfs A map from tableName to column family names
735 CompletableFuture<Void> appendReplicationPeerTableCFs(String peerId,
736 Map<TableName, List<String>> tableCfs);
739 * Remove some table-cfs from config of the specified peer
740 * @param peerId a short name that identifies the cluster
741 * @param tableCfs A map from tableName to column family names
743 CompletableFuture<Void> removeReplicationPeerTableCFs(String peerId,
744 Map<TableName, List<String>> tableCfs);
747 * Return a list of replication peers.
748 * @return a list of replication peers description. The return value will be wrapped by a
749 * {@link CompletableFuture}.
751 CompletableFuture<List<ReplicationPeerDescription>> listReplicationPeers();
754 * Return a list of replication peers.
755 * @param pattern The compiled regular expression to match peer id
756 * @return a list of replication peers description. The return value will be wrapped by a
757 * {@link CompletableFuture}.
759 CompletableFuture<List<ReplicationPeerDescription>> listReplicationPeers(Pattern pattern);
762 * Find all table and column families that are replicated from this cluster
763 * @return the replicated table-cfs list of this cluster. The return value will be wrapped by a
764 * {@link CompletableFuture}.
766 CompletableFuture<List<TableCFs>> listReplicatedTableCFs();
769 * Enable a table's replication switch.
770 * @param tableName name of the table
772 CompletableFuture<Void> enableTableReplication(TableName tableName);
775 * Disable a table's replication switch.
776 * @param tableName name of the table
778 CompletableFuture<Void> disableTableReplication(TableName tableName);
781 * Take a snapshot for the given table. If the table is enabled, a FLUSH-type snapshot will be
782 * taken. If the table is disabled, an offline snapshot is taken. Snapshots are taken
783 * sequentially even when requested concurrently, across all tables. Snapshots are considered
784 * unique based on <b>the name of the snapshot</b>. Attempts to take a snapshot with the same
785 * name (even a different type or with different parameters) will fail with a
786 * {@link org.apache.hadoop.hbase.snapshot.SnapshotCreationException} indicating the duplicate
787 * naming. Snapshot names follow the same naming constraints as tables in HBase. See
788 * {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}.
789 * @param snapshotName name of the snapshot to be created
790 * @param tableName name of the table for which snapshot is created
792 default CompletableFuture<Void> snapshot(String snapshotName, TableName tableName) {
793 return snapshot(snapshotName, tableName, SnapshotType.FLUSH);
797 * Create typed snapshot of the table. Snapshots are considered unique based on <b>the name of the
798 * snapshot</b>. Snapshots are taken sequentially even when requested concurrently, across all
799 * tables. Attempts to take a snapshot with the same name (even a different type or with
800 * different parameters) will fail with a
801 * {@link org.apache.hadoop.hbase.snapshot.SnapshotCreationException} indicating the duplicate
802 * naming. Snapshot names follow the same naming constraints as tables in HBase. See
803 * {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}.
804 * @param snapshotName name to give the snapshot on the filesystem. Must be unique from all other
805 * snapshots stored on the cluster
806 * @param tableName name of the table to snapshot
807 * @param type type of snapshot to take
809 default CompletableFuture<Void> snapshot(String snapshotName, TableName tableName,
810 SnapshotType type) {
811 return snapshot(new SnapshotDescription(snapshotName, tableName, type));
815 * Take a snapshot and wait for the server to complete that snapshot asynchronously. Snapshots
816 * are taken sequentially even when requested concurrently, across all tables. Snapshots are
817 * considered unique based on <b>the name of the snapshot</b>.
818 * Attempts to take a snapshot with the same name (even a different type or with different
819 * parameters) will fail with a {@link org.apache.hadoop.hbase.snapshot.SnapshotCreationException}
820 * indicating the duplicate naming. Snapshot names follow the same naming constraints as tables in
821 * HBase. See {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}.
822 * You should probably use {@link #snapshot(String, org.apache.hadoop.hbase.TableName)} unless you
823 * are sure about the type of snapshot that you want to take.
824 * @param snapshot snapshot to take
826 CompletableFuture<Void> snapshot(SnapshotDescription snapshot);
829 * Check the current state of the passed snapshot. There are three possible states:
830 * <ol>
831 * <li>running - returns <tt>false</tt></li>
832 * <li>finished - returns <tt>true</tt></li>
833 * <li>finished with error - throws the exception that caused the snapshot to fail</li>
834 * </ol>
835 * The cluster only knows about the most recent snapshot. Therefore, if another snapshot has been
836 * run/started since the snapshot you are checking, you will receive an
837 * {@link org.apache.hadoop.hbase.snapshot.UnknownSnapshotException}.
838 * @param snapshot description of the snapshot to check
839 * @return <tt>true</tt> if the snapshot is completed, <tt>false</tt> if the snapshot is still
840 * running
842 CompletableFuture<Boolean> isSnapshotFinished(SnapshotDescription snapshot);
845 * Restore the specified snapshot on the original table. (The table must be disabled) If the
846 * "hbase.snapshot.restore.take.failsafe.snapshot" configuration property is set to true, a
847 * snapshot of the current table is taken before executing the restore operation. In case of
848 * restore failure, the failsafe snapshot will be restored. If the restore completes without
849 * problem the failsafe snapshot is deleted.
850 * @param snapshotName name of the snapshot to restore
852 CompletableFuture<Void> restoreSnapshot(String snapshotName);
855 * Restore the specified snapshot on the original table. (The table must be disabled) If
856 * 'takeFailSafeSnapshot' is set to true, a snapshot of the current table is taken before
857 * executing the restore operation. In case of restore failure, the failsafe snapshot will be
858 * restored. If the restore completes without problem the failsafe snapshot is deleted. The
859 * failsafe snapshot name is configurable by using the property
860 * "hbase.snapshot.restore.failsafe.name".
861 * @param snapshotName name of the snapshot to restore
862 * @param takeFailSafeSnapshot true if the failsafe snapshot should be taken
864 default CompletableFuture<Void> restoreSnapshot(String snapshotName,
865 boolean takeFailSafeSnapshot) {
866 return restoreSnapshot(snapshotName, takeFailSafeSnapshot, false);
870 * Restore the specified snapshot on the original table. (The table must be disabled) If
871 * 'takeFailSafeSnapshot' is set to true, a snapshot of the current table is taken before
872 * executing the restore operation. In case of restore failure, the failsafe snapshot will be
873 * restored. If the restore completes without problem the failsafe snapshot is deleted. The
874 * failsafe snapshot name is configurable by using the property
875 * "hbase.snapshot.restore.failsafe.name".
876 * @param snapshotName name of the snapshot to restore
877 * @param takeFailSafeSnapshot true if the failsafe snapshot should be taken
878 * @param restoreAcl <code>true</code> to restore acl of snapshot
880 CompletableFuture<Void> restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot,
881 boolean restoreAcl);
884 * Create a new table by cloning the snapshot content.
885 * @param snapshotName name of the snapshot to be cloned
886 * @param tableName name of the table where the snapshot will be restored
888 default CompletableFuture<Void> cloneSnapshot(String snapshotName, TableName tableName) {
889 return cloneSnapshot(snapshotName, tableName, false);
893 * Create a new table by cloning the snapshot content.
894 * @param snapshotName name of the snapshot to be cloned
895 * @param tableName name of the table where the snapshot will be restored
896 * @param restoreAcl <code>true</code> to restore acl of snapshot
898 default CompletableFuture<Void> cloneSnapshot(String snapshotName, TableName tableName,
899 boolean restoreAcl) {
900 return cloneSnapshot(snapshotName, tableName, restoreAcl, null);
904 * Create a new table by cloning the snapshot content.
905 * @param snapshotName name of the snapshot to be cloned
906 * @param tableName name of the table where the snapshot will be restored
907 * @param restoreAcl <code>true</code> to restore acl of snapshot
908 * @param customSFT specify the StroreFileTracker used for the table
910 CompletableFuture<Void> cloneSnapshot(String snapshotName, TableName tableName,
911 boolean restoreAcl, String customSFT);
914 * List completed snapshots.
915 * @return a list of snapshot descriptors for completed snapshots wrapped by a
916 * {@link CompletableFuture}
918 CompletableFuture<List<SnapshotDescription>> listSnapshots();
921 * List all the completed snapshots matching the given pattern.
922 * @param pattern The compiled regular expression to match against
923 * @return - returns a List of SnapshotDescription wrapped by a {@link CompletableFuture}
925 CompletableFuture<List<SnapshotDescription>> listSnapshots(Pattern pattern);
928 * List all the completed snapshots matching the given table name pattern.
929 * @param tableNamePattern The compiled table name regular expression to match against
930 * @return - returns a List of completed SnapshotDescription wrapped by a
931 * {@link CompletableFuture}
933 CompletableFuture<List<SnapshotDescription>> listTableSnapshots(Pattern tableNamePattern);
936 * List all the completed snapshots matching the given table name regular expression and snapshot
937 * name regular expression.
938 * @param tableNamePattern The compiled table name regular expression to match against
939 * @param snapshotNamePattern The compiled snapshot name regular expression to match against
940 * @return - returns a List of completed SnapshotDescription wrapped by a
941 * {@link CompletableFuture}
943 CompletableFuture<List<SnapshotDescription>> listTableSnapshots(Pattern tableNamePattern,
944 Pattern snapshotNamePattern);
947 * Delete an existing snapshot.
948 * @param snapshotName name of the snapshot
950 CompletableFuture<Void> deleteSnapshot(String snapshotName);
953 * Delete all existing snapshots.
955 CompletableFuture<Void> deleteSnapshots();
958 * Delete existing snapshots whose names match the pattern passed.
959 * @param pattern pattern for names of the snapshot to match
961 CompletableFuture<Void> deleteSnapshots(Pattern pattern);
964 * Delete all existing snapshots matching the given table name pattern.
965 * @param tableNamePattern The compiled table name regular expression to match against
967 CompletableFuture<Void> deleteTableSnapshots(Pattern tableNamePattern);
970 * Delete all existing snapshots matching the given table name regular expression and snapshot
971 * name regular expression.
972 * @param tableNamePattern The compiled table name regular expression to match against
973 * @param snapshotNamePattern The compiled snapshot name regular expression to match against
975 CompletableFuture<Void> deleteTableSnapshots(Pattern tableNamePattern,
976 Pattern snapshotNamePattern);
979 * Execute a distributed procedure on a cluster.
980 * @param signature A distributed procedure is uniquely identified by its signature (default the
981 * root ZK node name of the procedure).
982 * @param instance The instance name of the procedure. For some procedures, this parameter is
983 * optional.
984 * @param props Property/Value pairs of properties passing to the procedure
986 CompletableFuture<Void> execProcedure(String signature, String instance,
987 Map<String, String> props);
990 * Execute a distributed procedure on a cluster.
991 * @param signature A distributed procedure is uniquely identified by its signature (default the
992 * root ZK node name of the procedure).
993 * @param instance The instance name of the procedure. For some procedures, this parameter is
994 * optional.
995 * @param props Property/Value pairs of properties passing to the procedure
996 * @return data returned after procedure execution. null if no return data.
998 CompletableFuture<byte[]> execProcedureWithReturn(String signature, String instance,
999 Map<String, String> props);
1002 * Check the current state of the specified procedure. There are three possible states:
1003 * <ol>
1004 * <li>running - returns <tt>false</tt></li>
1005 * <li>finished - returns <tt>true</tt></li>
1006 * <li>finished with error - throws the exception that caused the procedure to fail</li>
1007 * </ol>
1008 * @param signature The signature that uniquely identifies a procedure
1009 * @param instance The instance name of the procedure
1010 * @param props Property/Value pairs of properties passing to the procedure
1011 * @return true if the specified procedure is finished successfully, false if it is still running.
1012 * The value is wrapped by {@link CompletableFuture}
1014 CompletableFuture<Boolean> isProcedureFinished(String signature, String instance,
1015 Map<String, String> props);
1018 * Abort a procedure
1019 * Do not use. Usually it is ignored but if not, it can do more damage than good. See hbck2.
1020 * @param procId ID of the procedure to abort
1021 * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
1022 * @return true if aborted, false if procedure already completed or does not exist. the value is
1023 * wrapped by {@link CompletableFuture}
1024 * @deprecated since 2.1.1 and will be removed in 4.0.0.
1025 * @see <a href="https://issues.apache.org/jira/browse/HBASE-21223">HBASE-21223</a>
1027 @Deprecated
1028 CompletableFuture<Boolean> abortProcedure(long procId, boolean mayInterruptIfRunning);
1031 * List procedures
1032 * @return procedure list JSON wrapped by {@link CompletableFuture}
1034 CompletableFuture<String> getProcedures();
1037 * List locks.
1038 * @return lock list JSON wrapped by {@link CompletableFuture}
1040 CompletableFuture<String> getLocks();
1043 * Mark region server(s) as decommissioned to prevent additional regions from getting
1044 * assigned to them. Optionally unload the regions on the servers. If there are multiple servers
1045 * to be decommissioned, decommissioning them at the same time can prevent wasteful region
1046 * movements. Region unloading is asynchronous.
1047 * @param servers The list of servers to decommission.
1048 * @param offload True to offload the regions from the decommissioned servers
1050 CompletableFuture<Void> decommissionRegionServers(List<ServerName> servers, boolean offload);
1053 * List region servers marked as decommissioned, which can not be assigned regions.
1054 * @return List of decommissioned region servers wrapped by {@link CompletableFuture}
1056 CompletableFuture<List<ServerName>> listDecommissionedRegionServers();
1059 * Remove decommission marker from a region server to allow regions assignments. Load regions onto
1060 * the server if a list of regions is given. Region loading is asynchronous.
1061 * @param server The server to recommission.
1062 * @param encodedRegionNames Regions to load onto the server.
1064 CompletableFuture<Void> recommissionRegionServer(ServerName server,
1065 List<byte[]> encodedRegionNames);
1068 * @return cluster status wrapped by {@link CompletableFuture}
1070 CompletableFuture<ClusterMetrics> getClusterMetrics();
1073 * @return cluster status wrapped by {@link CompletableFuture}
1075 CompletableFuture<ClusterMetrics> getClusterMetrics(EnumSet<Option> options);
1078 * @return current master server name wrapped by {@link CompletableFuture}
1080 default CompletableFuture<ServerName> getMaster() {
1081 return getClusterMetrics(EnumSet.of(Option.MASTER)).thenApply(ClusterMetrics::getMasterName);
1085 * @return current backup master list wrapped by {@link CompletableFuture}
1087 default CompletableFuture<Collection<ServerName>> getBackupMasters() {
1088 return getClusterMetrics(EnumSet.of(Option.BACKUP_MASTERS))
1089 .thenApply(ClusterMetrics::getBackupMasterNames);
1093 * @return current live region servers list wrapped by {@link CompletableFuture}
1095 default CompletableFuture<Collection<ServerName>> getRegionServers() {
1096 return getClusterMetrics(EnumSet.of(Option.SERVERS_NAME))
1097 .thenApply(ClusterMetrics::getServersName);
1100 default CompletableFuture<Collection<ServerName>> getRegionServers(
1101 boolean excludeDecommissionedRS) {
1102 CompletableFuture<Collection<ServerName>> future = new CompletableFuture<>();
1103 addListener(
1104 getClusterMetrics(EnumSet.of(Option.SERVERS_NAME)).thenApply(ClusterMetrics::getServersName),
1105 (allServers, err) -> {
1106 if (err != null) {
1107 future.completeExceptionally(err);
1108 } else {
1109 if (!excludeDecommissionedRS) {
1110 future.complete(allServers);
1111 } else {
1112 addListener(listDecommissionedRegionServers(), (decomServers, decomErr) -> {
1113 if (decomErr != null) {
1114 future.completeExceptionally(decomErr);
1115 } else {
1116 future.complete(allServers.stream().filter(s -> !decomServers.contains(s))
1117 .collect(ImmutableList.toImmutableList()));
1123 return future;
1127 * @return a list of master coprocessors wrapped by {@link CompletableFuture}
1129 default CompletableFuture<List<String>> getMasterCoprocessorNames() {
1130 return getClusterMetrics(EnumSet.of(Option.MASTER_COPROCESSORS))
1131 .thenApply(ClusterMetrics::getMasterCoprocessorNames);
1135 * Get the info port of the current master if one is available.
1136 * @return master info port
1138 default CompletableFuture<Integer> getMasterInfoPort() {
1139 return getClusterMetrics(EnumSet.of(Option.MASTER_INFO_PORT)).thenApply(
1140 ClusterMetrics::getMasterInfoPort);
1144 * Shuts down the HBase cluster.
1146 CompletableFuture<Void> shutdown();
1149 * Shuts down the current HBase master only.
1151 CompletableFuture<Void> stopMaster();
1154 * Stop the designated regionserver.
1155 * @param serverName
1157 CompletableFuture<Void> stopRegionServer(ServerName serverName);
1160 * Update the configuration and trigger an online config change on the regionserver.
1161 * @param serverName : The server whose config needs to be updated.
1163 CompletableFuture<Void> updateConfiguration(ServerName serverName);
1166 * Update the configuration and trigger an online config change on all the masters and
1167 * regionservers.
1169 CompletableFuture<Void> updateConfiguration();
1172 * Update the configuration and trigger an online config change on all the regionservers in
1173 * the RSGroup.
1174 * @param groupName the group name
1176 CompletableFuture<Void> updateConfiguration(String groupName);
1179 * Roll the log writer. I.e. for filesystem based write ahead logs, start writing to a new file.
1180 * <p>
1181 * When the returned CompletableFuture is done, it only means the rollWALWriter request was sent
1182 * to the region server and may need some time to finish the rollWALWriter operation. As a side
1183 * effect of this call, the named region server may schedule store flushes at the request of the
1184 * wal.
1185 * @param serverName The servername of the region server.
1187 CompletableFuture<Void> rollWALWriter(ServerName serverName);
1190 * Clear compacting queues on a region server.
1191 * @param serverName
1192 * @param queues the set of queue name
1194 CompletableFuture<Void> clearCompactionQueues(ServerName serverName, Set<String> queues);
1197 * Get a list of {@link RegionMetrics} of all regions hosted on a region seerver.
1198 * @param serverName
1199 * @return a list of {@link RegionMetrics} wrapped by {@link CompletableFuture}
1201 CompletableFuture<List<RegionMetrics>> getRegionMetrics(ServerName serverName);
1204 * Get a list of {@link RegionMetrics} of all regions hosted on a region seerver for a table.
1205 * @param serverName
1206 * @param tableName
1207 * @return a list of {@link RegionMetrics} wrapped by {@link CompletableFuture}
1209 CompletableFuture<List<RegionMetrics>> getRegionMetrics(ServerName serverName,
1210 TableName tableName);
1213 * Check whether master is in maintenance mode
1214 * @return true if master is in maintenance mode, false otherwise. The return value will be
1215 * wrapped by a {@link CompletableFuture}
1217 CompletableFuture<Boolean> isMasterInMaintenanceMode();
1220 * Get the current compaction state of a table. It could be in a major compaction, a minor
1221 * compaction, both, or none.
1222 * @param tableName table to examine
1223 * @return the current compaction state wrapped by a {@link CompletableFuture}
1225 default CompletableFuture<CompactionState> getCompactionState(TableName tableName) {
1226 return getCompactionState(tableName, CompactType.NORMAL);
1230 * Get the current compaction state of a table. It could be in a major compaction, a minor
1231 * compaction, both, or none.
1232 * @param tableName table to examine
1233 * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
1234 * @return the current compaction state wrapped by a {@link CompletableFuture}
1236 CompletableFuture<CompactionState> getCompactionState(TableName tableName,
1237 CompactType compactType);
1240 * Get the current compaction state of region. It could be in a major compaction, a minor
1241 * compaction, both, or none.
1242 * @param regionName region to examine
1243 * @return the current compaction state wrapped by a {@link CompletableFuture}
1245 CompletableFuture<CompactionState> getCompactionStateForRegion(byte[] regionName);
1248 * Get the timestamp of the last major compaction for the passed table.
1249 * <p>
1250 * The timestamp of the oldest HFile resulting from a major compaction of that table, or not
1251 * present if no such HFile could be found.
1252 * @param tableName table to examine
1253 * @return the last major compaction timestamp wrapped by a {@link CompletableFuture}
1255 CompletableFuture<Optional<Long>> getLastMajorCompactionTimestamp(TableName tableName);
1258 * Get the timestamp of the last major compaction for the passed region.
1259 * <p>
1260 * The timestamp of the oldest HFile resulting from a major compaction of that region, or not
1261 * present if no such HFile could be found.
1262 * @param regionName region to examine
1263 * @return the last major compaction timestamp wrapped by a {@link CompletableFuture}
1265 CompletableFuture<Optional<Long>> getLastMajorCompactionTimestampForRegion(byte[] regionName);
1268 * @return the list of supported security capabilities. The return value will be wrapped by a
1269 * {@link CompletableFuture}.
1271 CompletableFuture<List<SecurityCapability>> getSecurityCapabilities();
1274 * Turn the load balancer on or off.
1275 * @param on Set to <code>true</code> to enable, <code>false</code> to disable.
1276 * @return Previous balancer value wrapped by a {@link CompletableFuture}.
1278 default CompletableFuture<Boolean> balancerSwitch(boolean on) {
1279 return balancerSwitch(on, false);
1283 * Turn the load balancer on or off.
1284 * <p/>
1285 * Notice that, the method itself is always non-blocking, which means it will always return
1286 * immediately. The {@code drainRITs} parameter only effects when will we complete the returned
1287 * {@link CompletableFuture}.
1288 * @param on Set to <code>true</code> to enable, <code>false</code> to disable.
1289 * @param drainRITs If <code>true</code>, it waits until current balance() call, if outstanding,
1290 * to return.
1291 * @return Previous balancer value wrapped by a {@link CompletableFuture}.
1293 CompletableFuture<Boolean> balancerSwitch(boolean on, boolean drainRITs);
1296 * Invoke the balancer. Will run the balancer and if regions to move, it will go ahead and do the
1297 * reassignments. Can NOT run for various reasons. Check logs.
1298 * @return True if balancer ran, false otherwise. The return value will be wrapped by a
1299 * {@link CompletableFuture}.
1301 default CompletableFuture<Boolean> balance() {
1302 return balance(BalanceRequest.defaultInstance())
1303 .thenApply(BalanceResponse::isBalancerRan);
1307 * Invoke the balancer. Will run the balancer and if regions to move, it will go ahead and do the
1308 * reassignments. If there is region in transition, force parameter of true would still run
1309 * balancer. Can *not* run for other reasons. Check logs.
1310 * @param forcible whether we should force balance even if there is region in transition.
1311 * @return True if balancer ran, false otherwise. The return value will be wrapped by a
1312 * {@link CompletableFuture}.
1313 * @deprecated Since 2.5.0. Will be removed in 4.0.0.
1314 * Use {@link #balance(BalanceRequest)} instead.
1316 default CompletableFuture<Boolean> balance(boolean forcible) {
1317 return balance(
1318 BalanceRequest.newBuilder()
1319 .setIgnoreRegionsInTransition(forcible)
1320 .build()
1321 ).thenApply(BalanceResponse::isBalancerRan);
1325 * Invoke the balancer with the given balance request. The BalanceRequest defines how the
1326 * balancer will run. See {@link BalanceRequest} for more details.
1328 * @param request defines how the balancer should run
1329 * @return {@link BalanceResponse} with details about the results of the invocation.
1331 CompletableFuture<BalanceResponse> balance(BalanceRequest request);
1334 * Query the current state of the balancer.
1335 * @return true if the balance switch is on, false otherwise. The return value will be wrapped by a
1336 * {@link CompletableFuture}.
1338 CompletableFuture<Boolean> isBalancerEnabled();
1341 * Set region normalizer on/off.
1342 * @param on whether normalizer should be on or off
1343 * @return Previous normalizer value wrapped by a {@link CompletableFuture}
1345 CompletableFuture<Boolean> normalizerSwitch(boolean on);
1348 * Query the current state of the region normalizer
1349 * @return true if region normalizer is on, false otherwise. The return value will be wrapped by a
1350 * {@link CompletableFuture}
1352 CompletableFuture<Boolean> isNormalizerEnabled();
1355 * Invoke region normalizer. Can NOT run for various reasons. Check logs.
1356 * @return true if region normalizer ran, false otherwise. The return value will be wrapped by a
1357 * {@link CompletableFuture}
1359 default CompletableFuture<Boolean> normalize() {
1360 return normalize(new NormalizeTableFilterParams.Builder().build());
1364 * Invoke region normalizer. Can NOT run for various reasons. Check logs.
1365 * @param ntfp limit to tables matching the specified filter.
1366 * @return true if region normalizer ran, false otherwise. The return value will be wrapped by a
1367 * {@link CompletableFuture}
1369 CompletableFuture<Boolean> normalize(NormalizeTableFilterParams ntfp);
1372 * Turn the cleaner chore on/off.
1373 * @param on
1374 * @return Previous cleaner state wrapped by a {@link CompletableFuture}
1376 CompletableFuture<Boolean> cleanerChoreSwitch(boolean on);
1379 * Query the current state of the cleaner chore.
1380 * @return true if cleaner chore is on, false otherwise. The return value will be wrapped by
1381 * a {@link CompletableFuture}
1383 CompletableFuture<Boolean> isCleanerChoreEnabled();
1386 * Ask for cleaner chore to run.
1387 * @return true if cleaner chore ran, false otherwise. The return value will be wrapped by a
1388 * {@link CompletableFuture}
1390 CompletableFuture<Boolean> runCleanerChore();
1393 * Turn the catalog janitor on/off.
1394 * @param on
1395 * @return the previous state wrapped by a {@link CompletableFuture}
1397 CompletableFuture<Boolean> catalogJanitorSwitch(boolean on);
1400 * Query on the catalog janitor state.
1401 * @return true if the catalog janitor is on, false otherwise. The return value will be
1402 * wrapped by a {@link CompletableFuture}
1404 CompletableFuture<Boolean> isCatalogJanitorEnabled();
1407 * Ask for a scan of the catalog table.
1408 * @return the number of entries cleaned. The return value will be wrapped by a
1409 * {@link CompletableFuture}
1411 CompletableFuture<Integer> runCatalogJanitor();
1414 * Execute the given coprocessor call on the master.
1415 * <p>
1416 * The {@code stubMaker} is just a delegation to the {@code newStub} call. Usually it is only a
1417 * one line lambda expression, like:
1419 * <pre>
1420 * <code>
1421 * channel -> xxxService.newStub(channel)
1422 * </code>
1423 * </pre>
1424 * @param stubMaker a delegation to the actual {@code newStub} call.
1425 * @param callable a delegation to the actual protobuf rpc call. See the comment of
1426 * {@link ServiceCaller} for more details.
1427 * @param <S> the type of the asynchronous stub
1428 * @param <R> the type of the return value
1429 * @return the return value of the protobuf rpc call, wrapped by a {@link CompletableFuture}.
1430 * @see ServiceCaller
1432 <S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker,
1433 ServiceCaller<S, R> callable);
1436 * Execute the given coprocessor call on the given region server.
1437 * <p>
1438 * The {@code stubMaker} is just a delegation to the {@code newStub} call. Usually it is only a
1439 * one line lambda expression, like:
1441 * <pre>
1442 * <code>
1443 * channel -> xxxService.newStub(channel)
1444 * </code>
1445 * </pre>
1446 * @param stubMaker a delegation to the actual {@code newStub} call.
1447 * @param callable a delegation to the actual protobuf rpc call. See the comment of
1448 * {@link ServiceCaller} for more details.
1449 * @param serverName the given region server
1450 * @param <S> the type of the asynchronous stub
1451 * @param <R> the type of the return value
1452 * @return the return value of the protobuf rpc call, wrapped by a {@link CompletableFuture}.
1453 * @see ServiceCaller
1455 <S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker,
1456 ServiceCaller<S, R> callable, ServerName serverName);
1459 * List all the dead region servers.
1461 default CompletableFuture<List<ServerName>> listDeadServers() {
1462 return this.getClusterMetrics(EnumSet.of(Option.DEAD_SERVERS))
1463 .thenApply(ClusterMetrics::getDeadServerNames);
1467 * Clear dead region servers from master.
1468 * @param servers list of dead region servers.
1469 * @return - returns a list of servers that not cleared wrapped by a {@link CompletableFuture}.
1471 CompletableFuture<List<ServerName>> clearDeadServers(final List<ServerName> servers);
1474 * Clear all the blocks corresponding to this table from BlockCache. For expert-admins. Calling
1475 * this API will drop all the cached blocks specific to a table from BlockCache. This can
1476 * significantly impact the query performance as the subsequent queries will have to retrieve the
1477 * blocks from underlying filesystem.
1478 * @param tableName table to clear block cache
1479 * @return CacheEvictionStats related to the eviction wrapped by a {@link CompletableFuture}.
1481 CompletableFuture<CacheEvictionStats> clearBlockCache(final TableName tableName);
1484 * Create a new table by cloning the existent table schema.
1486 * @param tableName name of the table to be cloned
1487 * @param newTableName name of the new table where the table will be created
1488 * @param preserveSplits True if the splits should be preserved
1490 CompletableFuture<Void> cloneTableSchema(final TableName tableName,
1491 final TableName newTableName, final boolean preserveSplits);
1494 * Turn the compaction on or off. Disabling compactions will also interrupt any currently ongoing
1495 * compactions. This state is ephemeral. The setting will be lost on restart. Compaction
1496 * can also be enabled/disabled by modifying configuration hbase.regionserver.compaction.enabled
1497 * in hbase-site.xml.
1499 * @param switchState Set to <code>true</code> to enable, <code>false</code> to disable.
1500 * @param serverNamesList list of region servers.
1501 * @return Previous compaction states for region servers
1503 CompletableFuture<Map<ServerName, Boolean>> compactionSwitch(boolean switchState,
1504 List<String> serverNamesList);
1507 * Switch the rpc throttle enabled state.
1508 * @param enable Set to <code>true</code> to enable, <code>false</code> to disable.
1509 * @return Previous rpc throttle enabled value
1511 CompletableFuture<Boolean> switchRpcThrottle(boolean enable);
1514 * Get if the rpc throttle is enabled.
1515 * @return True if rpc throttle is enabled
1517 CompletableFuture<Boolean> isRpcThrottleEnabled();
1520 * Switch the exceed throttle quota. If enabled, user/table/namespace throttle quota
1521 * can be exceeded if region server has availble quota.
1522 * @param enable Set to <code>true</code> to enable, <code>false</code> to disable.
1523 * @return Previous exceed throttle enabled value
1525 CompletableFuture<Boolean> exceedThrottleQuotaSwitch(boolean enable);
1528 * Fetches the table sizes on the filesystem as tracked by the HBase Master.
1530 CompletableFuture<Map<TableName, Long>> getSpaceQuotaTableSizes();
1533 * Fetches the observed {@link SpaceQuotaSnapshotView}s observed by a RegionServer.
1535 CompletableFuture<? extends Map<TableName, ? extends SpaceQuotaSnapshotView>>
1536 getRegionServerSpaceQuotaSnapshots(ServerName serverName);
1539 * Returns the Master's view of a quota on the given {@code namespace} or null if the Master has
1540 * no quota information on that namespace.
1542 CompletableFuture<? extends SpaceQuotaSnapshotView>
1543 getCurrentSpaceQuotaSnapshot(String namespace);
1546 * Returns the Master's view of a quota on the given {@code tableName} or null if the Master has
1547 * no quota information on that table.
1549 CompletableFuture<? extends SpaceQuotaSnapshotView> getCurrentSpaceQuotaSnapshot(
1550 TableName tableName);
1553 * Grants user specific permissions
1554 * @param userPermission user name and the specific permission
1555 * @param mergeExistingPermissions If set to false, later granted permissions will override
1556 * previous granted permissions. otherwise, it'll merge with previous granted
1557 * permissions.
1559 CompletableFuture<Void> grant(UserPermission userPermission, boolean mergeExistingPermissions);
1562 * Revokes user specific permissions
1563 * @param userPermission user name and the specific permission
1565 CompletableFuture<Void> revoke(UserPermission userPermission);
1568 * Get the global/namespace/table permissions for user
1569 * @param getUserPermissionsRequest A request contains which user, global, namespace or table
1570 * permissions needed
1571 * @return The user and permission list
1573 CompletableFuture<List<UserPermission>>
1574 getUserPermissions(GetUserPermissionsRequest getUserPermissionsRequest);
1577 * Check if the user has specific permissions
1578 * @param userName the user name
1579 * @param permissions the specific permission list
1580 * @return True if user has the specific permissions
1582 CompletableFuture<List<Boolean>> hasUserPermissions(String userName,
1583 List<Permission> permissions);
1586 * Check if call user has specific permissions
1587 * @param permissions the specific permission list
1588 * @return True if user has the specific permissions
1590 default CompletableFuture<List<Boolean>> hasUserPermissions(List<Permission> permissions) {
1591 return hasUserPermissions(null, permissions);
1595 * Turn on or off the auto snapshot cleanup based on TTL.
1596 * <p/>
1597 * Notice that, the method itself is always non-blocking, which means it will always return
1598 * immediately. The {@code sync} parameter only effects when will we complete the returned
1599 * {@link CompletableFuture}.
1601 * @param on Set to <code>true</code> to enable, <code>false</code> to disable.
1602 * @param sync If <code>true</code>, it waits until current snapshot cleanup is completed,
1603 * if outstanding.
1604 * @return Previous auto snapshot cleanup value wrapped by a {@link CompletableFuture}.
1606 CompletableFuture<Boolean> snapshotCleanupSwitch(boolean on, boolean sync);
1609 * Query the current state of the auto snapshot cleanup based on TTL.
1611 * @return true if the auto snapshot cleanup is enabled, false otherwise.
1612 * The return value will be wrapped by a {@link CompletableFuture}.
1614 CompletableFuture<Boolean> isSnapshotCleanupEnabled();
1617 * Retrieves online slow RPC logs from the provided list of
1618 * RegionServers
1620 * @param serverNames Server names to get slowlog responses from
1621 * @param logQueryFilter filter to be used if provided
1622 * @return Online slowlog response list. The return value wrapped by a {@link CompletableFuture}
1623 * @deprecated since 2.4.0 and will be removed in 4.0.0.
1624 * Use {@link #getLogEntries(Set, String, ServerType, int, Map)} instead.
1626 @Deprecated
1627 default CompletableFuture<List<OnlineLogRecord>> getSlowLogResponses(
1628 final Set<ServerName> serverNames, final LogQueryFilter logQueryFilter) {
1629 String logType;
1630 if (LogQueryFilter.Type.LARGE_LOG.equals(logQueryFilter.getType())) {
1631 logType = "LARGE_LOG";
1632 } else {
1633 logType = "SLOW_LOG";
1635 Map<String, Object> filterParams = new HashMap<>();
1636 filterParams.put("regionName", logQueryFilter.getRegionName());
1637 filterParams.put("clientAddress", logQueryFilter.getClientAddress());
1638 filterParams.put("tableName", logQueryFilter.getTableName());
1639 filterParams.put("userName", logQueryFilter.getUserName());
1640 filterParams.put("filterByOperator", logQueryFilter.getFilterByOperator().toString());
1641 CompletableFuture<List<LogEntry>> logEntries =
1642 getLogEntries(serverNames, logType, ServerType.REGION_SERVER, logQueryFilter.getLimit(),
1643 filterParams);
1644 return logEntries.thenApply(
1645 logEntryList -> logEntryList.stream().map(logEntry -> (OnlineLogRecord) logEntry)
1646 .collect(Collectors.toList()));
1650 * Clears online slow RPC logs from the provided list of
1651 * RegionServers
1653 * @param serverNames Set of Server names to clean slowlog responses from
1654 * @return List of booleans representing if online slowlog response buffer is cleaned
1655 * from each RegionServer. The return value wrapped by a {@link CompletableFuture}
1657 CompletableFuture<List<Boolean>> clearSlowLogResponses(final Set<ServerName> serverNames);
1660 * Creates a new RegionServer group with the given name
1661 * @param groupName the name of the group
1662 * @throws IOException if a remote or network exception occurs
1664 CompletableFuture<Void> addRSGroup(String groupName);
1667 * Get group info for the given group name
1668 * @param groupName the group name
1669 * @return group info
1670 * @throws IOException if a remote or network exception occurs
1672 CompletableFuture<RSGroupInfo> getRSGroup(String groupName);
1675 * Get group info for the given hostPort
1676 * @param hostPort HostPort to get RSGroupInfo for
1677 * @throws IOException if a remote or network exception occurs
1679 CompletableFuture<RSGroupInfo> getRSGroup(Address hostPort);
1682 * Get group info for the given table
1683 * @param tableName table name to get RSGroupInfo for
1684 * @throws IOException if a remote or network exception occurs
1686 CompletableFuture<RSGroupInfo> getRSGroup(TableName tableName);
1689 * Lists current set of RegionServer groups
1690 * @throws IOException if a remote or network exception occurs
1692 CompletableFuture<List<RSGroupInfo>> listRSGroups();
1695 * Get all tables in this RegionServer group.
1696 * @param groupName the group name
1697 * @throws IOException if a remote or network exception occurs
1698 * @see #getConfiguredNamespacesAndTablesInRSGroup(String)
1700 CompletableFuture<List<TableName>> listTablesInRSGroup(String groupName);
1703 * Get the namespaces and tables which have this RegionServer group in descriptor.
1704 * <p/>
1705 * The difference between this method and {@link #listTablesInRSGroup(String)} is that, this
1706 * method will not include the table which is actually in this RegionServr group but without the
1707 * RegionServer group configuration in its {@link TableDescriptor}. For example, we have a group
1708 * 'A', and we make namespace 'nsA' in this group, then all the tables under this namespace will
1709 * in the group 'A', but this method will not return these tables but only the namespace 'nsA',
1710 * while the {@link #listTablesInRSGroup(String)} will return all these tables.
1711 * @param groupName the group name
1712 * @throws IOException if a remote or network exception occurs
1713 * @see #listTablesInRSGroup(String)
1715 CompletableFuture<Pair<List<String>, List<TableName>>>
1716 getConfiguredNamespacesAndTablesInRSGroup(String groupName);
1719 * Remove RegionServer group associated with the given name
1720 * @param groupName the group name
1721 * @throws IOException if a remote or network exception occurs
1723 CompletableFuture<Void> removeRSGroup(String groupName);
1726 * Remove decommissioned servers from group
1727 * 1. Sometimes we may find the server aborted due to some hardware failure and we must offline
1728 * the server for repairing. Or we need to move some servers to join other clusters.
1729 * So we need to remove these servers from the group.
1730 * 2. Dead/recovering/live servers will be disallowed.
1731 * @param servers set of servers to remove
1732 * @throws IOException if a remote or network exception occurs
1734 CompletableFuture<Void> removeServersFromRSGroup(Set<Address> servers);
1737 * Move given set of servers to the specified target RegionServer group
1738 * @param servers set of servers to move
1739 * @param groupName the group to move servers to
1740 * @throws IOException if a remote or network exception occurs
1742 CompletableFuture<Void> moveServersToRSGroup(Set<Address> servers, String groupName);
1745 * Set the RegionServer group for tables
1746 * @param tables tables to set group for
1747 * @param groupName group name for tables
1748 * @throws IOException if a remote or network exception occurs
1750 CompletableFuture<Void> setRSGroup(Set<TableName> tables, String groupName);
1753 * Balance regions in the given RegionServer group
1754 * @param groupName the group name
1755 * @return BalanceResponse details about the balancer run
1756 * @throws IOException if a remote or network exception occurs
1758 default CompletableFuture<BalanceResponse> balanceRSGroup(String groupName) {
1759 return balanceRSGroup(groupName, BalanceRequest.defaultInstance());
1763 * Balance regions in the given RegionServer group
1764 * @param groupName the group name
1765 * @param request options to define how the balancer should run
1766 * @return BalanceResponse details about the balancer run
1767 * @throws IOException if a remote or network exception occurs
1769 CompletableFuture<BalanceResponse> balanceRSGroup(String groupName, BalanceRequest request);
1772 * Rename rsgroup
1773 * @param oldName old rsgroup name
1774 * @param newName new rsgroup name
1775 * @throws IOException if a remote or network exception occurs
1777 CompletableFuture<Void> renameRSGroup(String oldName, String newName);
1780 * Update RSGroup configuration
1781 * @param groupName the group name
1782 * @param configuration new configuration of the group name to be set
1783 * @throws IOException if a remote or network exception occurs
1785 CompletableFuture<Void> updateRSGroupConfig(String groupName, Map<String, String> configuration);
1788 * Retrieve recent online records from HMaster / RegionServers.
1789 * Examples include slow/large RPC logs, balancer decisions by master.
1791 * @param serverNames servers to retrieve records from, useful in case of records maintained
1792 * by RegionServer as we can select specific server. In case of servertype=MASTER, logs will
1793 * only come from the currently active master.
1794 * @param logType string representing type of log records
1795 * @param serverType enum for server type: HMaster or RegionServer
1796 * @param limit put a limit to list of records that server should send in response
1797 * @param filterParams additional filter params
1798 * @return Log entries representing online records from servers
1800 CompletableFuture<List<LogEntry>> getLogEntries(Set<ServerName> serverNames, String logType,
1801 ServerType serverType, int limit, Map<String, Object> filterParams);