Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DB42C200D12 for ; Sat, 7 Oct 2017 17:13:34 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D9D56160BE5; Sat, 7 Oct 2017 15:13:34 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D4E2D160BE4 for ; Sat, 7 Oct 2017 17:13:28 +0200 (CEST) Received: (qmail 91169 invoked by uid 500); 7 Oct 2017 15:13:27 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 90704 invoked by uid 99); 7 Oct 2017 15:13:27 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Oct 2017 15:13:27 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 57033F5D10; Sat, 7 Oct 2017 15:13:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: git-site-role@apache.org To: commits@hbase.apache.org Date: Sat, 07 Oct 2017 15:13:37 -0000 Message-Id: <097eba87191745d991c5da6707d2061c@git.apache.org> In-Reply-To: <1bfeb7927c49420383fabb50735a5ca8@git.apache.org> References: <1bfeb7927c49420383fabb50735a5ca8@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [12/42] hbase-site git commit: Published site at . archived-at: Sat, 07 Oct 2017 15:13:35 -0000 http://git-wip-us.apache.org/repos/asf/hbase-site/blob/578c06e9/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.TableFuture.TableWaitForStateCallable.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.TableFuture.TableWaitForStateCallable.html b/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.TableFuture.TableWaitForStateCallable.html index bc7604f..82cc8d9 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.TableFuture.TableWaitForStateCallable.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.TableFuture.TableWaitForStateCallable.html @@ -327,4081 +327,4071 @@ 319 } 320 321 @Override -322 public List<TableDescriptor> listTableDescriptors(String regex) throws IOException { -323 return listTableDescriptors(Pattern.compile(regex), false); -324 } -325 -326 @Override -327 public List<TableDescriptor> listTableDescriptors(Pattern pattern, boolean includeSysTables) throws IOException { -328 return executeCallable(new MasterCallable<List<TableDescriptor>>(getConnection(), -329 getRpcControllerFactory()) { -330 @Override -331 protected List<TableDescriptor> rpcCall() throws Exception { -332 GetTableDescriptorsRequest req = -333 RequestConverter.buildGetTableDescriptorsRequest(pattern, includeSysTables); -334 return ProtobufUtil.toTableDescriptorList(master.getTableDescriptors(getRpcController(), -335 req)); -336 } -337 }); -338 } -339 -340 @Override -341 public List<TableDescriptor> listTableDescriptors(String regex, boolean includeSysTables) throws IOException { -342 return listTableDescriptors(Pattern.compile(regex), includeSysTables); -343 } -344 -345 @Override -346 public TableDescriptor getDescriptor(TableName tableName) throws TableNotFoundException, IOException { -347 return getTableDescriptor(tableName, getConnection(), rpcCallerFactory, rpcControllerFactory, -348 operationTimeout, rpcTimeout); -349 } -350 -351 @Override -352 public void modifyTable(TableDescriptor td) throws IOException { -353 get(modifyTableAsync(td), syncWaitTimeout, TimeUnit.MILLISECONDS); -354 } -355 -356 @Override -357 public Future<Void> modifyTableAsync(TableDescriptor td) throws IOException { -358 ModifyTableResponse response = executeCallable( -359 new MasterCallable<ModifyTableResponse>(getConnection(), getRpcControllerFactory()) { -360 @Override -361 protected ModifyTableResponse rpcCall() throws Exception { -362 setPriority(td.getTableName()); -363 ModifyTableRequest request = RequestConverter.buildModifyTableRequest( -364 td.getTableName(), td, ng.getNonceGroup(), ng.newNonce()); -365 return master.modifyTable(getRpcController(), request); -366 } -367 }); -368 return new ModifyTableFuture(this, td.getTableName(), response); -369 } -370 -371 @Override -372 public List<TableDescriptor> listTableDescriptorsByNamespace(byte[] name) throws IOException { -373 return executeCallable(new MasterCallable<List<TableDescriptor>>(getConnection(), -374 getRpcControllerFactory()) { -375 @Override -376 protected List<TableDescriptor> rpcCall() throws Exception { -377 return master.listTableDescriptorsByNamespace(getRpcController(), -378 ListTableDescriptorsByNamespaceRequest.newBuilder() -379 .setNamespaceName(Bytes.toString(name)).build()) -380 .getTableSchemaList() -381 .stream() -382 .map(ProtobufUtil::toTableDescriptor) -383 .collect(Collectors.toList()); -384 } -385 }); -386 } -387 -388 @Override -389 public List<TableDescriptor> listTableDescriptors(List<TableName> tableNames) throws IOException { -390 return executeCallable(new MasterCallable<List<TableDescriptor>>(getConnection(), -391 getRpcControllerFactory()) { -392 @Override -393 protected List<TableDescriptor> rpcCall() throws Exception { -394 GetTableDescriptorsRequest req = -395 RequestConverter.buildGetTableDescriptorsRequest(tableNames); -396 return ProtobufUtil.toTableDescriptorList(master.getTableDescriptors(getRpcController(), req)); -397 } -398 }); -399 } -400 -401 @Override -402 public List<RegionInfo> getRegions(final ServerName sn) throws IOException { -403 AdminService.BlockingInterface admin = this.connection.getAdmin(sn); -404 // TODO: There is no timeout on this controller. Set one! -405 HBaseRpcController controller = rpcControllerFactory.newController(); -406 return ProtobufUtil.getOnlineRegions(controller, admin); -407 } -408 -409 @Override -410 public List<RegionInfo> getRegions(final TableName tableName) throws IOException { -411 ZooKeeperWatcher zookeeper = -412 new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), -413 new ThrowableAbortable()); -414 try { -415 if (TableName.META_TABLE_NAME.equals(tableName)) { -416 return new MetaTableLocator().getMetaRegions(zookeeper); -417 } else { -418 return MetaTableAccessor.getTableRegions(connection, tableName, true); -419 } -420 } finally { -421 zookeeper.close(); -422 } -423 } -424 -425 private static class AbortProcedureFuture extends ProcedureFuture<Boolean> { -426 private boolean isAbortInProgress; -427 -428 public AbortProcedureFuture( -429 final HBaseAdmin admin, -430 final Long procId, -431 final Boolean abortProcResponse) { -432 super(admin, procId); -433 this.isAbortInProgress = abortProcResponse; +322 public List<TableDescriptor> listTableDescriptors(Pattern pattern, boolean includeSysTables) throws IOException { +323 return executeCallable(new MasterCallable<List<TableDescriptor>>(getConnection(), +324 getRpcControllerFactory()) { +325 @Override +326 protected List<TableDescriptor> rpcCall() throws Exception { +327 GetTableDescriptorsRequest req = +328 RequestConverter.buildGetTableDescriptorsRequest(pattern, includeSysTables); +329 return ProtobufUtil.toTableDescriptorList(master.getTableDescriptors(getRpcController(), +330 req)); +331 } +332 }); +333 } +334 +335 @Override +336 public TableDescriptor getDescriptor(TableName tableName) throws TableNotFoundException, IOException { +337 return getTableDescriptor(tableName, getConnection(), rpcCallerFactory, rpcControllerFactory, +338 operationTimeout, rpcTimeout); +339 } +340 +341 @Override +342 public void modifyTable(TableDescriptor td) throws IOException { +343 get(modifyTableAsync(td), syncWaitTimeout, TimeUnit.MILLISECONDS); +344 } +345 +346 @Override +347 public Future<Void> modifyTableAsync(TableDescriptor td) throws IOException { +348 ModifyTableResponse response = executeCallable( +349 new MasterCallable<ModifyTableResponse>(getConnection(), getRpcControllerFactory()) { +350 @Override +351 protected ModifyTableResponse rpcCall() throws Exception { +352 setPriority(td.getTableName()); +353 ModifyTableRequest request = RequestConverter.buildModifyTableRequest( +354 td.getTableName(), td, ng.getNonceGroup(), ng.newNonce()); +355 return master.modifyTable(getRpcController(), request); +356 } +357 }); +358 return new ModifyTableFuture(this, td.getTableName(), response); +359 } +360 +361 @Override +362 public List<TableDescriptor> listTableDescriptorsByNamespace(byte[] name) throws IOException { +363 return executeCallable(new MasterCallable<List<TableDescriptor>>(getConnection(), +364 getRpcControllerFactory()) { +365 @Override +366 protected List<TableDescriptor> rpcCall() throws Exception { +367 return master.listTableDescriptorsByNamespace(getRpcController(), +368 ListTableDescriptorsByNamespaceRequest.newBuilder() +369 .setNamespaceName(Bytes.toString(name)).build()) +370 .getTableSchemaList() +371 .stream() +372 .map(ProtobufUtil::toTableDescriptor) +373 .collect(Collectors.toList()); +374 } +375 }); +376 } +377 +378 @Override +379 public List<TableDescriptor> listTableDescriptors(List<TableName> tableNames) throws IOException { +380 return executeCallable(new MasterCallable<List<TableDescriptor>>(getConnection(), +381 getRpcControllerFactory()) { +382 @Override +383 protected List<TableDescriptor> rpcCall() throws Exception { +384 GetTableDescriptorsRequest req = +385 RequestConverter.buildGetTableDescriptorsRequest(tableNames); +386 return ProtobufUtil.toTableDescriptorList(master.getTableDescriptors(getRpcController(), req)); +387 } +388 }); +389 } +390 +391 @Override +392 public List<RegionInfo> getRegions(final ServerName sn) throws IOException { +393 AdminService.BlockingInterface admin = this.connection.getAdmin(sn); +394 // TODO: There is no timeout on this controller. Set one! +395 HBaseRpcController controller = rpcControllerFactory.newController(); +396 return ProtobufUtil.getOnlineRegions(controller, admin); +397 } +398 +399 @Override +400 public List<RegionInfo> getRegions(final TableName tableName) throws IOException { +401 ZooKeeperWatcher zookeeper = +402 new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), +403 new ThrowableAbortable()); +404 try { +405 if (TableName.META_TABLE_NAME.equals(tableName)) { +406 return new MetaTableLocator().getMetaRegions(zookeeper); +407 } else { +408 return MetaTableAccessor.getTableRegions(connection, tableName, true); +409 } +410 } finally { +411 zookeeper.close(); +412 } +413 } +414 +415 private static class AbortProcedureFuture extends ProcedureFuture<Boolean> { +416 private boolean isAbortInProgress; +417 +418 public AbortProcedureFuture( +419 final HBaseAdmin admin, +420 final Long procId, +421 final Boolean abortProcResponse) { +422 super(admin, procId); +423 this.isAbortInProgress = abortProcResponse; +424 } +425 +426 @Override +427 public Boolean get(long timeout, TimeUnit unit) +428 throws InterruptedException, ExecutionException, TimeoutException { +429 if (!this.isAbortInProgress) { +430 return false; +431 } +432 super.get(timeout, unit); +433 return true; 434 } -435 -436 @Override -437 public Boolean get(long timeout, TimeUnit unit) -438 throws InterruptedException, ExecutionException, TimeoutException { -439 if (!this.isAbortInProgress) { -440 return false; -441 } -442 super.get(timeout, unit); -443 return true; -444 } -445 } -446 -447 /** @return Connection used by this object. */ -448 @Override -449 public Connection getConnection() { -450 return connection; +435 } +436 +437 /** @return Connection used by this object. */ +438 @Override +439 public Connection getConnection() { +440 return connection; +441 } +442 +443 @Override +444 public boolean tableExists(final TableName tableName) throws IOException { +445 return executeCallable(new RpcRetryingCallable<Boolean>() { +446 @Override +447 protected Boolean rpcCall(int callTimeout) throws Exception { +448 return MetaTableAccessor.tableExists(connection, tableName); +449 } +450 }); 451 } 452 453 @Override -454 public boolean tableExists(final TableName tableName) throws IOException { -455 return executeCallable(new RpcRetryingCallable<Boolean>() { -456 @Override -457 protected Boolean rpcCall(int callTimeout) throws Exception { -458 return MetaTableAccessor.tableExists(connection, tableName); -459 } -460 }); +454 public HTableDescriptor[] listTables() throws IOException { +455 return listTables((Pattern)null, false); +456 } +457 +458 @Override +459 public HTableDescriptor[] listTables(Pattern pattern) throws IOException { +460 return listTables(pattern, false); 461 } 462 463 @Override -464 public HTableDescriptor[] listTables() throws IOException { -465 return listTables((Pattern)null, false); +464 public HTableDescriptor[] listTables(String regex) throws IOException { +465 return listTables(Pattern.compile(regex), false); 466 } 467 468 @Override -469 public HTableDescriptor[] listTables(Pattern pattern) throws IOException { -470 return listTables(pattern, false); -471 } -472 -473 @Override -474 public HTableDescriptor[] listTables(String regex) throws IOException { -475 return listTables(Pattern.compile(regex), false); -476 } -477 -478 @Override -479 public HTableDescriptor[] listTables(final Pattern pattern, final boolean includeSysTables) -480 throws IOException { -481 return executeCallable(new MasterCallable<HTableDescriptor[]>(getConnection(), -482 getRpcControllerFactory()) { -483 @Override -484 protected HTableDescriptor[] rpcCall() throws Exception { -485 GetTableDescriptorsRequest req = -486 RequestConverter.buildGetTableDescriptorsRequest(pattern, includeSysTables); -487 return ProtobufUtil.toTableDescriptorList(master.getTableDescriptors(getRpcController(), -488 req)).stream().map(ImmutableHTableDescriptor::new).toArray(HTableDescriptor[]::new); -489 } -490 }); -491 } -492 -493 @Override -494 public HTableDescriptor[] listTables(String regex, boolean includeSysTables) -495 throws IOException { -496 return listTables(Pattern.compile(regex), includeSysTables); +469 public HTableDescriptor[] listTables(final Pattern pattern, final boolean includeSysTables) +470 throws IOException { +471 return executeCallable(new MasterCallable<HTableDescriptor[]>(getConnection(), +472 getRpcControllerFactory()) { +473 @Override +474 protected HTableDescriptor[] rpcCall() throws Exception { +475 GetTableDescriptorsRequest req = +476 RequestConverter.buildGetTableDescriptorsRequest(pattern, includeSysTables); +477 return ProtobufUtil.toTableDescriptorList(master.getTableDescriptors(getRpcController(), +478 req)).stream().map(ImmutableHTableDescriptor::new).toArray(HTableDescriptor[]::new); +479 } +480 }); +481 } +482 +483 @Override +484 public HTableDescriptor[] listTables(String regex, boolean includeSysTables) +485 throws IOException { +486 return listTables(Pattern.compile(regex), includeSysTables); +487 } +488 +489 @Override +490 public TableName[] listTableNames() throws IOException { +491 return listTableNames((Pattern)null, false); +492 } +493 +494 @Override +495 public TableName[] listTableNames(Pattern pattern) throws IOException { +496 return listTableNames(pattern, false); 497 } 498 499 @Override -500 public TableName[] listTableNames() throws IOException { -501 return listTableNames((Pattern)null, false); +500 public TableName[] listTableNames(String regex) throws IOException { +501 return listTableNames(Pattern.compile(regex), false); 502 } 503 504 @Override -505 public TableName[] listTableNames(Pattern pattern) throws IOException { -506 return listTableNames(pattern, false); -507 } -508 -509 @Override -510 public TableName[] listTableNames(String regex) throws IOException { -511 return listTableNames(Pattern.compile(regex), false); -512 } -513 -514 @Override -515 public TableName[] listTableNames(final Pattern pattern, final boolean includeSysTables) -516 throws IOException { -517 return executeCallable(new MasterCallable<TableName[]>(getConnection(), -518 getRpcControllerFactory()) { -519 @Override -520 protected TableName[] rpcCall() throws Exception { -521 GetTableNamesRequest req = -522 RequestConverter.buildGetTableNamesRequest(pattern, includeSysTables); -523 return ProtobufUtil.getTableNameArray(master.getTableNames(getRpcController(), req) -524 .getTableNamesList()); -525 } -526 }); -527 } -528 -529 @Override -530 public TableName[] listTableNames(final String regex, final boolean includeSysTables) -531 throws IOException { -532 return listTableNames(Pattern.compile(regex), includeSysTables); -533 } -534 -535 @Override -536 public HTableDescriptor getTableDescriptor(final TableName tableName) throws IOException { -537 return getHTableDescriptor(tableName, getConnection(), rpcCallerFactory, rpcControllerFactory, -538 operationTimeout, rpcTimeout); -539 } -540 -541 static TableDescriptor getTableDescriptor(final TableName tableName, Connection connection, -542 RpcRetryingCallerFactory rpcCallerFactory, final RpcControllerFactory rpcControllerFactory, -543 int operationTimeout, int rpcTimeout) throws IOException { -544 if (tableName == null) return null; -545 TableDescriptor td = -546 executeCallable(new MasterCallable<TableDescriptor>(connection, rpcControllerFactory) { -547 @Override -548 protected TableDescriptor rpcCall() throws Exception { -549 GetTableDescriptorsRequest req = -550 RequestConverter.buildGetTableDescriptorsRequest(tableName); -551 GetTableDescriptorsResponse htds = master.getTableDescriptors(getRpcController(), req); -552 if (!htds.getTableSchemaList().isEmpty()) { -553 return ProtobufUtil.toTableDescriptor(htds.getTableSchemaList().get(0)); -554 } -555 return null; -556 } -557 }, rpcCallerFactory, operationTimeout, rpcTimeout); -558 if (td != null) { -559 return td; -560 } -561 throw new TableNotFoundException(tableName.getNameAsString()); -562 } -563 -564 /** -565 * @deprecated since 2.0 version and will be removed in 3.0 version. -566 * use {@link #getTableDescriptor(TableName, -567 * Connection, RpcRetryingCallerFactory,RpcControllerFactory,int,int)} -568 */ -569 @Deprecated -570 static HTableDescriptor getHTableDescriptor(final TableName tableName, Connection connection, -571 RpcRetryingCallerFactory rpcCallerFactory, final RpcControllerFactory rpcControllerFactory, -572 int operationTimeout, int rpcTimeout) throws IOException { -573 if (tableName == null) return null; -574 HTableDescriptor htd = -575 executeCallable(new MasterCallable<HTableDescriptor>(connection, rpcControllerFactory) { -576 @Override -577 protected HTableDescriptor rpcCall() throws Exception { -578 GetTableDescriptorsRequest req = -579 RequestConverter.buildGetTableDescriptorsRequest(tableName); -580 GetTableDescriptorsResponse htds = master.getTableDescriptors(getRpcController(), req); -581 if (!htds.getTableSchemaList().isEmpty()) { -582 return new ImmutableHTableDescriptor(ProtobufUtil.toTableDescriptor(htds.getTableSchemaList().get(0))); -583 } -584 return null; -585 } -586 }, rpcCallerFactory, operationTimeout, rpcTimeout); -587 if (htd != null) { -588 return new ImmutableHTableDescriptor(htd); -589 } -590 throw new TableNotFoundException(tableName.getNameAsString()); -591 } -592 -593 private long getPauseTime(int tries) { -594 int triesCount = tries; -595 if (triesCount >= HConstants.RETRY_BACKOFF.length) { -596 triesCount = HConstants.RETRY_BACKOFF.length - 1; -597 } -598 return this.pause * HConstants.RETRY_BACKOFF[triesCount]; -599 } -600 -601 @Override -602 public void createTable(TableDescriptor desc) -603 throws IOException { -604 createTable(desc, null); -605 } -606 -607 @Override -608 public void createTable(TableDescriptor desc, byte [] startKey, -609 byte [] endKey, int numRegions) -610 throws IOException { -611 if(numRegions < 3) { -612 throw new IllegalArgumentException("Must create at least three regions"); -613 } else if(Bytes.compareTo(startKey, endKey) >= 0) { -614 throw new IllegalArgumentException("Start key must be smaller than end key"); -615 } -616 if (numRegions == 3) { -617 createTable(desc, new byte[][]{startKey, endKey}); -618 return; -619 } -620 byte [][] splitKeys = Bytes.split(startKey, endKey, numRegions - 3); -621 if(splitKeys == null || splitKeys.length != numRegions - 1) { -622 throw new IllegalArgumentException("Unable to split key range into enough regions"); -623 } -624 createTable(desc, splitKeys); -625 } -626 -627 @Override -628 public void createTable(final TableDescriptor desc, byte [][] splitKeys) -629 throws IOException { -630 get(createTableAsync(desc, splitKeys), syncWaitTimeout, TimeUnit.MILLISECONDS); -631 } -632 -633 @Override -634 public Future<Void> createTableAsync(final TableDescriptor desc, final byte[][] splitKeys) -635 throws IOException { -636 if (desc.getTableName() == null) { -637 throw new IllegalArgumentException("TableName cannot be null"); -638 } -639 if (splitKeys != null && splitKeys.length > 0) { -640 Arrays.sort(splitKeys, Bytes.BYTES_COMPARATOR); -641 // Verify there are no duplicate split keys -642 byte[] lastKey = null; -643 for (byte[] splitKey : splitKeys) { -644 if (Bytes.compareTo(splitKey, HConstants.EMPTY_BYTE_ARRAY) == 0) { -645 throw new IllegalArgumentException( -646 "Empty split key must not be passed in the split keys."); -647 } -648 if (lastKey != null && Bytes.equals(splitKey, lastKey)) { -649 throw new IllegalArgumentException("All split keys must be unique, " + -650 "found duplicate: " + Bytes.toStringBinary(splitKey) + -651 ", " + Bytes.toStringBinary(lastKey)); -652 } -653 lastKey = splitKey; -654 } -655 } -656 -657 CreateTableResponse response = executeCallable( -658 new MasterCallable<CreateTableResponse>(getConnection(), getRpcControllerFactory()) { -659 @Override -660 protected CreateTableResponse rpcCall() throws Exception { -661 setPriority(desc.getTableName()); -662 CreateTableRequest request = RequestConverter.buildCreateTableRequest( -663 desc, splitKeys, ng.getNonceGroup(), ng.newNonce()); -664 return master.createTable(getRpcController(), request); -665 } -666 }); -667 return new CreateTableFuture(this, desc, splitKeys, response); -668 } -669 -670 private static class CreateTableFuture extends TableFuture<Void> { -671 private final TableDescriptor desc; -672 private final byte[][] splitKeys; -673 -674 public CreateTableFuture(final HBaseAdmin admin, final TableDescriptor desc, -675 final byte[][] splitKeys, final CreateTableResponse response) { -676 super(admin, desc.getTableName(), -677 (response != null && response.hasProcId()) ? response.getProcId() : null); -678 this.splitKeys = splitKeys; -679 this.desc = desc; +505 public TableName[] listTableNames(final Pattern pattern, final boolean includeSysTables) +506 throws IOException { +507 return executeCallable(new MasterCallable<TableName[]>(getConnection(), +508 getRpcControllerFactory()) { +509 @Override +510 protected TableName[] rpcCall() throws Exception { +511 GetTableNamesRequest req = +512 RequestConverter.buildGetTableNamesRequest(pattern, includeSysTables); +513 return ProtobufUtil.getTableNameArray(master.getTableNames(getRpcController(), req) +514 .getTableNamesList()); +515 } +516 }); +517 } +518 +519 @Override +520 public TableName[] listTableNames(final String regex, final boolean includeSysTables) +521 throws IOException { +522 return listTableNames(Pattern.compile(regex), includeSysTables); +523 } +524 +525 @Override +526 public HTableDescriptor getTableDescriptor(final TableName tableName) throws IOException { +527 return getHTableDescriptor(tableName, getConnection(), rpcCallerFactory, rpcControllerFactory, +528 operationTimeout, rpcTimeout); +529 } +530 +531 static TableDescriptor getTableDescriptor(final TableName tableName, Connection connection, +532 RpcRetryingCallerFactory rpcCallerFactory, final RpcControllerFactory rpcControllerFactory, +533 int operationTimeout, int rpcTimeout) throws IOException { +534 if (tableName == null) return null; +535 TableDescriptor td = +536 executeCallable(new MasterCallable<TableDescriptor>(connection, rpcControllerFactory) { +537 @Override +538 protected TableDescriptor rpcCall() throws Exception { +539 GetTableDescriptorsRequest req = +540 RequestConverter.buildGetTableDescriptorsRequest(tableName); +541 GetTableDescriptorsResponse htds = master.getTableDescriptors(getRpcController(), req); +542 if (!htds.getTableSchemaList().isEmpty()) { +543 return ProtobufUtil.toTableDescriptor(htds.getTableSchemaList().get(0)); +544 } +545 return null; +546 } +547 }, rpcCallerFactory, operationTimeout, rpcTimeout); +548 if (td != null) { +549 return td; +550 } +551 throw new TableNotFoundException(tableName.getNameAsString()); +552 } +553 +554 /** +555 * @deprecated since 2.0 version and will be removed in 3.0 version. +556 * use {@link #getTableDescriptor(TableName, +557 * Connection, RpcRetryingCallerFactory,RpcControllerFactory,int,int)} +558 */ +559 @Deprecated +560 static HTableDescriptor getHTableDescriptor(final TableName tableName, Connection connection, +561 RpcRetryingCallerFactory rpcCallerFactory, final RpcControllerFactory rpcControllerFactory, +562 int operationTimeout, int rpcTimeout) throws IOException { +563 if (tableName == null) return null; +564 HTableDescriptor htd = +565 executeCallable(new MasterCallable<HTableDescriptor>(connection, rpcControllerFactory) { +566 @Override +567 protected HTableDescriptor rpcCall() throws Exception { +568 GetTableDescriptorsRequest req = +569 RequestConverter.buildGetTableDescriptorsRequest(tableName); +570 GetTableDescriptorsResponse htds = master.getTableDescriptors(getRpcController(), req); +571 if (!htds.getTableSchemaList().isEmpty()) { +572 return new ImmutableHTableDescriptor(ProtobufUtil.toTableDescriptor(htds.getTableSchemaList().get(0))); +573 } +574 return null; +575 } +576 }, rpcCallerFactory, operationTimeout, rpcTimeout); +577 if (htd != null) { +578 return new ImmutableHTableDescriptor(htd); +579 } +580 throw new TableNotFoundException(tableName.getNameAsString()); +581 } +582 +583 private long getPauseTime(int tries) { +584 int triesCount = tries; +585 if (triesCount >= HConstants.RETRY_BACKOFF.length) { +586 triesCount = HConstants.RETRY_BACKOFF.length - 1; +587 } +588 return this.pause * HConstants.RETRY_BACKOFF[triesCount]; +589 } +590 +591 @Override +592 public void createTable(TableDescriptor desc) +593 throws IOException { +594 createTable(desc, null); +595 } +596 +597 @Override +598 public void createTable(TableDescriptor desc, byte [] startKey, +599 byte [] endKey, int numRegions) +600 throws IOException { +601 if(numRegions < 3) { +602 throw new IllegalArgumentException("Must create at least three regions"); +603 } else if(Bytes.compareTo(startKey, endKey) >= 0) { +604 throw new IllegalArgumentException("Start key must be smaller than end key"); +605 } +606 if (numRegions == 3) { +607 createTable(desc, new byte[][]{startKey, endKey}); +608 return; +609 } +610 byte [][] splitKeys = Bytes.split(startKey, endKey, numRegions - 3); +611 if(splitKeys == null || splitKeys.length != numRegions - 1) { +612 throw new IllegalArgumentException("Unable to split key range into enough regions"); +613 } +614 createTable(desc, splitKeys); +615 } +616 +617 @Override +618 public void createTable(final TableDescriptor desc, byte [][] splitKeys) +619 throws IOException { +620 get(createTableAsync(desc, splitKeys), syncWaitTimeout, TimeUnit.MILLISECONDS); +621 } +622 +623 @Override +624 public Future<Void> createTableAsync(final TableDescriptor desc, final byte[][] splitKeys) +625 throws IOException { +626 if (desc.getTableName() == null) { +627 throw new IllegalArgumentException("TableName cannot be null"); +628 } +629 if (splitKeys != null && splitKeys.length > 0) { +630 Arrays.sort(splitKeys, Bytes.BYTES_COMPARATOR); +631 // Verify there are no duplicate split keys +632 byte[] lastKey = null; +633 for (byte[] splitKey : splitKeys) { +634 if (Bytes.compareTo(splitKey, HConstants.EMPTY_BYTE_ARRAY) == 0) { +635 throw new IllegalArgumentException( +636 "Empty split key must not be passed in the split keys."); +637 } +638 if (lastKey != null && Bytes.equals(splitKey, lastKey)) { +639 throw new IllegalArgumentException("All split keys must be unique, " + +640 "found duplicate: " + Bytes.toStringBinary(splitKey) + +641 ", " + Bytes.toStringBinary(lastKey)); +642 } +643 lastKey = splitKey; +644 } +645 } +646 +647 CreateTableResponse response = executeCallable( +648 new MasterCallable<CreateTableResponse>(getConnection(), getRpcControllerFactory()) { +649 @Override +650 protected CreateTableResponse rpcCall() throws Exception { +651 setPriority(desc.getTableName()); +652 CreateTableRequest request = RequestConverter.buildCreateTableRequest( +653 desc, splitKeys, ng.getNonceGroup(), ng.newNonce()); +654 return master.createTable(getRpcController(), request); +655 } +656 }); +657 return new CreateTableFuture(this, desc, splitKeys, response); +658 } +659 +660 private static class CreateTableFuture extends TableFuture<Void> { +661 private final TableDescriptor desc; +662 private final byte[][] splitKeys; +663 +664 public CreateTableFuture(final HBaseAdmin admin, final TableDescriptor desc, +665 final byte[][] splitKeys, final CreateTableResponse response) { +666 super(admin, desc.getTableName(), +667 (response != null && response.hasProcId()) ? response.getProcId() : null); +668 this.splitKeys = splitKeys; +669 this.desc = desc; +670 } +671 +672 @Override +673 protected TableDescriptor getTableDescriptor() { +674 return desc; +675 } +676 +677 @Override +678 public String getOperationType() { +679 return "CREATE"; 680 } 681 682 @Override -683 protected TableDescriptor getTableDescriptor() { -684 return desc; -685 } -686 -687 @Override -688 public String getOperationType() { -689 return "CREATE"; -690 } -691 -692 @Override -693 protected Void waitOperationResult(final long deadlineTs) throws IOException, TimeoutException { -694 waitForTableEnabled(deadlineTs); -695 waitForAllRegionsOnline(deadlineTs, splitKeys); -696 return null; -697 } -698 } -699 -700 @Override -701 public void deleteTable(final TableName tableName) throws IOException { -702 get(deleteTableAsync(tableName), syncWaitTimeout, TimeUnit.MILLISECONDS); -703 } -704 -705 @Override -706 public Future<Void> deleteTableAsync(final TableName tableName) throws IOException { -707 DeleteTableResponse response = executeCallable( -708 new MasterCallable<DeleteTableResponse>(getConnection(), getRpcControllerFactory()) { -709 @Override -710 protected DeleteTableResponse rpcCall() throws Exception { -711 setPriority(tableName); -712 DeleteTableRequest req = -713 RequestConverter.buildDeleteTableRequest(tableName, ng.getNonceGroup(),ng.newNonce()); -714 return master.deleteTable(getRpcController(), req); -715 } -716 }); -717 return new DeleteTableFuture(this, tableName, response); -718 } -719 -720 private static class DeleteTableFuture extends TableFuture<Void> { -721 public DeleteTableFuture(final HBaseAdmin admin, final TableName tableName, -722 final DeleteTableResponse response) { -723 super(admin, tableName, -724 (response != null && response.hasProcId()) ? response.getProcId() : null); -725 } -726 -727 @Override -728 public String getOperationType() { -729 return "DELETE"; -730 } -731 -732 @Override -733 protected Void waitOperationResult(final long deadlineTs) -734 throws IOException, TimeoutException { -735 waitTableNotFound(deadlineTs); -736 return null; -737 } -738 -739 @Override -740 protected Void postOperationResult(final Void result, final long deadlineTs) -741 throws IOException, TimeoutException { -742 // Delete cached information to prevent clients from using old locations -743 ((ClusterConnection) getAdmin().getConnection()).clearRegionCache(getTableName()); -744 return super.postOperationResult(result, deadlineTs); -745 } -746 } -747 -748 @Override -749 public HTableDescriptor[] deleteTables(String regex) throws IOException { -750 return deleteTables(Pattern.compile(regex)); -751 } -752 -753 /** -754 * Delete tables matching the passed in pattern and wait on completion. -755 * -756 * Warning: Use this method carefully, there is no prompting and the effect is -757 * immediate. Consider using {@link #listTables(java.util.regex.Pattern) } and -758 * {@link #deleteTable(TableName)} -759 * -760 * @param pattern The pattern to match table names against -761 * @return Table descriptors for tables that couldn't be deleted -762 * @throws IOException -763 */ -764 @Override -765 public HTableDescriptor[] deleteTables(Pattern pattern) throws IOException { -766 List<HTableDescriptor> failed = new LinkedList<>(); -767 for (HTableDescriptor table : listTables(pattern)) { -768 try { -769 deleteTable(table.getTableName()); -770 } catch (IOException ex) { -771 LOG.info("Failed to delete table " + table.getTableName(), ex); -772 failed.add(table); -773 } -774 } -775 return failed.toArray(new HTableDescriptor[failed.size()]); -776 } -777 -778 @Override -779 public void truncateTable(final TableName tableName, final boolean preserveSplits) -780 throws IOException { -781 get(truncateTableAsync(tableName, preserveSplits), syncWaitTimeout, TimeUnit.MILLISECONDS); -782 } -783 -784 @Override -785 public Future<Void> truncateTableAsync(final TableName tableName, final boolean preserveSplits) -786 throws IOException { -787 TruncateTableResponse response = -788 executeCallable(new MasterCallable<TruncateTableResponse>(getConnection(), -789 getRpcControllerFactory()) { -790 @Override -791 protected TruncateTableResponse rpcCall() throws Exception { -792 setPriority(tableName); -793 LOG.info("Started truncating " + tableName); -794 TruncateTableRequest req = RequestConverter.buildTruncateTableRequest( -795 tableName, preserveSplits, ng.getNonceGroup(), ng.newNonce()); -796 return master.truncateTable(getRpcController(), req); -797 } -798 }); -799 return new TruncateTableFuture(this, tableName, preserveSplits, response); -800 } +683 protected Void waitOperationResult(final long deadlineTs) throws IOException, TimeoutException { +684 waitForTableEnabled(deadlineTs); +685 waitForAllRegionsOnline(deadlineTs, splitKeys); +686 return null; +687 } +688 } +689 +690 @Override +691 public void deleteTable(final TableName tableName) throws IOException { +692 get(deleteTableAsync(tableName), syncWaitTimeout, TimeUnit.MILLISECONDS); +693 } +694 +695 @Override +696 public Future<Void> deleteTableAsync(final TableName tableName) throws IOException { +697 DeleteTableResponse response = executeCallable( +698 new MasterCallable<DeleteTableResponse>(getConnection(), getRpcControllerFactory()) { +699 @Override +700 protected DeleteTableResponse rpcCall() throws Exception { +701 setPriority(tableName); +702 DeleteTableRequest req = +703 RequestConverter.buildDeleteTableRequest(tableName, ng.getNonceGroup(),ng.newNonce()); +704 return master.deleteTable(getRpcController(), req); +705 } +706 }); +707 return new DeleteTableFuture(this, tableName, response); +708 } +709 +710 private static class DeleteTableFuture extends TableFuture<Void> { +711 public DeleteTableFuture(final HBaseAdmin admin, final TableName tableName, +712 final DeleteTableResponse response) { +713 super(admin, tableName, +714 (response != null && response.hasProcId()) ? response.getProcId() : null); +715 } +716 +717 @Override +718 public String getOperationType() { +719 return "DELETE"; +720 } +721 +722 @Override +723 protected Void waitOperationResult(final long deadlineTs) +724 throws IOException, TimeoutException { +725 waitTableNotFound(deadlineTs); +726 return null; +727 } +728 +729 @Override +730 protected Void postOperationResult(final Void result, final long deadlineTs) +731 throws IOException, TimeoutException { +732 // Delete cached information to prevent clients from using old locations +733 ((ClusterConnection) getAdmin().getConnection()).clearRegionCache(getTableName()); +734 return super.postOperationResult(result, deadlineTs); +735 } +736 } +737 +738 @Override +739 public HTableDescriptor[] deleteTables(String regex) throws IOException { +740 return deleteTables(Pattern.compile(regex)); +741 } +742 +743 /** +744 * Delete tables matching the passed in pattern and wait on completion. +745 * +746 * Warning: Use this method carefully, there is no prompting and the effect is +747 * immediate. Consider using {@link #listTables(java.util.regex.Pattern) } and<