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