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