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.get; 021 022import java.io.Closeable; 023import java.io.IOException; 024import java.util.Collection; 025import java.util.EnumSet; 026import java.util.HashMap; 027import java.util.List; 028import java.util.Map; 029import java.util.Set; 030import java.util.concurrent.Future; 031import java.util.concurrent.TimeUnit; 032import java.util.regex.Pattern; 033import java.util.stream.Collectors; 034import org.apache.hadoop.conf.Configuration; 035import org.apache.hadoop.hbase.Abortable; 036import org.apache.hadoop.hbase.CacheEvictionStats; 037import org.apache.hadoop.hbase.ClusterMetrics; 038import org.apache.hadoop.hbase.ClusterMetrics.Option; 039import org.apache.hadoop.hbase.NamespaceDescriptor; 040import org.apache.hadoop.hbase.NamespaceNotFoundException; 041import org.apache.hadoop.hbase.RegionMetrics; 042import org.apache.hadoop.hbase.ServerName; 043import org.apache.hadoop.hbase.TableExistsException; 044import org.apache.hadoop.hbase.TableName; 045import org.apache.hadoop.hbase.TableNotFoundException; 046import org.apache.hadoop.hbase.client.replication.ReplicationPeerConfigUtil; 047import org.apache.hadoop.hbase.client.replication.TableCFs; 048import org.apache.hadoop.hbase.client.security.SecurityCapability; 049import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel; 050import org.apache.hadoop.hbase.net.Address; 051import org.apache.hadoop.hbase.quotas.QuotaFilter; 052import org.apache.hadoop.hbase.quotas.QuotaSettings; 053import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshotView; 054import org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException; 055import org.apache.hadoop.hbase.replication.ReplicationException; 056import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; 057import org.apache.hadoop.hbase.replication.ReplicationPeerDescription; 058import org.apache.hadoop.hbase.replication.SyncReplicationState; 059import org.apache.hadoop.hbase.rsgroup.RSGroupInfo; 060import org.apache.hadoop.hbase.security.access.GetUserPermissionsRequest; 061import org.apache.hadoop.hbase.security.access.Permission; 062import org.apache.hadoop.hbase.security.access.UserPermission; 063import org.apache.hadoop.hbase.snapshot.HBaseSnapshotException; 064import org.apache.hadoop.hbase.snapshot.RestoreSnapshotException; 065import org.apache.hadoop.hbase.snapshot.SnapshotCreationException; 066import org.apache.hadoop.hbase.snapshot.UnknownSnapshotException; 067import org.apache.hadoop.hbase.util.Bytes; 068import org.apache.hadoop.hbase.util.Pair; 069import org.apache.yetus.audience.InterfaceAudience; 070 071import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList; 072 073/** 074 * The administrative API for HBase. Obtain an instance from {@link Connection#getAdmin()} and call 075 * {@link #close()} when done. 076 * <p> 077 * Admin can be used to create, drop, list, enable and disable and otherwise modify tables, as well 078 * as perform other administrative operations. 079 * @see ConnectionFactory 080 * @see Connection 081 * @see Table 082 * @since 0.99.0 083 */ 084@InterfaceAudience.Public 085public interface Admin extends Abortable, Closeable { 086 087 /** 088 * Return the operation timeout for a rpc call. 089 * @see #getSyncWaitTimeout() 090 */ 091 int getOperationTimeout(); 092 093 /** 094 * Return the blocking wait time for an asynchronous operation. Can be configured by 095 * {@code hbase.client.sync.wait.timeout.msec}. 096 * <p/> 097 * For several operations, such as createTable, deleteTable, etc, the rpc call will finish right 098 * after we schedule a procedure at master side, so the timeout will not be controlled by the 099 * above {@link #getOperationTimeout()}. And timeout value here tells you how much time we will 100 * wait until the procedure at master side is finished. 101 * <p/> 102 * In general, you can consider that the implementation for XXXX method is just a 103 * XXXXAsync().get(getSyncWaitTimeout(), TimeUnit.MILLISECONDS). 104 * @see #getOperationTimeout() 105 */ 106 int getSyncWaitTimeout(); 107 108 @Override 109 void abort(String why, Throwable e); 110 111 @Override 112 boolean isAborted(); 113 114 /** Returns Connection used by this object. */ 115 Connection getConnection(); 116 117 /** 118 * Check if a table exists. 119 * @param tableName Table to check. 120 * @return <code>true</code> if table exists already. 121 * @throws IOException if a remote or network exception occurs 122 */ 123 boolean tableExists(TableName tableName) throws IOException; 124 125 /** 126 * List all the userspace tables. 127 * @return a list of TableDescriptors 128 * @throws IOException if a remote or network exception occurs 129 */ 130 List<TableDescriptor> listTableDescriptors() throws IOException; 131 132 /** 133 * List all userspace tables and whether or not include system tables. 134 * @return a list of TableDescriptors 135 * @throws IOException if a remote or network exception occurs 136 */ 137 List<TableDescriptor> listTableDescriptors(boolean includeSysTables) throws IOException; 138 139 /** 140 * List all the userspace tables that match the given pattern. 141 * @param pattern The compiled regular expression to match against 142 * @return a list of TableDescriptors 143 * @throws IOException if a remote or network exception occurs 144 * @see #listTableDescriptors() 145 */ 146 default List<TableDescriptor> listTableDescriptors(Pattern pattern) throws IOException { 147 return listTableDescriptors(pattern, false); 148 } 149 150 /** 151 * List all the tables matching the given pattern. 152 * @param pattern The compiled regular expression to match against 153 * @param includeSysTables <code>false</code> to match only against userspace tables 154 * @return a list of TableDescriptors 155 * @throws IOException if a remote or network exception occurs 156 * @see #listTableDescriptors() 157 */ 158 List<TableDescriptor> listTableDescriptors(Pattern pattern, boolean includeSysTables) 159 throws IOException; 160 161 /** 162 * List all enabled or disabled tables 163 * @param isEnabled is true means return enabled tables, false means return disabled tables 164 * @return a list of enabled or disabled tables 165 */ 166 List<TableDescriptor> listTableDescriptorsByState(boolean isEnabled) throws IOException; 167 168 /** 169 * List all of the names of userspace tables. 170 * @return TableName[] table names 171 * @throws IOException if a remote or network exception occurs 172 */ 173 TableName[] listTableNames() throws IOException; 174 175 /** 176 * List all of the names of userspace tables. 177 * @param pattern The regular expression to match against 178 * @return array of table names 179 * @throws IOException if a remote or network exception occurs 180 */ 181 default TableName[] listTableNames(Pattern pattern) throws IOException { 182 return listTableNames(pattern, false); 183 } 184 185 /** 186 * List all of the names of userspace tables. 187 * @param pattern The regular expression to match against 188 * @param includeSysTables <code>false</code> to match only against userspace tables 189 * @return TableName[] table names 190 * @throws IOException if a remote or network exception occurs 191 */ 192 TableName[] listTableNames(Pattern pattern, boolean includeSysTables) throws IOException; 193 194 /** 195 * List all enabled or disabled table names 196 * @param isEnabled is true means return enabled table names, false means return disabled table 197 * names 198 * @return a list of enabled or disabled table names 199 */ 200 List<TableName> listTableNamesByState(boolean isEnabled) throws IOException; 201 202 /** 203 * Get a table descriptor. 204 * @param tableName as a {@link TableName} 205 * @return the tableDescriptor 206 * @throws TableNotFoundException if the table was not found 207 * @throws IOException if a remote or network exception occurs 208 */ 209 TableDescriptor getDescriptor(TableName tableName) throws TableNotFoundException, IOException; 210 211 /** 212 * Creates a new table. Synchronous operation. 213 * @param desc table descriptor for table 214 * @throws IllegalArgumentException if the table name is reserved 215 * @throws org.apache.hadoop.hbase.MasterNotRunningException if master is not running 216 * @throws TableExistsException if table already exists (If 217 * concurrent threads, the table may 218 * have been created between 219 * test-for-existence and 220 * attempt-at-creation). 221 * @throws IOException if a remote or network exception 222 * occurs 223 */ 224 default void createTable(TableDescriptor desc) throws IOException { 225 get(createTableAsync(desc), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 226 } 227 228 /** 229 * Creates a new table with the specified number of regions. The start key specified will become 230 * the end key of the first region of the table, and the end key specified will become the start 231 * key of the last region of the table (the first region has a null start key and the last region 232 * has a null end key). BigInteger math will be used to divide the key range specified into enough 233 * segments to make the required number of total regions. Synchronous operation. 234 * @param desc table descriptor for table 235 * @param startKey beginning of key range 236 * @param endKey end of key range 237 * @param numRegions the total number of regions to create 238 * @throws IOException if a remote or network exception 239 * occurs 240 * @throws IllegalArgumentException if the table name is reserved 241 * @throws org.apache.hadoop.hbase.MasterNotRunningException if master is not running 242 * @throws TableExistsException if table already exists (If 243 * concurrent threads, the table may 244 * have been created between 245 * test-for-existence and 246 * attempt-at-creation). 247 */ 248 void createTable(TableDescriptor desc, byte[] startKey, byte[] endKey, int numRegions) 249 throws IOException; 250 251 /** 252 * Creates a new table with an initial set of empty regions defined by the specified split keys. 253 * The total number of regions created will be the number of split keys plus one. Synchronous 254 * operation. Note : Avoid passing empty split key. 255 * @param desc table descriptor for table 256 * @param splitKeys array of split keys for the initial regions of the table 257 * @throws IllegalArgumentException if the table name is reserved, if the 258 * split keys are repeated and if the 259 * split key has empty byte array. 260 * @throws org.apache.hadoop.hbase.MasterNotRunningException if master is not running 261 * @throws TableExistsException if table already exists (If 262 * concurrent threads, the table may 263 * have been created between 264 * test-for-existence and 265 * attempt-at-creation). 266 * @throws IOException if a remote or network exception 267 * occurs 268 */ 269 default void createTable(TableDescriptor desc, byte[][] splitKeys) throws IOException { 270 get(createTableAsync(desc, splitKeys), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 271 } 272 273 /** 274 * Creates a new table but does not block and wait for it to come online. You can use 275 * Future.get(long, TimeUnit) to wait on the operation to complete. It may throw 276 * ExecutionException if there was an error while executing the operation or TimeoutException in 277 * case the wait timeout was not long enough to allow the operation to complete. 278 * <p/> 279 * Throws IllegalArgumentException Bad table name, if the split keys are repeated and if the split 280 * key has empty byte array. 281 * @param desc table descriptor for table 282 * @throws IOException if a remote or network exception occurs 283 * @return the result of the async creation. You can use Future.get(long, TimeUnit) to wait on the 284 * operation to complete. 285 */ 286 Future<Void> createTableAsync(TableDescriptor desc) throws IOException; 287 288 /** 289 * Creates a new table but does not block and wait for it to come online. You can use 290 * Future.get(long, TimeUnit) to wait on the operation to complete. It may throw 291 * ExecutionException if there was an error while executing the operation or TimeoutException in 292 * case the wait timeout was not long enough to allow the operation to complete. Throws 293 * IllegalArgumentException Bad table name, if the split keys are repeated and if the split key 294 * has empty byte array. 295 * @param desc table descriptor for table 296 * @param splitKeys keys to check if the table has been created with all split keys 297 * @throws IOException if a remote or network exception occurs 298 * @return the result of the async creation. You can use Future.get(long, TimeUnit) to wait on the 299 * operation to complete. 300 */ 301 Future<Void> createTableAsync(TableDescriptor desc, byte[][] splitKeys) throws IOException; 302 303 /** 304 * Deletes a table. Synchronous operation. 305 * @param tableName name of table to delete 306 * @throws IOException if a remote or network exception occurs 307 */ 308 default void deleteTable(TableName tableName) throws IOException { 309 get(deleteTableAsync(tableName), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 310 } 311 312 /** 313 * Deletes the table but does not block and wait for it to be completely removed. You can use 314 * Future.get(long, TimeUnit) to wait on the operation to complete. It may throw 315 * ExecutionException if there was an error while executing the operation or TimeoutException in 316 * case the wait timeout was not long enough to allow the operation to complete. 317 * @param tableName name of table to delete 318 * @throws IOException if a remote or network exception occurs 319 * @return the result of the async delete. You can use Future.get(long, TimeUnit) to wait on the 320 * operation to complete. 321 */ 322 Future<Void> deleteTableAsync(TableName tableName) throws IOException; 323 324 /** 325 * Truncate a table. Synchronous operation. 326 * @param tableName name of table to truncate 327 * @param preserveSplits <code>true</code> if the splits should be preserved 328 * @throws IOException if a remote or network exception occurs 329 */ 330 default void truncateTable(TableName tableName, boolean preserveSplits) throws IOException { 331 get(truncateTableAsync(tableName, preserveSplits), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 332 } 333 334 /** 335 * Truncate the table but does not block and wait for it to be completely enabled. You can use 336 * Future.get(long, TimeUnit) to wait on the operation to complete. It may throw 337 * ExecutionException if there was an error while executing the operation or TimeoutException in 338 * case the wait timeout was not long enough to allow the operation to complete. 339 * @param tableName name of table to delete 340 * @param preserveSplits <code>true</code> if the splits should be preserved 341 * @throws IOException if a remote or network exception occurs 342 * @return the result of the async truncate. You can use Future.get(long, TimeUnit) to wait on the 343 * operation to complete. 344 */ 345 Future<Void> truncateTableAsync(TableName tableName, boolean preserveSplits) throws IOException; 346 347 /** 348 * Enable a table. May timeout. Use {@link #enableTableAsync(org.apache.hadoop.hbase.TableName)} 349 * and {@link #isTableEnabled(org.apache.hadoop.hbase.TableName)} instead. The table has to be in 350 * disabled state for it to be enabled. 351 * @param tableName name of the table 352 * @throws IOException There could be couple types of IOException TableNotFoundException means the 353 * table doesn't exist. TableNotDisabledException means the table isn't in 354 * disabled state. 355 * @see #isTableEnabled(org.apache.hadoop.hbase.TableName) 356 * @see #disableTable(org.apache.hadoop.hbase.TableName) 357 * @see #enableTableAsync(org.apache.hadoop.hbase.TableName) 358 */ 359 default void enableTable(TableName tableName) throws IOException { 360 get(enableTableAsync(tableName), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 361 } 362 363 /** 364 * Enable the table but does not block and wait for it to be completely enabled. You can use 365 * Future.get(long, TimeUnit) to wait on the operation to complete. It may throw 366 * ExecutionException if there was an error while executing the operation or TimeoutException in 367 * case the wait timeout was not long enough to allow the operation to complete. 368 * @param tableName name of table to delete 369 * @throws IOException if a remote or network exception occurs 370 * @return the result of the async enable. You can use Future.get(long, TimeUnit) to wait on the 371 * operation to complete. 372 */ 373 Future<Void> enableTableAsync(TableName tableName) throws IOException; 374 375 /** 376 * Disable the table but does not block and wait for it to be completely disabled. You can use 377 * Future.get(long, TimeUnit) to wait on the operation to complete. It may throw 378 * ExecutionException if there was an error while executing the operation or TimeoutException in 379 * case the wait timeout was not long enough to allow the operation to complete. 380 * @param tableName name of table to delete 381 * @throws IOException if a remote or network exception occurs 382 * @return the result of the async disable. You can use Future.get(long, TimeUnit) to wait on the 383 * operation to complete. 384 */ 385 Future<Void> disableTableAsync(TableName tableName) throws IOException; 386 387 /** 388 * Disable table and wait on completion. May timeout eventually. Use 389 * {@link #disableTableAsync(org.apache.hadoop.hbase.TableName)} and 390 * {@link #isTableDisabled(org.apache.hadoop.hbase.TableName)} instead. The table has to be in 391 * enabled state for it to be disabled. 392 * @throws IOException There could be couple types of IOException TableNotFoundException means the 393 * table doesn't exist. TableNotEnabledException means the table isn't in 394 * enabled state. 395 */ 396 default void disableTable(TableName tableName) throws IOException { 397 get(disableTableAsync(tableName), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 398 } 399 400 /** 401 * Check if a table is enabled. 402 * @param tableName name of table to check 403 * @return <code>true</code> if table is on-line 404 * @throws IOException if a remote or network exception occurs 405 */ 406 boolean isTableEnabled(TableName tableName) throws IOException; 407 408 /** 409 * Check if a table is disabled. 410 * @param tableName name of table to check 411 * @return <code>true</code> if table is off-line 412 * @throws IOException if a remote or network exception occurs 413 */ 414 boolean isTableDisabled(TableName tableName) throws IOException; 415 416 /** 417 * Check if a table is available. 418 * @param tableName name of table to check 419 * @return <code>true</code> if all regions of the table are available 420 * @throws IOException if a remote or network exception occurs 421 */ 422 boolean isTableAvailable(TableName tableName) throws IOException; 423 424 /** 425 * Add a column family to an existing table. Synchronous operation. Use 426 * {@link #addColumnFamilyAsync(TableName, ColumnFamilyDescriptor)} instead because it returns a 427 * {@link Future} from which you can learn whether success or failure. 428 * @param tableName name of the table to add column family to 429 * @param columnFamily column family descriptor of column family to be added 430 * @throws IOException if a remote or network exception occurs 431 */ 432 default void addColumnFamily(TableName tableName, ColumnFamilyDescriptor columnFamily) 433 throws IOException { 434 get(addColumnFamilyAsync(tableName, columnFamily), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 435 } 436 437 /** 438 * Add a column family to an existing table. Asynchronous operation. You can use Future.get(long, 439 * TimeUnit) to wait on the operation to complete. It may throw ExecutionException if there was an 440 * error while executing the operation or TimeoutException in case the wait timeout was not long 441 * enough to allow the operation to complete. 442 * @param tableName name of the table to add column family to 443 * @param columnFamily column family descriptor of column family to be added 444 * @throws IOException if a remote or network exception occurs 445 * @return the result of the async add column family. You can use Future.get(long, TimeUnit) to 446 * wait on the operation to complete. 447 */ 448 Future<Void> addColumnFamilyAsync(TableName tableName, ColumnFamilyDescriptor columnFamily) 449 throws IOException; 450 451 /** 452 * Delete a column family from a table. Synchronous operation. Use 453 * {@link #deleteColumnFamily(TableName, byte[])} instead because it returns a {@link Future} from 454 * which you can learn whether success or failure. 455 * @param tableName name of table 456 * @param columnFamily name of column family to be deleted 457 * @throws IOException if a remote or network exception occurs 458 */ 459 default void deleteColumnFamily(TableName tableName, byte[] columnFamily) throws IOException { 460 get(deleteColumnFamilyAsync(tableName, columnFamily), getSyncWaitTimeout(), 461 TimeUnit.MILLISECONDS); 462 } 463 464 /** 465 * Delete a column family from a table. Asynchronous operation. You can use Future.get(long, 466 * TimeUnit) to wait on the operation to complete. It may throw ExecutionException if there was an 467 * error while executing the operation or TimeoutException in case the wait timeout was not long 468 * enough to allow the operation to complete. 469 * @param tableName name of table 470 * @param columnFamily name of column family to be deleted 471 * @throws IOException if a remote or network exception occurs 472 * @return the result of the async delete column family. You can use Future.get(long, TimeUnit) to 473 * wait on the operation to complete. 474 */ 475 Future<Void> deleteColumnFamilyAsync(TableName tableName, byte[] columnFamily) throws IOException; 476 477 /** 478 * Modify an existing column family on a table. Synchronous operation. Use 479 * {@link #modifyColumnFamilyAsync(TableName, ColumnFamilyDescriptor)} instead because it returns 480 * a {@link Future} from which you can learn whether success or failure. 481 * @param tableName name of table 482 * @param columnFamily new column family descriptor to use 483 * @throws IOException if a remote or network exception occurs 484 */ 485 default void modifyColumnFamily(TableName tableName, ColumnFamilyDescriptor columnFamily) 486 throws IOException { 487 get(modifyColumnFamilyAsync(tableName, columnFamily), getSyncWaitTimeout(), 488 TimeUnit.MILLISECONDS); 489 } 490 491 /** 492 * Modify an existing column family on a table. Asynchronous operation. You can use 493 * Future.get(long, TimeUnit) to wait on the operation to complete. It may throw 494 * ExecutionException if there was an error while executing the operation or TimeoutException in 495 * case the wait timeout was not long enough to allow the operation to complete. 496 * @param tableName name of table 497 * @param columnFamily new column family descriptor to use 498 * @throws IOException if a remote or network exception occurs 499 * @return the result of the async modify column family. You can use Future.get(long, TimeUnit) to 500 * wait on the operation to complete. 501 */ 502 Future<Void> modifyColumnFamilyAsync(TableName tableName, ColumnFamilyDescriptor columnFamily) 503 throws IOException; 504 505 /** 506 * Change the store file tracker of the given table's given family. 507 * @param tableName the table you want to change 508 * @param family the family you want to change 509 * @param dstSFT the destination store file tracker 510 * @throws IOException if a remote or network exception occurs 511 */ 512 default void modifyColumnFamilyStoreFileTracker(TableName tableName, byte[] family, String dstSFT) 513 throws IOException { 514 get(modifyColumnFamilyStoreFileTrackerAsync(tableName, family, dstSFT), getSyncWaitTimeout(), 515 TimeUnit.MILLISECONDS); 516 } 517 518 /** 519 * Change the store file tracker of the given table's given family. 520 * @param tableName the table you want to change 521 * @param family the family you want to change 522 * @param dstSFT the destination store file tracker 523 * @return the result of the async modify. You can use Future.get(long, TimeUnit) to wait on the 524 * operation to complete 525 * @throws IOException if a remote or network exception occurs 526 */ 527 Future<Void> modifyColumnFamilyStoreFileTrackerAsync(TableName tableName, byte[] family, 528 String dstSFT) throws IOException; 529 530 /** 531 * Get all the online regions on a region server. 532 * @return List of {@link RegionInfo} 533 * @throws IOException if a remote or network exception occurs 534 */ 535 List<RegionInfo> getRegions(ServerName serverName) throws IOException; 536 537 /** 538 * Flush a table. Synchronous operation. 539 * @param tableName table to flush 540 * @throws IOException if a remote or network exception occurs 541 */ 542 void flush(TableName tableName) throws IOException; 543 544 /** 545 * Flush the specified column family stores on all regions of the passed table. This runs as a 546 * synchronous operation. 547 * @param tableName table to flush 548 * @param columnFamily column family within a table 549 * @throws IOException if a remote or network exception occurs 550 */ 551 void flush(TableName tableName, byte[] columnFamily) throws IOException; 552 553 /** 554 * Flush the specified column family stores on all regions of the passed table. This runs as a 555 * synchronous operation. 556 * @param tableName table to flush 557 * @param columnFamilies column families within a table 558 * @throws IOException if a remote or network exception occurs 559 */ 560 void flush(TableName tableName, List<byte[]> columnFamilies) throws IOException; 561 562 /** 563 * Flush an individual region. Synchronous operation. 564 * @param regionName region to flush 565 * @throws IOException if a remote or network exception occurs 566 */ 567 void flushRegion(byte[] regionName) throws IOException; 568 569 /** 570 * Flush a column family within a region. Synchronous operation. 571 * @param regionName region to flush 572 * @param columnFamily column family within a region 573 * @throws IOException if a remote or network exception occurs 574 */ 575 void flushRegion(byte[] regionName, byte[] columnFamily) throws IOException; 576 577 /** 578 * Flush all regions on the region server. Synchronous operation. 579 * @param serverName the region server name to flush 580 * @throws IOException if a remote or network exception occurs 581 */ 582 void flushRegionServer(ServerName serverName) throws IOException; 583 584 /** 585 * Compact a table. Asynchronous operation in that this method requests that a Compaction run and 586 * then it returns. It does not wait on the completion of Compaction (it can take a while). 587 * @param tableName table to compact 588 * @throws IOException if a remote or network exception occurs 589 */ 590 void compact(TableName tableName) throws IOException; 591 592 /** 593 * Compact an individual region. Asynchronous operation in that this method requests that a 594 * Compaction run and then it returns. It does not wait on the completion of Compaction (it can 595 * take a while). 596 * @param regionName region to compact 597 * @throws IOException if a remote or network exception occurs 598 */ 599 void compactRegion(byte[] regionName) throws IOException; 600 601 /** 602 * Compact a column family within a table. Asynchronous operation in that this method requests 603 * that a Compaction run and then it returns. It does not wait on the completion of Compaction (it 604 * can take a while). 605 * @param tableName table to compact 606 * @param columnFamily column family within a table 607 * @throws IOException if a remote or network exception occurs 608 */ 609 void compact(TableName tableName, byte[] columnFamily) throws IOException; 610 611 /** 612 * Compact a column family within a region. Asynchronous operation in that this method requests 613 * that a Compaction run and then it returns. It does not wait on the completion of Compaction (it 614 * can take a while). 615 * @param regionName region to compact 616 * @param columnFamily column family within a region 617 * @throws IOException if a remote or network exception occurs 618 */ 619 void compactRegion(byte[] regionName, byte[] columnFamily) throws IOException; 620 621 /** 622 * Compact a table. Asynchronous operation in that this method requests that a Compaction run and 623 * then it returns. It does not wait on the completion of Compaction (it can take a while). 624 * @param tableName table to compact 625 * @param compactType {@link org.apache.hadoop.hbase.client.CompactType} 626 * @throws IOException if a remote or network exception occurs 627 */ 628 void compact(TableName tableName, CompactType compactType) 629 throws IOException, InterruptedException; 630 631 /** 632 * Compact a column family within a table. Asynchronous operation in that this method requests 633 * that a Compaction run and then it returns. It does not wait on the completion of Compaction (it 634 * can take a while). 635 * @param tableName table to compact 636 * @param columnFamily column family within a table 637 * @param compactType {@link org.apache.hadoop.hbase.client.CompactType} 638 * @throws IOException if not a mob column family or if a remote or network exception occurs 639 */ 640 void compact(TableName tableName, byte[] columnFamily, CompactType compactType) 641 throws IOException, InterruptedException; 642 643 /** 644 * Major compact a table. Asynchronous operation in that this method requests that a Compaction 645 * run and then it returns. It does not wait on the completion of Compaction (it can take a 646 * while). 647 * @param tableName table to major compact 648 * @throws IOException if a remote or network exception occurs 649 */ 650 void majorCompact(TableName tableName) throws IOException; 651 652 /** 653 * Major compact a table or an individual region. Asynchronous operation in that this method 654 * requests that a Compaction run and then it returns. It does not wait on the completion of 655 * Compaction (it can take a while). 656 * @param regionName region to major compact 657 * @throws IOException if a remote or network exception occurs 658 */ 659 void majorCompactRegion(byte[] regionName) throws IOException; 660 661 /** 662 * Major compact a column family within a table. Asynchronous operation in that this method 663 * requests that a Compaction run and then it returns. It does not wait on the completion of 664 * Compaction (it can take a while). 665 * @param tableName table to major compact 666 * @param columnFamily column family within a table 667 * @throws IOException if a remote or network exception occurs 668 */ 669 void majorCompact(TableName tableName, byte[] columnFamily) throws IOException; 670 671 /** 672 * Major compact a column family within region. Asynchronous operation in that this method 673 * requests that a Compaction run and then it returns. It does not wait on the completion of 674 * Compaction (it can take a while). 675 * @param regionName egion to major compact 676 * @param columnFamily column family within a region 677 * @throws IOException if a remote or network exception occurs 678 */ 679 void majorCompactRegion(byte[] regionName, byte[] columnFamily) throws IOException; 680 681 /** 682 * Major compact a table. Asynchronous operation in that this method requests that a Compaction 683 * run and then it returns. It does not wait on the completion of Compaction (it can take a 684 * while). 685 * @param tableName table to compact 686 * @param compactType {@link org.apache.hadoop.hbase.client.CompactType} 687 * @throws IOException if a remote or network exception occurs 688 */ 689 void majorCompact(TableName tableName, CompactType compactType) 690 throws IOException, InterruptedException; 691 692 /** 693 * Major compact a column family within a table. Asynchronous operation in that this method 694 * requests that a Compaction run and then it returns. It does not wait on the completion of 695 * Compaction (it can take a while). 696 * @param tableName table to compact 697 * @param columnFamily column family within a table 698 * @param compactType {@link org.apache.hadoop.hbase.client.CompactType} 699 * @throws IOException if not a mob column family or if a remote or network exception occurs 700 */ 701 void majorCompact(TableName tableName, byte[] columnFamily, CompactType compactType) 702 throws IOException, InterruptedException; 703 704 /** 705 * Turn the compaction on or off. Disabling compactions will also interrupt any currently ongoing 706 * compactions. This state is ephemeral. The setting will be lost on restart. Compaction can also 707 * be enabled/disabled by modifying configuration hbase.regionserver.compaction.enabled in 708 * hbase-site.xml. 709 * @param switchState Set to <code>true</code> to enable, <code>false</code> to disable. 710 * @param serverNamesList list of region servers. 711 * @return Previous compaction states for region servers 712 * @throws IOException if a remote or network exception occurs 713 */ 714 Map<ServerName, Boolean> compactionSwitch(boolean switchState, List<String> serverNamesList) 715 throws IOException; 716 717 /** 718 * Compact all regions on the region server. Asynchronous operation in that this method requests 719 * that a Compaction run and then it returns. It does not wait on the completion of Compaction (it 720 * can take a while). 721 * @param serverName the region server name 722 * @throws IOException if a remote or network exception occurs 723 */ 724 void compactRegionServer(ServerName serverName) throws IOException; 725 726 /** 727 * Major compact all regions on the region server. Asynchronous operation in that this method 728 * requests that a Compaction run and then it returns. It does not wait on the completion of 729 * Compaction (it can take a while). 730 * @param serverName the region server name 731 * @throws IOException if a remote or network exception occurs 732 */ 733 void majorCompactRegionServer(ServerName serverName) throws IOException; 734 735 /** 736 * Move the region <code>encodedRegionName</code> to a random server. 737 * @param encodedRegionName The encoded region name; i.e. the hash that makes up the region name 738 * suffix: e.g. if regionname is 739 * <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>, 740 * then the encoded region name is: 741 * <code>527db22f95c8a9e0116f0cc13c680396</code>. 742 * @throws IOException if we can't find a region named <code>encodedRegionName</code> 743 */ 744 void move(byte[] encodedRegionName) throws IOException; 745 746 /** 747 * Move the region <code>rencodedRegionName</code> to <code>destServerName</code>. 748 * @param encodedRegionName The encoded region name; i.e. the hash that makes up the region name 749 * suffix: e.g. if regionname is 750 * <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>, 751 * then the encoded region name is: 752 * <code>527db22f95c8a9e0116f0cc13c680396</code>. 753 * @param destServerName The servername of the destination regionserver. If passed the empty 754 * byte array we'll assign to a random server. A server name is made of 755 * host, port and startcode. Here is an example: 756 * <code> host187.example.com,60020,1289493121758</code> 757 * @throws IOException if we can't find a region named <code>encodedRegionName</code> 758 * @deprecated since 2.2.0 and will be removed in 4.0.0. Use {@link #move(byte[], ServerName)} 759 * instead. And if you want to move the region to a random server, please use 760 * {@link #move(byte[])}. 761 * @see <a href="https://issues.apache.org/jira/browse/HBASE-22108">HBASE-22108</a> 762 */ 763 @Deprecated 764 default void move(byte[] encodedRegionName, byte[] destServerName) throws IOException { 765 if (destServerName == null || destServerName.length == 0) { 766 move(encodedRegionName); 767 } else { 768 move(encodedRegionName, ServerName.valueOf(Bytes.toString(destServerName))); 769 } 770 } 771 772 /** 773 * Move the region <code>encodedRegionName</code> to <code>destServerName</code>. 774 * @param encodedRegionName The encoded region name; i.e. the hash that makes up the region name 775 * suffix: e.g. if regionname is 776 * <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>, 777 * then the encoded region name is: 778 * <code>527db22f95c8a9e0116f0cc13c680396</code>. 779 * @param destServerName The servername of the destination regionserver. A server name is made 780 * of host, port and startcode. Here is an example: 781 * <code> host187.example.com,60020,1289493121758</code> 782 * @throws IOException if we can't find a region named <code>encodedRegionName</code> 783 */ 784 void move(byte[] encodedRegionName, ServerName destServerName) throws IOException; 785 786 /** 787 * Assign a Region. 788 * @param regionName Region name to assign. 789 * @throws IOException if a remote or network exception occurs 790 */ 791 void assign(byte[] regionName) throws IOException; 792 793 /** 794 * Unassign a Region. 795 * @param regionName Region name to unassign. 796 * @throws IOException if a remote or network exception occurs 797 */ 798 void unassign(byte[] regionName) throws IOException; 799 800 /** 801 * Unassign a region from current hosting regionserver. Region will then be assigned to a 802 * regionserver chosen at random. Region could be reassigned back to the same server. Use 803 * {@link #move(byte[], ServerName)} if you want to control the region movement. 804 * @param regionName Region to unassign. Will clear any existing RegionPlan if one found. 805 * @param force If <code>true</code>, force unassign (Will remove region from 806 * regions-in-transition too if present. If results in double assignment use 807 * hbck -fix to resolve. To be used by experts). 808 * @throws IOException if a remote or network exception occurs 809 * @deprecated since 2.4.0 and will be removed in 4.0.0. Use {@link #unassign(byte[])} instead. 810 * @see <a href="https://issues.apache.org/jira/browse/HBASE-24875">HBASE-24875</a> 811 */ 812 @Deprecated 813 default void unassign(byte[] regionName, boolean force) throws IOException { 814 unassign(regionName); 815 } 816 817 /** 818 * Offline specified region from master's in-memory state. It will not attempt to reassign the 819 * region as in unassign. This API can be used when a region not served by any region server and 820 * still online as per Master's in memory state. If this API is incorrectly used on active region 821 * then master will loose track of that region. This is a special method that should be used by 822 * experts or hbck. 823 * @param regionName Region to offline. 824 * @throws IOException if a remote or network exception occurs 825 */ 826 void offline(byte[] regionName) throws IOException; 827 828 /** 829 * Turn the load balancer on or off. 830 * @param onOrOff Set to <code>true</code> to enable, <code>false</code> to disable. 831 * @param synchronous If <code>true</code>, it waits until current balance() call, if outstanding, 832 * to return. 833 * @return Previous balancer value 834 * @throws IOException if a remote or network exception occurs 835 */ 836 boolean balancerSwitch(boolean onOrOff, boolean synchronous) throws IOException; 837 838 /** 839 * Invoke the balancer. Will run the balancer and if regions to move, it will go ahead and do the 840 * reassignments. Can NOT run for various reasons. Check logs. 841 * @return <code>true</code> if balancer ran, <code>false</code> otherwise. 842 * @throws IOException if a remote or network exception occurs 843 */ 844 default boolean balance() throws IOException { 845 return balance(BalanceRequest.defaultInstance()).isBalancerRan(); 846 } 847 848 /** 849 * Invoke the balancer with the given balance request. The BalanceRequest defines how the balancer 850 * will run. See {@link BalanceRequest} for more details. 851 * @param request defines how the balancer should run 852 * @return {@link BalanceResponse} with details about the results of the invocation. 853 * @throws IOException if a remote or network exception occurs 854 */ 855 BalanceResponse balance(BalanceRequest request) throws IOException; 856 857 /** 858 * Invoke the balancer. Will run the balancer and if regions to move, it will go ahead and do the 859 * reassignments. If there is region in transition, force parameter of true would still run 860 * balancer. Can *not* run for other reasons. Check logs. 861 * @param force whether we should force balance even if there is region in transition 862 * @return <code>true</code> if balancer ran, <code>false</code> otherwise. 863 * @throws IOException if a remote or network exception occurs 864 * @deprecated Since 2.5.0. Will be removed in 4.0.0. Use {@link #balance(BalanceRequest)} 865 * instead. 866 */ 867 @Deprecated 868 default boolean balance(boolean force) throws IOException { 869 return balance(BalanceRequest.newBuilder().setIgnoreRegionsInTransition(force).build()) 870 .isBalancerRan(); 871 } 872 873 /** 874 * Query the current state of the balancer. 875 * @return <code>true</code> if the balancer is enabled, <code>false</code> otherwise. 876 * @throws IOException if a remote or network exception occurs 877 */ 878 boolean isBalancerEnabled() throws IOException; 879 880 /** 881 * Clear all the blocks corresponding to this table from BlockCache. For expert-admins. Calling 882 * this API will drop all the cached blocks specific to a table from BlockCache. This can 883 * significantly impact the query performance as the subsequent queries will have to retrieve the 884 * blocks from underlying filesystem. 885 * @param tableName table to clear block cache 886 * @return CacheEvictionStats related to the eviction 887 * @throws IOException if a remote or network exception occurs 888 */ 889 CacheEvictionStats clearBlockCache(final TableName tableName) throws IOException; 890 891 /** 892 * Invoke region normalizer. Can NOT run for various reasons. Check logs. This is a non-blocking 893 * invocation to region normalizer. If return value is true, it means the request was submitted 894 * successfully. We need to check logs for the details of which regions were split/merged. 895 * @return {@code true} if region normalizer ran, {@code false} otherwise. 896 * @throws IOException if a remote or network exception occurs 897 */ 898 default boolean normalize() throws IOException { 899 return normalize(new NormalizeTableFilterParams.Builder().build()); 900 } 901 902 /** 903 * Invoke region normalizer. Can NOT run for various reasons. Check logs. This is a non-blocking 904 * invocation to region normalizer. If return value is true, it means the request was submitted 905 * successfully. We need to check logs for the details of which regions were split/merged. 906 * @param ntfp limit to tables matching the specified filter. 907 * @return {@code true} if region normalizer ran, {@code false} otherwise. 908 * @throws IOException if a remote or network exception occurs 909 */ 910 boolean normalize(NormalizeTableFilterParams ntfp) throws IOException; 911 912 /** 913 * Query the current state of the region normalizer. 914 * @return <code>true</code> if region normalizer is enabled, <code>false</code> otherwise. 915 * @throws IOException if a remote or network exception occurs 916 */ 917 boolean isNormalizerEnabled() throws IOException; 918 919 /** 920 * Turn region normalizer on or off. 921 * @return Previous normalizer value 922 * @throws IOException if a remote or network exception occurs 923 */ 924 boolean normalizerSwitch(boolean on) throws IOException; 925 926 /** 927 * Enable/Disable the catalog janitor/ 928 * @param onOrOff if <code>true</code> enables the catalog janitor 929 * @return the previous state 930 * @throws IOException if a remote or network exception occurs 931 */ 932 boolean catalogJanitorSwitch(boolean onOrOff) throws IOException; 933 934 /** 935 * Ask for a scan of the catalog table. 936 * @return the number of entries cleaned. Returns -1 if previous run is in progress. 937 * @throws IOException if a remote or network exception occurs 938 */ 939 int runCatalogJanitor() throws IOException; 940 941 /** 942 * Query on the catalog janitor state (Enabled/Disabled?). 943 * @throws IOException if a remote or network exception occurs 944 */ 945 boolean isCatalogJanitorEnabled() throws IOException; 946 947 /** 948 * Enable/Disable the cleaner chore. 949 * @param onOrOff if <code>true</code> enables the cleaner chore 950 * @return the previous state 951 * @throws IOException if a remote or network exception occurs 952 */ 953 boolean cleanerChoreSwitch(boolean onOrOff) throws IOException; 954 955 /** 956 * Ask for cleaner chore to run. 957 * @return <code>true</code> if cleaner chore ran, <code>false</code> otherwise 958 * @throws IOException if a remote or network exception occurs 959 */ 960 boolean runCleanerChore() throws IOException; 961 962 /** 963 * Query on the cleaner chore state (Enabled/Disabled?). 964 * @throws IOException if a remote or network exception occurs 965 */ 966 boolean isCleanerChoreEnabled() throws IOException; 967 968 /** 969 * Merge two regions. Asynchronous operation. 970 * @param nameOfRegionA encoded or full name of region a 971 * @param nameOfRegionB encoded or full name of region b 972 * @param forcible <code>true</code> if do a compulsory merge, otherwise we will only merge 973 * two adjacent regions 974 * @throws IOException if a remote or network exception occurs 975 * @deprecated since 2.3.0 and will be removed in 4.0.0. Multi-region merge feature is now 976 * supported. Use {@link #mergeRegionsAsync(byte[][], boolean)} instead. 977 */ 978 @Deprecated 979 default Future<Void> mergeRegionsAsync(byte[] nameOfRegionA, byte[] nameOfRegionB, 980 boolean forcible) throws IOException { 981 byte[][] nameofRegionsToMerge = new byte[2][]; 982 nameofRegionsToMerge[0] = nameOfRegionA; 983 nameofRegionsToMerge[1] = nameOfRegionB; 984 return mergeRegionsAsync(nameofRegionsToMerge, forcible); 985 } 986 987 /** 988 * Merge multiple regions (>=2). Asynchronous operation. 989 * @param nameofRegionsToMerge encoded or full name of daughter regions 990 * @param forcible <code>true</code> if do a compulsory merge, otherwise we will only 991 * merge adjacent regions 992 * @throws IOException if a remote or network exception occurs 993 */ 994 Future<Void> mergeRegionsAsync(byte[][] nameofRegionsToMerge, boolean forcible) 995 throws IOException; 996 997 /** 998 * Split a table. The method will execute split action for each region in table. 999 * @param tableName table to split 1000 * @throws IOException if a remote or network exception occurs 1001 */ 1002 void split(TableName tableName) throws IOException; 1003 1004 /** 1005 * Split a table. 1006 * @param tableName table to split 1007 * @param splitPoint the explicit position to split on 1008 * @throws IOException if a remote or network exception occurs 1009 */ 1010 void split(TableName tableName, byte[] splitPoint) throws IOException; 1011 1012 /** 1013 * Split an individual region. Asynchronous operation. 1014 * @param regionName region to split 1015 * @throws IOException if a remote or network exception occurs 1016 */ 1017 Future<Void> splitRegionAsync(byte[] regionName) throws IOException; 1018 1019 /** 1020 * Split an individual region. Asynchronous operation. 1021 * @param regionName region to split 1022 * @param splitPoint the explicit position to split on 1023 * @throws IOException if a remote or network exception occurs 1024 */ 1025 Future<Void> splitRegionAsync(byte[] regionName, byte[] splitPoint) throws IOException; 1026 1027 /** 1028 * Modify an existing table, more IRB friendly version. 1029 * @param td modified description of the table 1030 * @throws IOException if a remote or network exception occurs 1031 */ 1032 default void modifyTable(TableDescriptor td) throws IOException { 1033 get(modifyTableAsync(td), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 1034 } 1035 1036 /** 1037 * Truncate an individual region. 1038 * @param regionName region to truncate 1039 * @throws IOException if a remote or network exception occurs 1040 */ 1041 void truncateRegion(byte[] regionName) throws IOException; 1042 1043 /** 1044 * Truncate an individual region. Asynchronous operation. 1045 * @param regionName region to truncate 1046 * @throws IOException if a remote or network exception occurs 1047 */ 1048 Future<Void> truncateRegionAsync(byte[] regionName) throws IOException; 1049 1050 /** 1051 * Modify an existing table, more IRB (ruby) friendly version. Asynchronous operation. This means 1052 * that it may be a while before your schema change is updated across all of the table. You can 1053 * use Future.get(long, TimeUnit) to wait on the operation to complete. It may throw 1054 * ExecutionException if there was an error while executing the operation or TimeoutException in 1055 * case the wait timeout was not long enough to allow the operation to complete. 1056 * @param td description of the table 1057 * @throws IOException if a remote or network exception occurs 1058 * @return the result of the async modify. You can use Future.get(long, TimeUnit) to wait on the 1059 * operation to complete 1060 */ 1061 default Future<Void> modifyTableAsync(TableDescriptor td) throws IOException { 1062 return modifyTableAsync(td, true); 1063 } 1064 1065 /** 1066 * The same as {@link #modifyTableAsync(TableDescriptor td)}, except for the reopenRegions 1067 * parameter, which controls whether the process of modifying the table should reopen all regions. 1068 * @param td description of the table 1069 * @param reopenRegions By default, 'modifyTable' reopens all regions, potentially causing a RIT 1070 * (Region In Transition) storm in large tables. If set to 'false', regions 1071 * will remain unaware of the modification until they are individually 1072 * reopened. Please note that this may temporarily result in configuration 1073 * inconsistencies among regions. 1074 * @return the result of the async modify. You can use Future.get(long, TimeUnit) to wait on the 1075 * operation to complete 1076 * @throws IOException if a remote or network exception occurs 1077 */ 1078 Future<Void> modifyTableAsync(TableDescriptor td, boolean reopenRegions) throws IOException; 1079 1080 /** 1081 * Reopen all regions of a table. This is useful after calling 1082 * {@link #modifyTableAsync(TableDescriptor, boolean)} with reopenRegions=false to gradually roll 1083 * out table descriptor changes to regions. Regions are reopened in-place (no move). 1084 * @param tableName table whose regions to reopen 1085 * @throws IOException if a remote or network exception occurs 1086 */ 1087 default void reopenTableRegions(TableName tableName) throws IOException { 1088 get(reopenTableRegionsAsync(tableName), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 1089 } 1090 1091 /** 1092 * Reopen specific regions of a table. Useful for canary testing table descriptor changes on a 1093 * subset of regions before rolling out to the entire table. 1094 * @param tableName table whose regions to reopen 1095 * @param regions specific regions to reopen 1096 * @throws IOException if a remote or network exception occurs 1097 */ 1098 default void reopenTableRegions(TableName tableName, List<RegionInfo> regions) 1099 throws IOException { 1100 get(reopenTableRegionsAsync(tableName, regions), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 1101 } 1102 1103 /** 1104 * Asynchronously reopen all regions of a table. 1105 * @param tableName table whose regions to reopen 1106 * @return Future for tracking completion 1107 * @throws IOException if a remote or network exception occurs 1108 */ 1109 Future<Void> reopenTableRegionsAsync(TableName tableName) throws IOException; 1110 1111 /** 1112 * Asynchronously reopen specific regions of a table. 1113 * @param tableName table whose regions to reopen 1114 * @param regions specific regions to reopen 1115 * @return Future for tracking completion 1116 * @throws IOException if a remote or network exception occurs 1117 */ 1118 Future<Void> reopenTableRegionsAsync(TableName tableName, List<RegionInfo> regions) 1119 throws IOException; 1120 1121 /** 1122 * Change the store file tracker of the given table. 1123 * @param tableName the table you want to change 1124 * @param dstSFT the destination store file tracker 1125 * @throws IOException if a remote or network exception occurs 1126 */ 1127 default void modifyTableStoreFileTracker(TableName tableName, String dstSFT) throws IOException { 1128 get(modifyTableStoreFileTrackerAsync(tableName, dstSFT), getSyncWaitTimeout(), 1129 TimeUnit.MILLISECONDS); 1130 } 1131 1132 /** 1133 * Change the store file tracker of the given table. 1134 * @param tableName the table you want to change 1135 * @param dstSFT the destination store file tracker 1136 * @return the result of the async modify. You can use Future.get(long, TimeUnit) to wait on the 1137 * operation to complete 1138 * @throws IOException if a remote or network exception occurs 1139 */ 1140 Future<Void> modifyTableStoreFileTrackerAsync(TableName tableName, String dstSFT) 1141 throws IOException; 1142 1143 /** 1144 * Shuts down the HBase cluster. 1145 * <p/> 1146 * Notice that, a success shutdown call may ends with an error since the remote server has already 1147 * been shutdown. 1148 * @throws IOException if a remote or network exception occurs 1149 */ 1150 void shutdown() throws IOException; 1151 1152 /** 1153 * Shuts down the current HBase master only. Does not shutdown the cluster. 1154 * <p/> 1155 * Notice that, a success stopMaster call may ends with an error since the remote server has 1156 * already been shutdown. 1157 * @throws IOException if a remote or network exception occurs 1158 * @see #shutdown() 1159 */ 1160 void stopMaster() throws IOException; 1161 1162 /** 1163 * Check whether Master is in maintenance mode. 1164 * @throws IOException if a remote or network exception occurs 1165 */ 1166 boolean isMasterInMaintenanceMode() throws IOException; 1167 1168 /** 1169 * Stop the designated regionserver. 1170 * @param hostnamePort Hostname and port delimited by a <code>:</code> as in 1171 * <code>example.org:1234</code> 1172 * @throws IOException if a remote or network exception occurs 1173 */ 1174 void stopRegionServer(String hostnamePort) throws IOException; 1175 1176 /** 1177 * Get whole cluster metrics, containing status about: 1178 * 1179 * <pre> 1180 * hbase version 1181 * cluster id 1182 * primary/backup master(s) 1183 * master's coprocessors 1184 * live/dead regionservers 1185 * balancer 1186 * regions in transition 1187 * </pre> 1188 * 1189 * @return cluster metrics 1190 * @throws IOException if a remote or network exception occurs 1191 */ 1192 default ClusterMetrics getClusterMetrics() throws IOException { 1193 return getClusterMetrics(EnumSet.allOf(ClusterMetrics.Option.class)); 1194 } 1195 1196 /** 1197 * Get cluster status with a set of {@link Option} to get desired status. 1198 * @return cluster status 1199 * @throws IOException if a remote or network exception occurs 1200 */ 1201 ClusterMetrics getClusterMetrics(EnumSet<Option> options) throws IOException; 1202 1203 /** 1204 * Get the current active master. 1205 * @return current master server name 1206 * @throws IOException if a remote or network exception occurs 1207 */ 1208 default ServerName getMaster() throws IOException { 1209 return getClusterMetrics(EnumSet.of(Option.MASTER)).getMasterName(); 1210 } 1211 1212 /** 1213 * Get a list of current backup masters. 1214 * @return current backup master list 1215 * @throws IOException if a remote or network exception occurs 1216 */ 1217 default Collection<ServerName> getBackupMasters() throws IOException { 1218 return getClusterMetrics(EnumSet.of(Option.BACKUP_MASTERS)).getBackupMasterNames(); 1219 } 1220 1221 /** 1222 * Get the live server list. 1223 * @return current live region servers list 1224 * @throws IOException if a remote or network exception occurs 1225 */ 1226 default Collection<ServerName> getRegionServers() throws IOException { 1227 return getRegionServers(false); 1228 } 1229 1230 /** 1231 * Retrieve all current live region servers including decommissioned if excludeDecommissionedRS is 1232 * false, else non-decommissioned ones only 1233 * @param excludeDecommissionedRS should we exclude decommissioned RS nodes 1234 * @return all current live region servers including/excluding decommissioned hosts 1235 * @throws IOException if a remote or network exception occurs 1236 */ 1237 default Collection<ServerName> getRegionServers(boolean excludeDecommissionedRS) 1238 throws IOException { 1239 List<ServerName> allServers = 1240 getClusterMetrics(EnumSet.of(Option.SERVERS_NAME)).getServersName(); 1241 if (!excludeDecommissionedRS) { 1242 return allServers; 1243 } 1244 List<ServerName> decommissionedRegionServers = listDecommissionedRegionServers(); 1245 return allServers.stream().filter(s -> !decommissionedRegionServers.contains(s)) 1246 .collect(ImmutableList.toImmutableList()); 1247 } 1248 1249 /** 1250 * Get {@link RegionMetrics} of all regions hosted on a regionserver. 1251 * @param serverName region server from which {@link RegionMetrics} is required. 1252 * @return a {@link RegionMetrics} list of all regions hosted on a region server 1253 * @throws IOException if a remote or network exception occurs 1254 */ 1255 List<RegionMetrics> getRegionMetrics(ServerName serverName) throws IOException; 1256 1257 /** 1258 * Get {@link RegionMetrics} of all regions hosted on a regionserver for a table. 1259 * @param serverName region server from which {@link RegionMetrics} is required. 1260 * @param tableName get {@link RegionMetrics} of regions belonging to the table 1261 * @return region metrics map of all regions of a table hosted on a region server 1262 * @throws IOException if a remote or network exception occurs 1263 */ 1264 List<RegionMetrics> getRegionMetrics(ServerName serverName, TableName tableName) 1265 throws IOException; 1266 1267 /** Returns Configuration used by the instance. */ 1268 Configuration getConfiguration(); 1269 1270 /** 1271 * Create a new namespace. Blocks until namespace has been successfully created or an exception is 1272 * thrown. 1273 * @param descriptor descriptor which describes the new namespace. 1274 * @throws IOException if a remote or network exception occurs 1275 */ 1276 default void createNamespace(NamespaceDescriptor descriptor) throws IOException { 1277 get(createNamespaceAsync(descriptor), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 1278 } 1279 1280 /** 1281 * Create a new namespace. 1282 * @param descriptor descriptor which describes the new namespace 1283 * @return the result of the async create namespace operation. Use Future.get(long, TimeUnit) to 1284 * wait on the operation to complete. 1285 * @throws IOException if a remote or network exception occurs 1286 */ 1287 Future<Void> createNamespaceAsync(NamespaceDescriptor descriptor) throws IOException; 1288 1289 /** 1290 * Modify an existing namespace. Blocks until namespace has been successfully modified or an 1291 * exception is thrown. 1292 * @param descriptor descriptor which describes the new namespace 1293 * @throws IOException if a remote or network exception occurs 1294 */ 1295 default void modifyNamespace(NamespaceDescriptor descriptor) throws IOException { 1296 get(modifyNamespaceAsync(descriptor), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 1297 } 1298 1299 /** 1300 * Modify an existing namespace. 1301 * @param descriptor descriptor which describes the new namespace 1302 * @return the result of the async modify namespace operation. Use Future.get(long, TimeUnit) to 1303 * wait on the operation to complete. 1304 * @throws IOException if a remote or network exception occurs 1305 */ 1306 Future<Void> modifyNamespaceAsync(NamespaceDescriptor descriptor) throws IOException; 1307 1308 /** 1309 * Delete an existing namespace. Only empty namespaces (no tables) can be removed. Blocks until 1310 * namespace has been successfully deleted or an exception is thrown. 1311 * @param name namespace name 1312 * @throws IOException if a remote or network exception occurs 1313 */ 1314 default void deleteNamespace(String name) throws IOException { 1315 get(deleteNamespaceAsync(name), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 1316 } 1317 1318 /** 1319 * Delete an existing namespace. Only empty namespaces (no tables) can be removed. 1320 * @param name namespace name 1321 * @return the result of the async delete namespace operation. Use Future.get(long, TimeUnit) to 1322 * wait on the operation to complete. 1323 * @throws IOException if a remote or network exception occurs 1324 */ 1325 Future<Void> deleteNamespaceAsync(String name) throws IOException; 1326 1327 /** 1328 * Get a namespace descriptor by name. 1329 * @param name name of namespace descriptor 1330 * @return A descriptor 1331 * @throws org.apache.hadoop.hbase.NamespaceNotFoundException if the namespace was not found 1332 * @throws IOException if a remote or network exception 1333 * occurs 1334 */ 1335 NamespaceDescriptor getNamespaceDescriptor(String name) 1336 throws NamespaceNotFoundException, IOException; 1337 1338 /** 1339 * List available namespaces 1340 * @return List of namespace names 1341 * @throws IOException if a remote or network exception occurs 1342 */ 1343 String[] listNamespaces() throws IOException; 1344 1345 /** 1346 * List available namespace descriptors 1347 * @return List of descriptors 1348 * @throws IOException if a remote or network exception occurs 1349 */ 1350 NamespaceDescriptor[] listNamespaceDescriptors() throws IOException; 1351 1352 /** 1353 * Get list of table descriptors by namespace. 1354 * @param name namespace name 1355 * @return returns a list of TableDescriptors 1356 * @throws IOException if a remote or network exception occurs 1357 */ 1358 List<TableDescriptor> listTableDescriptorsByNamespace(byte[] name) throws IOException; 1359 1360 /** 1361 * Get list of table names by namespace. 1362 * @param name namespace name 1363 * @return The list of table names in the namespace 1364 * @throws IOException if a remote or network exception occurs 1365 */ 1366 TableName[] listTableNamesByNamespace(String name) throws IOException; 1367 1368 /** 1369 * Get the regions of a given table. 1370 * @param tableName the name of the table 1371 * @return List of {@link RegionInfo}. 1372 * @throws IOException if a remote or network exception occurs 1373 */ 1374 List<RegionInfo> getRegions(TableName tableName) throws IOException; 1375 1376 @Override 1377 void close(); 1378 1379 /** 1380 * Get tableDescriptors. 1381 * @param tableNames List of table names 1382 * @return returns a list of TableDescriptors 1383 * @throws IOException if a remote or network exception occurs 1384 */ 1385 List<TableDescriptor> listTableDescriptors(List<TableName> tableNames) throws IOException; 1386 1387 /** 1388 * Abort a procedure. 1389 * <p/> 1390 * Do not use. Usually it is ignored but if not, it can do more damage than good. See hbck2. 1391 * @param procId ID of the procedure to abort 1392 * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted? 1393 * @return <code>true</code> if aborted, <code>false</code> if procedure already completed or does 1394 * not exist 1395 * @throws IOException if a remote or network exception occurs 1396 * @deprecated since 2.1.1 and will be removed in 4.0.0. 1397 * @see <a href="https://issues.apache.org/jira/browse/HBASE-21223">HBASE-21223</a> 1398 */ 1399 @Deprecated 1400 default boolean abortProcedure(long procId, boolean mayInterruptIfRunning) throws IOException { 1401 return get(abortProcedureAsync(procId, mayInterruptIfRunning), getSyncWaitTimeout(), 1402 TimeUnit.MILLISECONDS); 1403 } 1404 1405 /** 1406 * Abort a procedure but does not block and wait for completion. You can use Future.get(long, 1407 * TimeUnit) to wait on the operation to complete. It may throw ExecutionException if there was an 1408 * error while executing the operation or TimeoutException in case the wait timeout was not long 1409 * enough to allow the operation to complete. Do not use. Usually it is ignored but if not, it can 1410 * do more damage than good. See hbck2. 1411 * @param procId ID of the procedure to abort 1412 * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted? 1413 * @return <code>true</code> if aborted, <code>false</code> if procedure already completed or does 1414 * not exist 1415 * @throws IOException if a remote or network exception occurs 1416 * @deprecated since 2.1.1 and will be removed in 4.0.0. 1417 * @see <a href="https://issues.apache.org/jira/browse/HBASE-21223">HBASE-21223</a> 1418 */ 1419 @Deprecated 1420 Future<Boolean> abortProcedureAsync(long procId, boolean mayInterruptIfRunning) 1421 throws IOException; 1422 1423 /** 1424 * Get procedures. 1425 * @return procedure list in JSON 1426 * @throws IOException if a remote or network exception occurs 1427 */ 1428 String getProcedures() throws IOException; 1429 1430 /** 1431 * Get locks. 1432 * @return lock list in JSON 1433 * @throws IOException if a remote or network exception occurs 1434 */ 1435 String getLocks() throws IOException; 1436 1437 /** 1438 * Roll the log writer. I.e. for filesystem based write ahead logs, start writing to a new file. 1439 * Note that the actual rolling of the log writer is asynchronous and may not be complete when 1440 * this method returns. As a side effect of this call, the named region server may schedule store 1441 * flushes at the request of the wal. 1442 * @param serverName The servername of the regionserver. 1443 * @throws IOException if a remote or network exception occurs 1444 * @throws FailedLogCloseException if we failed to close the WAL 1445 */ 1446 void rollWALWriter(ServerName serverName) throws IOException, FailedLogCloseException; 1447 1448 /** 1449 * Roll log writer for all RegionServers. Note that unlike 1450 * {@link Admin#rollWALWriter(ServerName)}, this method is synchronous, which means it will block 1451 * until all RegionServers have completed the log roll, or a RegionServer fails due to an 1452 * exception that retry will not work. 1453 * @return server and the highest wal filenum of server before performing log roll 1454 * @throws IOException if a remote or network exception occurs 1455 */ 1456 Map<ServerName, Long> rollAllWALWriters() throws IOException; 1457 1458 /** 1459 * Helper that delegates to getClusterMetrics().getMasterCoprocessorNames(). 1460 * @return an array of master coprocessors 1461 * @see org.apache.hadoop.hbase.ClusterMetrics#getMasterCoprocessorNames() 1462 */ 1463 default List<String> getMasterCoprocessorNames() throws IOException { 1464 return getClusterMetrics(EnumSet.of(Option.MASTER_COPROCESSORS)).getMasterCoprocessorNames(); 1465 } 1466 1467 /** 1468 * Get the current compaction state of a table. It could be in a major compaction, a minor 1469 * compaction, both, or none. 1470 * @param tableName table to examine 1471 * @return the current compaction state 1472 * @throws IOException if a remote or network exception occurs 1473 */ 1474 CompactionState getCompactionState(TableName tableName) throws IOException; 1475 1476 /** 1477 * Get the current compaction state of a table. It could be in a compaction, or none. 1478 * @param tableName table to examine 1479 * @param compactType {@link org.apache.hadoop.hbase.client.CompactType} 1480 * @return the current compaction state 1481 * @throws IOException if a remote or network exception occurs 1482 */ 1483 CompactionState getCompactionState(TableName tableName, CompactType compactType) 1484 throws IOException; 1485 1486 /** 1487 * Get the current compaction state of region. It could be in a major compaction, a minor 1488 * compaction, both, or none. 1489 * @param regionName region to examine 1490 * @return the current compaction state 1491 * @throws IOException if a remote or network exception occurs 1492 */ 1493 CompactionState getCompactionStateForRegion(byte[] regionName) throws IOException; 1494 1495 /** 1496 * Get the timestamp of the last major compaction for the passed table The timestamp of the oldest 1497 * HFile resulting from a major compaction of that table, or 0 if no such HFile could be found. 1498 * @param tableName table to examine 1499 * @return the last major compaction timestamp or 0 1500 * @throws IOException if a remote or network exception occurs 1501 */ 1502 long getLastMajorCompactionTimestamp(TableName tableName) throws IOException; 1503 1504 /** 1505 * Get the timestamp of the last major compaction for the passed region. The timestamp of the 1506 * oldest HFile resulting from a major compaction of that region, or 0 if no such HFile could be 1507 * found. 1508 * @param regionName region to examine 1509 * @return the last major compaction timestamp or 0 1510 * @throws IOException if a remote or network exception occurs 1511 */ 1512 long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException; 1513 1514 /** 1515 * Take a snapshot for the given table. If the table is enabled, a FLUSH-type snapshot will be 1516 * taken. If the table is disabled, an offline snapshot is taken. Snapshots are taken sequentially 1517 * even when requested concurrently, across all tables. Snapshots are considered unique based on 1518 * <b>the name of the snapshot</b>. Attempts to take a snapshot with the same name (even a 1519 * different type or with different parameters) will fail with a 1520 * {@link org.apache.hadoop.hbase.snapshot.SnapshotCreationException} indicating the duplicate 1521 * naming. Snapshot names follow the same naming constraints as tables in HBase. See 1522 * {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}. 1523 * @param snapshotName name of the snapshot to be created 1524 * @param tableName name of the table for which snapshot is created 1525 * @throws IOException if a remote or network 1526 * exception occurs 1527 * @throws org.apache.hadoop.hbase.snapshot.SnapshotCreationException if snapshot creation failed 1528 * @throws IllegalArgumentException if the snapshot request is 1529 * formatted incorrectly 1530 */ 1531 default void snapshot(String snapshotName, TableName tableName) 1532 throws IOException, SnapshotCreationException, IllegalArgumentException { 1533 snapshot(snapshotName, tableName, SnapshotType.FLUSH); 1534 } 1535 1536 /** 1537 * Create typed snapshot of the table. Snapshots are considered unique based on <b>the name of the 1538 * snapshot</b>. Snapshots are taken sequentially even when requested concurrently, across all 1539 * tables. Attempts to take a snapshot with the same name (even a different type or with different 1540 * parameters) will fail with a {@link SnapshotCreationException} indicating the duplicate naming. 1541 * Snapshot names follow the same naming constraints as tables in HBase. See 1542 * {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}. 1543 * @param snapshotName name to give the snapshot on the filesystem. Must be unique from all other 1544 * snapshots stored on the cluster 1545 * @param tableName name of the table to snapshot 1546 * @param type type of snapshot to take 1547 * @throws IOException we fail to reach the master 1548 * @throws SnapshotCreationException if snapshot creation failed 1549 * @throws IllegalArgumentException if the snapshot request is formatted incorrectly 1550 */ 1551 default void snapshot(String snapshotName, TableName tableName, SnapshotType type) 1552 throws IOException, SnapshotCreationException, IllegalArgumentException { 1553 snapshot(new SnapshotDescription(snapshotName, tableName, type)); 1554 } 1555 1556 /** 1557 * Create typed snapshot of the table. Snapshots are considered unique based on <b>the name of the 1558 * snapshot</b>. Snapshots are taken sequentially even when requested concurrently, across all 1559 * tables. Attempts to take a snapshot with the same name (even a different type or with different 1560 * parameters) will fail with a {@link SnapshotCreationException} indicating the duplicate naming. 1561 * Snapshot names follow the same naming constraints as tables in HBase. See 1562 * {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}. Snapshot can 1563 * live with ttl seconds. 1564 * @param snapshotName name to give the snapshot on the filesystem. Must be unique from all other 1565 * snapshots stored on the cluster 1566 * @param tableName name of the table to snapshot 1567 * @param type type of snapshot to take 1568 * @param snapshotProps snapshot additional properties e.g. TTL 1569 * @throws IOException we fail to reach the master 1570 * @throws SnapshotCreationException if snapshot creation failed 1571 * @throws IllegalArgumentException if the snapshot request is formatted incorrectly 1572 */ 1573 default void snapshot(String snapshotName, TableName tableName, SnapshotType type, 1574 Map<String, Object> snapshotProps) 1575 throws IOException, SnapshotCreationException, IllegalArgumentException { 1576 snapshot(new SnapshotDescription(snapshotName, tableName, type, snapshotProps)); 1577 } 1578 1579 /** 1580 * Create typed snapshot of the table. Snapshots are considered unique based on <b>the name of the 1581 * snapshot</b>. Snapshots are taken sequentially even when requested concurrently, across all 1582 * tables. Attempts to take a snapshot with the same name (even a different type or with different 1583 * parameters) will fail with a {@link SnapshotCreationException} indicating the duplicate naming. 1584 * Snapshot names follow the same naming constraints as tables in HBase. See 1585 * {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}. Snapshot can 1586 * live with ttl seconds. 1587 * @param snapshotName name to give the snapshot on the filesystem. Must be unique from all other 1588 * snapshots stored on the cluster 1589 * @param tableName name of the table to snapshot 1590 * @param snapshotProps snapshot additional properties e.g. TTL 1591 * @throws IOException we fail to reach the master 1592 * @throws SnapshotCreationException if snapshot creation failed 1593 * @throws IllegalArgumentException if the snapshot request is formatted incorrectly 1594 */ 1595 default void snapshot(String snapshotName, TableName tableName, Map<String, Object> snapshotProps) 1596 throws IOException, SnapshotCreationException, IllegalArgumentException { 1597 snapshot(new SnapshotDescription(snapshotName, tableName, SnapshotType.FLUSH, snapshotProps)); 1598 } 1599 1600 /** 1601 * Take a snapshot and wait for the server to complete that snapshot (blocking). Snapshots are 1602 * considered unique based on <b>the name of the snapshot</b>. Snapshots are taken sequentially 1603 * even when requested concurrently, across all tables. Attempts to take a snapshot with the same 1604 * name (even a different type or with different parameters) will fail with a 1605 * {@link SnapshotCreationException} indicating the duplicate naming. Snapshot names follow the 1606 * same naming constraints as tables in HBase. See 1607 * {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}. You should 1608 * probably use {@link #snapshot(String, org.apache.hadoop.hbase.TableName)} unless you are sure 1609 * about the type of snapshot that you want to take. 1610 * @param snapshot snapshot to take 1611 * @throws IOException or we lose contact with the master. 1612 * @throws SnapshotCreationException if snapshot failed to be taken 1613 * @throws IllegalArgumentException if the snapshot request is formatted incorrectly 1614 */ 1615 void snapshot(SnapshotDescription snapshot) 1616 throws IOException, SnapshotCreationException, IllegalArgumentException; 1617 1618 /** 1619 * Take a snapshot without waiting for the server to complete that snapshot (asynchronous). 1620 * Snapshots are considered unique based on <b>the name of the snapshot</b>. Snapshots are taken 1621 * sequentially even when requested concurrently, across all tables. 1622 * @param snapshot snapshot to take 1623 * @throws IOException if the snapshot did not succeed or we lose contact with the 1624 * master. 1625 * @throws SnapshotCreationException if snapshot creation failed 1626 * @throws IllegalArgumentException if the snapshot request is formatted incorrectly 1627 */ 1628 Future<Void> snapshotAsync(SnapshotDescription snapshot) 1629 throws IOException, SnapshotCreationException; 1630 1631 /** 1632 * Check the current state of the passed snapshot. There are three possible states: 1633 * <ol> 1634 * <li>running - returns <tt>false</tt></li> 1635 * <li>finished - returns <tt>true</tt></li> 1636 * <li>finished with error - throws the exception that caused the snapshot to fail</li> 1637 * </ol> 1638 * The cluster only knows about the most recent snapshot. Therefore, if another snapshot has been 1639 * run/started since the snapshot you are checking, you will receive an 1640 * {@link org.apache.hadoop.hbase.snapshot.UnknownSnapshotException}. 1641 * @param snapshot description of the snapshot to check 1642 * @return <tt>true</tt> if the snapshot is completed, <tt>false</tt> if the snapshot is still 1643 * running 1644 * @throws IOException if we have a network issue 1645 * @throws org.apache.hadoop.hbase.snapshot.HBaseSnapshotException if the snapshot failed 1646 * @throws org.apache.hadoop.hbase.snapshot.UnknownSnapshotException if the requested snapshot is 1647 * unknown 1648 */ 1649 boolean isSnapshotFinished(SnapshotDescription snapshot) 1650 throws IOException, HBaseSnapshotException, UnknownSnapshotException; 1651 1652 /** 1653 * Restore the specified snapshot on the original table. (The table must be disabled) If the 1654 * "hbase.snapshot.restore.take.failsafe.snapshot" configuration property is set to 1655 * <code>true</code>, a snapshot of the current table is taken before executing the restore 1656 * operation. In case of restore failure, the failsafe snapshot will be restored. If the restore 1657 * completes without problem the failsafe snapshot is deleted. 1658 * @param snapshotName name of the snapshot to restore 1659 * @throws IOException if a remote or network exception occurs 1660 * @throws RestoreSnapshotException if snapshot failed to be restored 1661 * @throws IllegalArgumentException if the restore request is formatted incorrectly 1662 */ 1663 void restoreSnapshot(String snapshotName) throws IOException, RestoreSnapshotException; 1664 1665 /** 1666 * Restore the specified snapshot on the original table. (The table must be disabled) If 1667 * 'takeFailSafeSnapshot' is set to <code>true</code>, a snapshot of the current table is taken 1668 * before executing the restore operation. In case of restore failure, the failsafe snapshot will 1669 * be restored. If the restore completes without problem the failsafe snapshot is deleted. The 1670 * failsafe snapshot name is configurable by using the property 1671 * "hbase.snapshot.restore.failsafe.name". 1672 * @param snapshotName name of the snapshot to restore 1673 * @param takeFailSafeSnapshot <code>true</code> if the failsafe snapshot should be taken 1674 * @throws IOException if a remote or network exception occurs 1675 * @throws RestoreSnapshotException if snapshot failed to be restored 1676 * @throws IllegalArgumentException if the restore request is formatted incorrectly 1677 */ 1678 default void restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot) 1679 throws IOException, RestoreSnapshotException { 1680 restoreSnapshot(snapshotName, takeFailSafeSnapshot, false); 1681 } 1682 1683 /** 1684 * Restore the specified snapshot on the original table. (The table must be disabled) If 1685 * 'takeFailSafeSnapshot' is set to <code>true</code>, a snapshot of the current table is taken 1686 * before executing the restore operation. In case of restore failure, the failsafe snapshot will 1687 * be restored. If the restore completes without problem the failsafe snapshot is deleted. The 1688 * failsafe snapshot name is configurable by using the property 1689 * "hbase.snapshot.restore.failsafe.name". 1690 * @param snapshotName name of the snapshot to restore 1691 * @param takeFailSafeSnapshot <code>true</code> if the failsafe snapshot should be taken 1692 * @param restoreAcl <code>true</code> to restore acl of snapshot 1693 * @throws IOException if a remote or network exception occurs 1694 * @throws RestoreSnapshotException if snapshot failed to be restored 1695 * @throws IllegalArgumentException if the restore request is formatted incorrectly 1696 */ 1697 void restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot, boolean restoreAcl) 1698 throws IOException, RestoreSnapshotException; 1699 1700 /** 1701 * Create a new table by cloning the snapshot content. 1702 * @param snapshotName name of the snapshot to be cloned 1703 * @param tableName name of the table where the snapshot will be restored 1704 * @throws IOException if a remote or network exception occurs 1705 * @throws TableExistsException if table to be created already exists 1706 * @throws RestoreSnapshotException if snapshot failed to be cloned 1707 * @throws IllegalArgumentException if the specified table has not a valid name 1708 */ 1709 default void cloneSnapshot(String snapshotName, TableName tableName) 1710 throws IOException, TableExistsException, RestoreSnapshotException { 1711 cloneSnapshot(snapshotName, tableName, false, null); 1712 } 1713 1714 /** 1715 * Create a new table by cloning the snapshot content. 1716 * @param snapshotName name of the snapshot to be cloned 1717 * @param tableName name of the table where the snapshot will be restored 1718 * @param restoreAcl <code>true</code> to clone acl into newly created table 1719 * @param customSFT specify the StoreFileTracker used for the table 1720 * @throws IOException if a remote or network exception occurs 1721 * @throws TableExistsException if table to be created already exists 1722 * @throws RestoreSnapshotException if snapshot failed to be cloned 1723 * @throws IllegalArgumentException if the specified table has not a valid name 1724 */ 1725 default void cloneSnapshot(String snapshotName, TableName tableName, boolean restoreAcl, 1726 String customSFT) throws IOException, TableExistsException, RestoreSnapshotException { 1727 get(cloneSnapshotAsync(snapshotName, tableName, restoreAcl, customSFT), getSyncWaitTimeout(), 1728 TimeUnit.MILLISECONDS); 1729 } 1730 1731 /** 1732 * Create a new table by cloning the snapshot content. 1733 * @param snapshotName name of the snapshot to be cloned 1734 * @param tableName name of the table where the snapshot will be restored 1735 * @param restoreAcl <code>true</code> to clone acl into newly created table 1736 * @throws IOException if a remote or network exception occurs 1737 * @throws TableExistsException if table to be created already exists 1738 * @throws RestoreSnapshotException if snapshot failed to be cloned 1739 * @throws IllegalArgumentException if the specified table has not a valid name 1740 */ 1741 default void cloneSnapshot(String snapshotName, TableName tableName, boolean restoreAcl) 1742 throws IOException, TableExistsException, RestoreSnapshotException { 1743 get(cloneSnapshotAsync(snapshotName, tableName, restoreAcl), getSyncWaitTimeout(), 1744 TimeUnit.MILLISECONDS); 1745 } 1746 1747 /** 1748 * Create a new table by cloning the snapshot content, but does not block and wait for it to be 1749 * completely cloned. You can use Future.get(long, TimeUnit) to wait on the operation to complete. 1750 * It may throw ExecutionException if there was an error while executing the operation or 1751 * TimeoutException in case the wait timeout was not long enough to allow the operation to 1752 * complete. 1753 * @param snapshotName name of the snapshot to be cloned 1754 * @param tableName name of the table where the snapshot will be restored 1755 * @throws IOException if a remote or network exception occurs 1756 * @throws TableExistsException if table to be cloned already exists 1757 * @return the result of the async clone snapshot. You can use Future.get(long, TimeUnit) to wait 1758 * on the operation to complete. 1759 */ 1760 default Future<Void> cloneSnapshotAsync(String snapshotName, TableName tableName) 1761 throws IOException, TableExistsException { 1762 return cloneSnapshotAsync(snapshotName, tableName, false); 1763 } 1764 1765 /** 1766 * Create a new table by cloning the snapshot content. 1767 * @param snapshotName name of the snapshot to be cloned 1768 * @param tableName name of the table where the snapshot will be restored 1769 * @param restoreAcl <code>true</code> to clone acl into newly created table 1770 * @throws IOException if a remote or network exception occurs 1771 * @throws TableExistsException if table to be created already exists 1772 * @throws RestoreSnapshotException if snapshot failed to be cloned 1773 * @throws IllegalArgumentException if the specified table has not a valid name 1774 */ 1775 default Future<Void> cloneSnapshotAsync(String snapshotName, TableName tableName, 1776 boolean restoreAcl) throws IOException, TableExistsException, RestoreSnapshotException { 1777 return cloneSnapshotAsync(snapshotName, tableName, restoreAcl, null); 1778 } 1779 1780 /** 1781 * Create a new table by cloning the snapshot content. 1782 * @param snapshotName name of the snapshot to be cloned 1783 * @param tableName name of the table where the snapshot will be restored 1784 * @param restoreAcl <code>true</code> to clone acl into newly created table 1785 * @param customSFT specify the StroreFileTracker used for the table 1786 * @throws IOException if a remote or network exception occurs 1787 * @throws TableExistsException if table to be created already exists 1788 * @throws RestoreSnapshotException if snapshot failed to be cloned 1789 * @throws IllegalArgumentException if the specified table has not a valid name 1790 */ 1791 Future<Void> cloneSnapshotAsync(String snapshotName, TableName tableName, boolean restoreAcl, 1792 String customSFT) throws IOException, TableExistsException, RestoreSnapshotException; 1793 1794 /** 1795 * Execute a distributed procedure on a cluster. 1796 * @param signature A distributed procedure is uniquely identified by its signature (default the 1797 * root ZK node name of the procedure). 1798 * @param instance The instance name of the procedure. For some procedures, this parameter is 1799 * optional. 1800 * @param props Property/Value pairs of properties passing to the procedure 1801 * @throws IOException if a remote or network exception occurs 1802 */ 1803 void execProcedure(String signature, String instance, Map<String, String> props) 1804 throws IOException; 1805 1806 /** 1807 * Execute a distributed procedure on a cluster. 1808 * @param signature A distributed procedure is uniquely identified by its signature (default the 1809 * root ZK node name of the procedure). 1810 * @param instance The instance name of the procedure. For some procedures, this parameter is 1811 * optional. 1812 * @param props Property/Value pairs of properties passing to the procedure 1813 * @return data returned after procedure execution. null if no return data. 1814 * @throws IOException if a remote or network exception occurs 1815 */ 1816 byte[] execProcedureWithReturn(String signature, String instance, Map<String, String> props) 1817 throws IOException; 1818 1819 /** 1820 * Check the current state of the specified procedure. There are three possible states: 1821 * <ol> 1822 * <li>running - returns <tt>false</tt></li> 1823 * <li>finished - returns <tt>true</tt></li> 1824 * <li>finished with error - throws the exception that caused the procedure to fail</li> 1825 * </ol> 1826 * @param signature The signature that uniquely identifies a procedure 1827 * @param instance The instance name of the procedure 1828 * @param props Property/Value pairs of properties passing to the procedure 1829 * @return <code>true</code> if the specified procedure is finished successfully, 1830 * <code>false</code> if it is still running 1831 * @throws IOException if the specified procedure finished with error 1832 */ 1833 boolean isProcedureFinished(String signature, String instance, Map<String, String> props) 1834 throws IOException; 1835 1836 /** 1837 * List completed snapshots. 1838 * @return a list of snapshot descriptors for completed snapshots 1839 * @throws IOException if a network error occurs 1840 */ 1841 List<SnapshotDescription> listSnapshots() throws IOException; 1842 1843 /** 1844 * List all the completed snapshots matching the given pattern. 1845 * @param pattern The compiled regular expression to match against 1846 * @return list of SnapshotDescription 1847 * @throws IOException if a remote or network exception occurs 1848 */ 1849 List<SnapshotDescription> listSnapshots(Pattern pattern) throws IOException; 1850 1851 /** 1852 * List all the completed snapshots matching the given table name regular expression and snapshot 1853 * name regular expression. 1854 * @param tableNamePattern The compiled table name regular expression to match against 1855 * @param snapshotNamePattern The compiled snapshot name regular expression to match against 1856 * @return list of completed SnapshotDescription 1857 * @throws IOException if a remote or network exception occurs 1858 */ 1859 List<SnapshotDescription> listTableSnapshots(Pattern tableNamePattern, 1860 Pattern snapshotNamePattern) throws IOException; 1861 1862 /** 1863 * Delete an existing snapshot. 1864 * @param snapshotName name of the snapshot 1865 * @throws IOException if a remote or network exception occurs 1866 */ 1867 void deleteSnapshot(String snapshotName) throws IOException; 1868 1869 /** 1870 * Delete existing snapshots whose names match the pattern passed. 1871 * @param pattern pattern for names of the snapshot to match 1872 * @throws IOException if a remote or network exception occurs 1873 */ 1874 void deleteSnapshots(Pattern pattern) throws IOException; 1875 1876 /** 1877 * Delete all existing snapshots matching the given table name regular expression and snapshot 1878 * name regular expression. 1879 * @param tableNamePattern The compiled table name regular expression to match against 1880 * @param snapshotNamePattern The compiled snapshot name regular expression to match against 1881 * @throws IOException if a remote or network exception occurs 1882 */ 1883 void deleteTableSnapshots(Pattern tableNamePattern, Pattern snapshotNamePattern) 1884 throws IOException; 1885 1886 /** 1887 * Apply the new quota settings. 1888 * @param quota the quota settings 1889 * @throws IOException if a remote or network exception occurs 1890 */ 1891 void setQuota(QuotaSettings quota) throws IOException; 1892 1893 /** 1894 * List the quotas based on the filter. 1895 * @param filter the quota settings filter 1896 * @return the QuotaSetting list 1897 * @throws IOException if a remote or network exception occurs 1898 */ 1899 List<QuotaSettings> getQuota(QuotaFilter filter) throws IOException; 1900 1901 /** 1902 * Creates and returns a {@link org.apache.hbase.thirdparty.com.google.protobuf.RpcChannel} 1903 * instance connected to the active master. 1904 * <p/> 1905 * The obtained {@link org.apache.hbase.thirdparty.com.google.protobuf.RpcChannel} instance can be 1906 * used to access a published coprocessor 1907 * {@link org.apache.hbase.thirdparty.com.google.protobuf.Service} using standard protobuf service 1908 * invocations: 1909 * <p/> 1910 * <div style="background-color: #cccccc; padding: 2px"> <blockquote> 1911 * 1912 * <pre> 1913 * CoprocessorRpcChannel channel = myAdmin.coprocessorService(); 1914 * MyService.BlockingInterface service = MyService.newBlockingStub(channel); 1915 * MyCallRequest request = MyCallRequest.newBuilder() 1916 * ... 1917 * .build(); 1918 * MyCallResponse response = service.myCall(null, request); 1919 * </pre> 1920 * 1921 * </blockquote> </div> 1922 * @return A MasterCoprocessorRpcChannel instance 1923 * @deprecated since 3.0.0, will removed in 4.0.0. This is too low level, please stop using it any 1924 * more. Use the coprocessorService methods in {@link AsyncAdmin} instead. 1925 */ 1926 @Deprecated 1927 CoprocessorRpcChannel coprocessorService(); 1928 1929 /** 1930 * Creates and returns a {@link org.apache.hbase.thirdparty.com.google.protobuf.RpcChannel} 1931 * instance connected to the passed region server. 1932 * <p/> 1933 * The obtained {@link org.apache.hbase.thirdparty.com.google.protobuf.RpcChannel} instance can be 1934 * used to access a published coprocessor 1935 * {@link org.apache.hbase.thirdparty.com.google.protobuf.Service} using standard protobuf service 1936 * invocations: 1937 * <p/> 1938 * <div style="background-color: #cccccc; padding: 2px"> <blockquote> 1939 * 1940 * <pre> 1941 * CoprocessorRpcChannel channel = myAdmin.coprocessorService(serverName); 1942 * MyService.BlockingInterface service = MyService.newBlockingStub(channel); 1943 * MyCallRequest request = MyCallRequest.newBuilder() 1944 * ... 1945 * .build(); 1946 * MyCallResponse response = service.myCall(null, request); 1947 * </pre> 1948 * 1949 * </blockquote> </div> 1950 * @param serverName the server name to which the endpoint call is made 1951 * @return A RegionServerCoprocessorRpcChannel instance 1952 * @deprecated since 3.0.0, will removed in 4.0.0. This is too low level, please stop using it any 1953 * more. Use the coprocessorService methods in {@link AsyncAdmin} instead. 1954 */ 1955 @Deprecated 1956 CoprocessorRpcChannel coprocessorService(ServerName serverName); 1957 1958 /** 1959 * Update the configuration and trigger an online config change on the regionserver. 1960 * @param server : The server whose config needs to be updated. 1961 * @throws IOException if a remote or network exception occurs 1962 */ 1963 void updateConfiguration(ServerName server) throws IOException; 1964 1965 /** 1966 * Update the configuration and trigger an online config change on all the regionservers. 1967 * @throws IOException if a remote or network exception occurs 1968 */ 1969 void updateConfiguration() throws IOException; 1970 1971 /** 1972 * Update the configuration and trigger an online config change on all the regionservers in the 1973 * RSGroup. 1974 * @param groupName the group name 1975 * @throws IOException if a remote or network exception occurs 1976 */ 1977 void updateConfiguration(String groupName) throws IOException; 1978 1979 /** 1980 * Get the info port of the current master if one is available. 1981 * @return master info port 1982 * @throws IOException if a remote or network exception occurs 1983 */ 1984 default int getMasterInfoPort() throws IOException { 1985 return getClusterMetrics(EnumSet.of(Option.MASTER_INFO_PORT)).getMasterInfoPort(); 1986 } 1987 1988 /** 1989 * Return the set of supported security capabilities. 1990 * @throws IOException if a remote or network exception occurs 1991 */ 1992 List<SecurityCapability> getSecurityCapabilities() throws IOException; 1993 1994 /** 1995 * Turn the split switch on or off. 1996 * @param enabled enabled or not 1997 * @param synchronous If <code>true</code>, it waits until current split() call, if outstanding, 1998 * to return. 1999 * @return Previous switch value 2000 * @throws IOException if a remote or network exception occurs 2001 */ 2002 boolean splitSwitch(boolean enabled, boolean synchronous) throws IOException; 2003 2004 /** 2005 * Turn the merge switch on or off. 2006 * @param enabled enabled or not 2007 * @param synchronous If <code>true</code>, it waits until current merge() call, if outstanding, 2008 * to return. 2009 * @return Previous switch value 2010 * @throws IOException if a remote or network exception occurs 2011 */ 2012 boolean mergeSwitch(boolean enabled, boolean synchronous) throws IOException; 2013 2014 /** 2015 * Query the current state of the split switch. 2016 * @return <code>true</code> if the switch is enabled, <code>false</code> otherwise. 2017 * @throws IOException if a remote or network exception occurs 2018 */ 2019 boolean isSplitEnabled() throws IOException; 2020 2021 /** 2022 * Query the current state of the merge switch. 2023 * @return <code>true</code> if the switch is enabled, <code>false</code> otherwise. 2024 * @throws IOException if a remote or network exception occurs 2025 */ 2026 boolean isMergeEnabled() throws IOException; 2027 2028 /** 2029 * Add a new replication peer for replicating data to slave cluster. 2030 * @param peerId a short name that identifies the peer 2031 * @param peerConfig configuration for the replication peer 2032 * @throws IOException if a remote or network exception occurs 2033 */ 2034 default void addReplicationPeer(String peerId, ReplicationPeerConfig peerConfig) 2035 throws IOException { 2036 addReplicationPeer(peerId, peerConfig, true); 2037 } 2038 2039 /** 2040 * Add a new replication peer for replicating data to slave cluster. 2041 * @param peerId a short name that identifies the peer 2042 * @param peerConfig configuration for the replication peer 2043 * @param enabled peer state, true if ENABLED and false if DISABLED 2044 * @throws IOException if a remote or network exception occurs 2045 */ 2046 default void addReplicationPeer(String peerId, ReplicationPeerConfig peerConfig, boolean enabled) 2047 throws IOException { 2048 get(addReplicationPeerAsync(peerId, peerConfig, enabled), getSyncWaitTimeout(), 2049 TimeUnit.MILLISECONDS); 2050 } 2051 2052 /** 2053 * Add a new replication peer but does not block and wait for it. 2054 * <p/> 2055 * You can use Future.get(long, TimeUnit) to wait on the operation to complete. It may throw 2056 * ExecutionException if there was an error while executing the operation or TimeoutException in 2057 * case the wait timeout was not long enough to allow the operation to complete. 2058 * @param peerId a short name that identifies the peer 2059 * @param peerConfig configuration for the replication peer 2060 * @return the result of the async operation 2061 * @throws IOException IOException if a remote or network exception occurs 2062 */ 2063 default Future<Void> addReplicationPeerAsync(String peerId, ReplicationPeerConfig peerConfig) 2064 throws IOException { 2065 return addReplicationPeerAsync(peerId, peerConfig, true); 2066 } 2067 2068 /** 2069 * Add a new replication peer but does not block and wait for it. 2070 * <p> 2071 * You can use Future.get(long, TimeUnit) to wait on the operation to complete. It may throw 2072 * ExecutionException if there was an error while executing the operation or TimeoutException in 2073 * case the wait timeout was not long enough to allow the operation to complete. 2074 * @param peerId a short name that identifies the peer 2075 * @param peerConfig configuration for the replication peer 2076 * @param enabled peer state, true if ENABLED and false if DISABLED 2077 * @return the result of the async operation 2078 * @throws IOException IOException if a remote or network exception occurs 2079 */ 2080 Future<Void> addReplicationPeerAsync(String peerId, ReplicationPeerConfig peerConfig, 2081 boolean enabled) throws IOException; 2082 2083 /** 2084 * Remove a peer and stop the replication. 2085 * @param peerId a short name that identifies the peer 2086 * @throws IOException if a remote or network exception occurs 2087 */ 2088 default void removeReplicationPeer(String peerId) throws IOException { 2089 get(removeReplicationPeerAsync(peerId), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 2090 } 2091 2092 /** 2093 * Remove a replication peer but does not block and wait for it. 2094 * <p> 2095 * You can use Future.get(long, TimeUnit) to wait on the operation to complete. It may throw 2096 * ExecutionException if there was an error while executing the operation or TimeoutException in 2097 * case the wait timeout was not long enough to allow the operation to complete. 2098 * @param peerId a short name that identifies the peer 2099 * @return the result of the async operation 2100 * @throws IOException IOException if a remote or network exception occurs 2101 */ 2102 Future<Void> removeReplicationPeerAsync(String peerId) throws IOException; 2103 2104 /** 2105 * Restart the replication stream to the specified peer. 2106 * @param peerId a short name that identifies the peer 2107 * @throws IOException if a remote or network exception occurs 2108 */ 2109 default void enableReplicationPeer(String peerId) throws IOException { 2110 get(enableReplicationPeerAsync(peerId), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 2111 } 2112 2113 /** 2114 * Enable a replication peer but does not block and wait for it. 2115 * <p> 2116 * You can use Future.get(long, TimeUnit) to wait on the operation to complete. It may throw 2117 * ExecutionException if there was an error while executing the operation or TimeoutException in 2118 * case the wait timeout was not long enough to allow the operation to complete. 2119 * @param peerId a short name that identifies the peer 2120 * @return the result of the async operation 2121 * @throws IOException IOException if a remote or network exception occurs 2122 */ 2123 Future<Void> enableReplicationPeerAsync(String peerId) throws IOException; 2124 2125 /** 2126 * Stop the replication stream to the specified peer. 2127 * @param peerId a short name that identifies the peer 2128 * @throws IOException if a remote or network exception occurs 2129 */ 2130 default void disableReplicationPeer(String peerId) throws IOException { 2131 get(disableReplicationPeerAsync(peerId), getSyncWaitTimeout(), TimeUnit.MILLISECONDS); 2132 } 2133 2134 /** 2135 * Disable a replication peer but does not block and wait for it. 2136 * <p/> 2137 * You can use Future.get(long, TimeUnit) to wait on the operation to complete. It may throw 2138 * ExecutionException if there was an error while executing the operation or TimeoutException in 2139 * case the wait timeout was not long enough to allow the operation to complete. 2140 * @param peerId a short name that identifies the peer 2141 * @return the result of the async operation 2142 * @throws IOException IOException if a remote or network exception occurs 2143 */ 2144 Future<Void> disableReplicationPeerAsync(String peerId) throws IOException; 2145 2146 /** 2147 * Returns the configured ReplicationPeerConfig for the specified peer. 2148 * @param peerId a short name that identifies the peer 2149 * @return ReplicationPeerConfig for the peer 2150 * @throws IOException if a remote or network exception occurs 2151 */ 2152 ReplicationPeerConfig getReplicationPeerConfig(String peerId) throws IOException; 2153 2154 /** 2155 * Update the peerConfig for the specified peer. 2156 * @param peerId a short name that identifies the peer 2157 * @param peerConfig new config for the replication peer 2158 * @throws IOException if a remote or network exception occurs 2159 */ 2160 default void updateReplicationPeerConfig(String peerId, ReplicationPeerConfig peerConfig) 2161 throws IOException { 2162 get(updateReplicationPeerConfigAsync(peerId, peerConfig), getSyncWaitTimeout(), 2163 TimeUnit.MILLISECONDS); 2164 } 2165 2166 /** 2167 * Update the peerConfig for the specified peer but does not block and wait for it. 2168 * <p/> 2169 * You can use Future.get(long, TimeUnit) to wait on the operation to complete. It may throw 2170 * ExecutionException if there was an error while executing the operation or TimeoutException in 2171 * case the wait timeout was not long enough to allow the operation to complete. 2172 * @param peerId a short name that identifies the peer 2173 * @param peerConfig new config for the replication peer 2174 * @return the result of the async operation 2175 * @throws IOException IOException if a remote or network exception occurs 2176 */ 2177 Future<Void> updateReplicationPeerConfigAsync(String peerId, ReplicationPeerConfig peerConfig) 2178 throws IOException; 2179 2180 /** 2181 * Append the replicable table column family config from the specified peer. 2182 * @param id a short that identifies the cluster 2183 * @param tableCfs A map from tableName to column family names 2184 * @throws ReplicationException if tableCfs has conflict with existing config 2185 * @throws IOException if a remote or network exception occurs 2186 */ 2187 default void appendReplicationPeerTableCFs(String id, Map<TableName, List<String>> tableCfs) 2188 throws ReplicationException, IOException { 2189 if (tableCfs == null) { 2190 throw new ReplicationException("tableCfs is null"); 2191 } 2192 ReplicationPeerConfig peerConfig = getReplicationPeerConfig(id); 2193 ReplicationPeerConfig newPeerConfig = 2194 ReplicationPeerConfigUtil.appendTableCFsToReplicationPeerConfig(tableCfs, peerConfig); 2195 updateReplicationPeerConfig(id, newPeerConfig); 2196 } 2197 2198 /** 2199 * Remove some table-cfs from config of the specified peer. 2200 * @param id a short name that identifies the cluster 2201 * @param tableCfs A map from tableName to column family names 2202 * @throws ReplicationException if tableCfs has conflict with existing config 2203 * @throws IOException if a remote or network exception occurs 2204 */ 2205 default void removeReplicationPeerTableCFs(String id, Map<TableName, List<String>> tableCfs) 2206 throws ReplicationException, IOException { 2207 if (tableCfs == null) { 2208 throw new ReplicationException("tableCfs is null"); 2209 } 2210 ReplicationPeerConfig peerConfig = getReplicationPeerConfig(id); 2211 ReplicationPeerConfig newPeerConfig = 2212 ReplicationPeerConfigUtil.removeTableCFsFromReplicationPeerConfig(tableCfs, peerConfig, id); 2213 updateReplicationPeerConfig(id, newPeerConfig); 2214 } 2215 2216 /** 2217 * Return a list of replication peers. 2218 * @return a list of replication peers description 2219 * @throws IOException if a remote or network exception occurs 2220 */ 2221 List<ReplicationPeerDescription> listReplicationPeers() throws IOException; 2222 2223 /** 2224 * Return a list of replication peers. 2225 * @param pattern The compiled regular expression to match peer id 2226 * @return a list of replication peers description 2227 * @throws IOException if a remote or network exception occurs 2228 */ 2229 List<ReplicationPeerDescription> listReplicationPeers(Pattern pattern) throws IOException; 2230 2231 /** 2232 * Transit current cluster to a new state in a synchronous replication peer. 2233 * @param peerId a short name that identifies the peer 2234 * @param state a new state of current cluster 2235 * @throws IOException if a remote or network exception occurs 2236 */ 2237 default void transitReplicationPeerSyncReplicationState(String peerId, SyncReplicationState state) 2238 throws IOException { 2239 get(transitReplicationPeerSyncReplicationStateAsync(peerId, state), getSyncWaitTimeout(), 2240 TimeUnit.MILLISECONDS); 2241 } 2242 2243 /** 2244 * Transit current cluster to a new state in a synchronous replication peer. But does not block 2245 * and wait for it. 2246 * <p> 2247 * You can use Future.get(long, TimeUnit) to wait on the operation to complete. It may throw 2248 * ExecutionException if there was an error while executing the operation or TimeoutException in 2249 * case the wait timeout was not long enough to allow the operation to complete. 2250 * @param peerId a short name that identifies the peer 2251 * @param state a new state of current cluster 2252 * @throws IOException if a remote or network exception occurs 2253 */ 2254 Future<Void> transitReplicationPeerSyncReplicationStateAsync(String peerId, 2255 SyncReplicationState state) throws IOException; 2256 2257 /** 2258 * Get the current cluster state in a synchronous replication peer. 2259 * @param peerId a short name that identifies the peer 2260 * @return the current cluster state 2261 * @throws IOException if a remote or network exception occurs 2262 */ 2263 default SyncReplicationState getReplicationPeerSyncReplicationState(String peerId) 2264 throws IOException { 2265 List<ReplicationPeerDescription> peers = listReplicationPeers(Pattern.compile(peerId)); 2266 if (peers.isEmpty() || !peers.get(0).getPeerId().equals(peerId)) { 2267 throw new IOException("Replication peer " + peerId + " does not exist"); 2268 } 2269 return peers.get(0).getSyncReplicationState(); 2270 } 2271 2272 /** 2273 * Check if a replication peer is enabled. 2274 * @param peerId id of replication peer to check 2275 * @return <code>true</code> if replication peer is enabled 2276 * @throws IOException if a remote or network exception occurs 2277 */ 2278 boolean isReplicationPeerEnabled(String peerId) throws IOException; 2279 2280 /** 2281 * Enable or disable replication peer modification. 2282 * <p/> 2283 * This is especially useful when you want to change the replication peer storage. 2284 * @param on {@code true} means enable, otherwise disable 2285 * @return the previous enable/disable state 2286 */ 2287 default boolean replicationPeerModificationSwitch(boolean on) throws IOException { 2288 return replicationPeerModificationSwitch(on, false); 2289 } 2290 2291 /** 2292 * Enable or disable replication peer modification. 2293 * <p/> 2294 * This is especially useful when you want to change the replication peer storage. 2295 * @param on {@code true} means enable, otherwise disable 2296 * @param drainProcedures if {@code true}, will wait until all the running replication peer 2297 * modification procedures finish 2298 * @return the previous enable/disable state 2299 */ 2300 boolean replicationPeerModificationSwitch(boolean on, boolean drainProcedures) throws IOException; 2301 2302 /** 2303 * Check whether replication peer modification is enabled. 2304 * @return {@code true} if modification is enabled, otherwise {@code false} 2305 */ 2306 boolean isReplicationPeerModificationEnabled() throws IOException; 2307 2308 /** 2309 * Mark region server(s) as decommissioned to prevent additional regions from getting assigned to 2310 * them. Optionally unload the regions on the servers. If there are multiple servers to be 2311 * decommissioned, decommissioning them at the same time can prevent wasteful region movements. 2312 * Region unloading is asynchronous. 2313 * @param servers The list of servers to decommission. 2314 * @param offload True to offload the regions from the decommissioned servers 2315 * @throws IOException if a remote or network exception occurs 2316 */ 2317 void decommissionRegionServers(List<ServerName> servers, boolean offload) throws IOException; 2318 2319 /** 2320 * List region servers marked as decommissioned, which can not be assigned regions. 2321 * @return List of decommissioned region servers. 2322 * @throws IOException if a remote or network exception occurs 2323 */ 2324 List<ServerName> listDecommissionedRegionServers() throws IOException; 2325 2326 /** 2327 * Remove decommission marker from a region server to allow regions assignments. Load regions onto 2328 * the server if a list of regions is given. Region loading is asynchronous. 2329 * @param server The server to recommission. 2330 * @param encodedRegionNames Regions to load onto the server. 2331 * @throws IOException if a remote or network exception occurs 2332 */ 2333 void recommissionRegionServer(ServerName server, List<byte[]> encodedRegionNames) 2334 throws IOException; 2335 2336 /** 2337 * Find all table and column families that are replicated from this cluster 2338 * @return the replicated table-cfs list of this cluster. 2339 * @throws IOException if a remote or network exception occurs 2340 */ 2341 List<TableCFs> listReplicatedTableCFs() throws IOException; 2342 2343 /** 2344 * Enable a table's replication switch. 2345 * @param tableName name of the table 2346 * @throws IOException if a remote or network exception occurs 2347 */ 2348 void enableTableReplication(TableName tableName) throws IOException; 2349 2350 /** 2351 * Disable a table's replication switch. 2352 * @param tableName name of the table 2353 * @throws IOException if a remote or network exception occurs 2354 */ 2355 void disableTableReplication(TableName tableName) throws IOException; 2356 2357 /** 2358 * Clear compacting queues on a regionserver. 2359 * @param serverName the region server name 2360 * @param queues the set of queue name 2361 * @throws IOException if a remote or network exception occurs 2362 */ 2363 void clearCompactionQueues(ServerName serverName, Set<String> queues) 2364 throws IOException, InterruptedException; 2365 2366 /** 2367 * List dead region servers. 2368 * @return List of dead region servers. 2369 */ 2370 default List<ServerName> listDeadServers() throws IOException { 2371 return getClusterMetrics(EnumSet.of(Option.DEAD_SERVERS)).getDeadServerNames(); 2372 } 2373 2374 /** 2375 * List unknown region servers. 2376 * @return List of unknown region servers. 2377 */ 2378 default List<ServerName> listUnknownServers() throws IOException { 2379 return getClusterMetrics(EnumSet.of(Option.UNKNOWN_SERVERS)).getUnknownServerNames(); 2380 } 2381 2382 /** 2383 * Clear dead region servers from master. 2384 * @param servers list of dead region servers. 2385 * @throws IOException if a remote or network exception occurs 2386 * @return List of servers that are not cleared 2387 */ 2388 List<ServerName> clearDeadServers(List<ServerName> servers) throws IOException; 2389 2390 /** 2391 * Create a new table by cloning the existent table schema. 2392 * @param tableName name of the table to be cloned 2393 * @param newTableName name of the new table where the table will be created 2394 * @param preserveSplits True if the splits should be preserved 2395 * @throws IOException if a remote or network exception occurs 2396 */ 2397 void cloneTableSchema(TableName tableName, TableName newTableName, boolean preserveSplits) 2398 throws IOException; 2399 2400 /** 2401 * Switch the rpc throttle enable state. 2402 * @param enable Set to <code>true</code> to enable, <code>false</code> to disable. 2403 * @return Previous rpc throttle enabled value 2404 * @throws IOException if a remote or network exception occurs 2405 */ 2406 boolean switchRpcThrottle(boolean enable) throws IOException; 2407 2408 /** 2409 * Get if the rpc throttle is enabled. 2410 * @return True if rpc throttle is enabled 2411 * @throws IOException if a remote or network exception occurs 2412 */ 2413 boolean isRpcThrottleEnabled() throws IOException; 2414 2415 /** 2416 * Switch the exceed throttle quota. If enabled, user/table/namespace throttle quota can be 2417 * exceeded if region server has availble quota. 2418 * @param enable Set to <code>true</code> to enable, <code>false</code> to disable. 2419 * @return Previous exceed throttle enabled value 2420 * @throws IOException if a remote or network exception occurs 2421 */ 2422 boolean exceedThrottleQuotaSwitch(final boolean enable) throws IOException; 2423 2424 /** 2425 * Fetches the table sizes on the filesystem as tracked by the HBase Master. 2426 * @throws IOException if a remote or network exception occurs 2427 */ 2428 Map<TableName, Long> getSpaceQuotaTableSizes() throws IOException; 2429 2430 /** 2431 * Fetches the observed {@link SpaceQuotaSnapshotView}s observed by a RegionServer. 2432 * @throws IOException if a remote or network exception occurs 2433 */ 2434 Map<TableName, ? extends SpaceQuotaSnapshotView> 2435 getRegionServerSpaceQuotaSnapshots(ServerName serverName) throws IOException; 2436 2437 /** 2438 * Returns the Master's view of a quota on the given {@code namespace} or null if the Master has 2439 * no quota information on that namespace. 2440 * @throws IOException if a remote or network exception occurs 2441 */ 2442 SpaceQuotaSnapshotView getCurrentSpaceQuotaSnapshot(String namespace) throws IOException; 2443 2444 /** 2445 * Returns the Master's view of a quota on the given {@code tableName} or null if the Master has 2446 * no quota information on that table. 2447 * @throws IOException if a remote or network exception occurs 2448 */ 2449 SpaceQuotaSnapshotView getCurrentSpaceQuotaSnapshot(TableName tableName) throws IOException; 2450 2451 /** 2452 * Grants user specific permissions 2453 * @param userPermission user name and the specific permission 2454 * @param mergeExistingPermissions If set to false, later granted permissions will override 2455 * previous granted permissions. otherwise, it'll merge with 2456 * previous granted permissions. 2457 * @throws IOException if a remote or network exception occurs 2458 */ 2459 void grant(UserPermission userPermission, boolean mergeExistingPermissions) throws IOException; 2460 2461 /** 2462 * Revokes user specific permissions 2463 * @param userPermission user name and the specific permission 2464 * @throws IOException if a remote or network exception occurs 2465 */ 2466 void revoke(UserPermission userPermission) throws IOException; 2467 2468 /** 2469 * Get the global/namespace/table permissions for user 2470 * @param getUserPermissionsRequest A request contains which user, global, namespace or table 2471 * permissions needed 2472 * @return The user and permission list 2473 * @throws IOException if a remote or network exception occurs 2474 */ 2475 List<UserPermission> getUserPermissions(GetUserPermissionsRequest getUserPermissionsRequest) 2476 throws IOException; 2477 2478 /** 2479 * Check if the user has specific permissions 2480 * @param userName the user name 2481 * @param permissions the specific permission list 2482 * @return True if user has the specific permissions 2483 * @throws IOException if a remote or network exception occurs 2484 */ 2485 List<Boolean> hasUserPermissions(String userName, List<Permission> permissions) 2486 throws IOException; 2487 2488 /** 2489 * Check if call user has specific permissions 2490 * @param permissions the specific permission list 2491 * @return True if user has the specific permissions 2492 * @throws IOException if a remote or network exception occurs 2493 */ 2494 default List<Boolean> hasUserPermissions(List<Permission> permissions) throws IOException { 2495 return hasUserPermissions(null, permissions); 2496 } 2497 2498 /** 2499 * Turn on or off the auto snapshot cleanup based on TTL. 2500 * @param on Set to <code>true</code> to enable, <code>false</code> to disable. 2501 * @param synchronous If <code>true</code>, it waits until current snapshot cleanup is completed, 2502 * if outstanding. 2503 * @return Previous auto snapshot cleanup value 2504 * @throws IOException if a remote or network exception occurs 2505 */ 2506 boolean snapshotCleanupSwitch(final boolean on, final boolean synchronous) throws IOException; 2507 2508 /** 2509 * Query the current state of the auto snapshot cleanup based on TTL. 2510 * @return <code>true</code> if the auto snapshot cleanup is enabled, <code>false</code> 2511 * otherwise. 2512 * @throws IOException if a remote or network exception occurs 2513 */ 2514 boolean isSnapshotCleanupEnabled() throws IOException; 2515 2516 /** 2517 * Retrieves online slow/large RPC logs from the provided list of RegionServers 2518 * @param serverNames Server names to get slowlog responses from 2519 * @param logQueryFilter filter to be used if provided (determines slow / large RPC logs) 2520 * @return online slowlog response list 2521 * @throws IOException if a remote or network exception occurs 2522 * @deprecated since 2.4.0 and will be removed in 4.0.0. Use 2523 * {@link #getLogEntries(Set, String, ServerType, int, Map)} instead. 2524 */ 2525 @Deprecated 2526 default List<OnlineLogRecord> getSlowLogResponses(final Set<ServerName> serverNames, 2527 final LogQueryFilter logQueryFilter) throws IOException { 2528 String logType; 2529 if (LogQueryFilter.Type.LARGE_LOG.equals(logQueryFilter.getType())) { 2530 logType = "LARGE_LOG"; 2531 } else { 2532 logType = "SLOW_LOG"; 2533 } 2534 Map<String, Object> filterParams = new HashMap<>(); 2535 filterParams.put("regionName", logQueryFilter.getRegionName()); 2536 filterParams.put("clientAddress", logQueryFilter.getClientAddress()); 2537 filterParams.put("tableName", logQueryFilter.getTableName()); 2538 filterParams.put("userName", logQueryFilter.getUserName()); 2539 filterParams.put("filterByOperator", logQueryFilter.getFilterByOperator().toString()); 2540 List<LogEntry> logEntries = getLogEntries(serverNames, logType, ServerType.REGION_SERVER, 2541 logQueryFilter.getLimit(), filterParams); 2542 return logEntries.stream().map(logEntry -> (OnlineLogRecord) logEntry) 2543 .collect(Collectors.toList()); 2544 } 2545 2546 /** 2547 * Clears online slow/large RPC logs from the provided list of RegionServers 2548 * @param serverNames Set of Server names to clean slowlog responses from 2549 * @return List of booleans representing if online slowlog response buffer is cleaned from each 2550 * RegionServer 2551 * @throws IOException if a remote or network exception occurs 2552 */ 2553 List<Boolean> clearSlowLogResponses(final Set<ServerName> serverNames) throws IOException; 2554 2555 /** 2556 * Creates a new RegionServer group with the given name 2557 * @param groupName the name of the group 2558 * @throws IOException if a remote or network exception occurs 2559 */ 2560 void addRSGroup(String groupName) throws IOException; 2561 2562 /** 2563 * Get group info for the given group name 2564 * @param groupName the group name 2565 * @return group info 2566 * @throws IOException if a remote or network exception occurs 2567 */ 2568 RSGroupInfo getRSGroup(String groupName) throws IOException; 2569 2570 /** 2571 * Get group info for the given hostPort 2572 * @param hostPort HostPort to get RSGroupInfo for 2573 * @throws IOException if a remote or network exception occurs 2574 */ 2575 RSGroupInfo getRSGroup(Address hostPort) throws IOException; 2576 2577 /** 2578 * Get group info for the given table 2579 * @param tableName table name to get RSGroupInfo for 2580 * @throws IOException if a remote or network exception occurs 2581 */ 2582 RSGroupInfo getRSGroup(TableName tableName) throws IOException; 2583 2584 /** 2585 * Lists current set of RegionServer groups 2586 * @throws IOException if a remote or network exception occurs 2587 */ 2588 List<RSGroupInfo> listRSGroups() throws IOException; 2589 2590 /** 2591 * Get all tables in this RegionServer group. 2592 * @param groupName the group name 2593 * @throws IOException if a remote or network exception occurs 2594 * @see #getConfiguredNamespacesAndTablesInRSGroup(String) 2595 */ 2596 List<TableName> listTablesInRSGroup(String groupName) throws IOException; 2597 2598 /** 2599 * Get the namespaces and tables which have this RegionServer group in descriptor. 2600 * <p/> 2601 * The difference between this method and {@link #listTablesInRSGroup(String)} is that, this 2602 * method will not include the table which is actually in this RegionServr group but without the 2603 * RegionServer group configuration in its {@link TableDescriptor}. For example, we have a group 2604 * 'A', and we make namespace 'nsA' in this group, then all the tables under this namespace will 2605 * in the group 'A', but this method will not return these tables but only the namespace 'nsA', 2606 * while the {@link #listTablesInRSGroup(String)} will return all these tables. 2607 * @param groupName the group name 2608 * @throws IOException if a remote or network exception occurs 2609 * @see #listTablesInRSGroup(String) 2610 */ 2611 Pair<List<String>, List<TableName>> getConfiguredNamespacesAndTablesInRSGroup(String groupName) 2612 throws IOException; 2613 2614 /** 2615 * Remove RegionServer group associated with the given name 2616 * @param groupName the group name 2617 * @throws IOException if a remote or network exception occurs 2618 */ 2619 void removeRSGroup(String groupName) throws IOException; 2620 2621 /** 2622 * Remove decommissioned servers from group 1. Sometimes we may find the server aborted due to 2623 * some hardware failure and we must offline the server for repairing. Or we need to move some 2624 * servers to join other clusters. So we need to remove these servers from the group. 2. 2625 * Dead/recovering/live servers will be disallowed. 2626 * @param servers set of servers to remove 2627 * @throws IOException if a remote or network exception occurs 2628 */ 2629 void removeServersFromRSGroup(Set<Address> servers) throws IOException; 2630 2631 /** 2632 * Move given set of servers to the specified target RegionServer group 2633 * @param servers set of servers to move 2634 * @param targetGroup the group to move servers to 2635 * @throws IOException if a remote or network exception occurs 2636 */ 2637 void moveServersToRSGroup(Set<Address> servers, String targetGroup) throws IOException; 2638 2639 /** 2640 * Set the RegionServer group for tables 2641 * @param tables tables to set group for 2642 * @param groupName group name for tables 2643 * @throws IOException if a remote or network exception occurs 2644 */ 2645 void setRSGroup(Set<TableName> tables, String groupName) throws IOException; 2646 2647 /** 2648 * Balance regions in the given RegionServer group 2649 * @param groupName the group name 2650 * @return BalanceResponse details about the balancer run 2651 * @throws IOException if a remote or network exception occurs 2652 */ 2653 default BalanceResponse balanceRSGroup(String groupName) throws IOException { 2654 return balanceRSGroup(groupName, BalanceRequest.defaultInstance()); 2655 } 2656 2657 /** 2658 * Balance regions in the given RegionServer group, running based on the given 2659 * {@link BalanceRequest}. 2660 * @return BalanceResponse details about the balancer run 2661 */ 2662 BalanceResponse balanceRSGroup(String groupName, BalanceRequest request) throws IOException; 2663 2664 /** 2665 * Rename rsgroup 2666 * @param oldName old rsgroup name 2667 * @param newName new rsgroup name 2668 * @throws IOException if a remote or network exception occurs 2669 */ 2670 void renameRSGroup(String oldName, String newName) throws IOException; 2671 2672 /** 2673 * Update RSGroup configuration 2674 * @param groupName the group name 2675 * @param configuration new configuration of the group name to be set 2676 * @throws IOException if a remote or network exception occurs 2677 */ 2678 void updateRSGroupConfig(String groupName, Map<String, String> configuration) throws IOException; 2679 2680 /** 2681 * Retrieve recent online records from HMaster / RegionServers. Examples include slow/large RPC 2682 * logs, balancer decisions by master. 2683 * @param serverNames servers to retrieve records from, useful in case of records maintained by 2684 * RegionServer as we can select specific server. In case of 2685 * servertype=MASTER, logs will only come from the currently active master. 2686 * @param logType string representing type of log records 2687 * @param serverType enum for server type: HMaster or RegionServer 2688 * @param limit put a limit to list of records that server should send in response 2689 * @param filterParams additional filter params 2690 * @return Log entries representing online records from servers 2691 * @throws IOException if a remote or network exception occurs 2692 */ 2693 List<LogEntry> getLogEntries(Set<ServerName> serverNames, String logType, ServerType serverType, 2694 int limit, Map<String, Object> filterParams) throws IOException; 2695 2696 /** 2697 * Flush master local region 2698 */ 2699 void flushMasterStore() throws IOException; 2700 2701 /** 2702 * Get the list of cached files 2703 */ 2704 List<String> getCachedFilesList(ServerName serverName) throws IOException; 2705 2706 @InterfaceAudience.Private 2707 void restoreBackupSystemTable(String snapshotName) throws IOException; 2708}