Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 37E3B1915B for ; Wed, 27 Apr 2016 17:06:22 +0000 (UTC) Received: (qmail 92319 invoked by uid 500); 27 Apr 2016 17:06:16 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 91554 invoked by uid 500); 27 Apr 2016 17:06:15 -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 85757 invoked by uid 99); 27 Apr 2016 17:06:10 -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; Wed, 27 Apr 2016 17:06:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 52F4BE0381; Wed, 27 Apr 2016 17:06:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: busbey@apache.org To: commits@hbase.apache.org Date: Wed, 27 Apr 2016 17:06:42 -0000 Message-Id: <9cb769e1e3c64526bdd6758a261a3f5f@git.apache.org> In-Reply-To: <5939d0173bb849d18ee19fbbce9d3dc6@git.apache.org> References: <5939d0173bb849d18ee19fbbce9d3dc6@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [34/51] [partial] hbase-site git commit: Published site at ce318a2906817058ae7b2fce6e9b54d9d6230f9b. http://git-wip-us.apache.org/repos/asf/hbase-site/blob/4131cace/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.CreateTableFuture.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.CreateTableFuture.html b/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.CreateTableFuture.html index 31bc86e..f97ea84 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.CreateTableFuture.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.CreateTableFuture.html @@ -223,3410 +223,3414 @@ 215 private final int syncWaitTimeout; 216 private boolean aborted; 217 private int operationTimeout; -218 -219 private RpcRetryingCallerFactory rpcCallerFactory; -220 private RpcControllerFactory rpcControllerFactory; -221 -222 private NonceGenerator ng; -223 -224 @Override -225 public int getOperationTimeout() { -226 return operationTimeout; -227 } -228 -229 HBaseAdmin(ClusterConnection connection) throws IOException { -230 this.conf = connection.getConfiguration(); -231 this.connection = connection; -232 -233 // TODO: receive ConnectionConfiguration here rather than re-parsing these configs every time. -234 this.pause = this.conf.getLong(HConstants.HBASE_CLIENT_PAUSE, -235 HConstants.DEFAULT_HBASE_CLIENT_PAUSE); -236 this.numRetries = this.conf.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, -237 HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER); -238 this.retryLongerMultiplier = this.conf.getInt( -239 "hbase.client.retries.longer.multiplier", 10); -240 this.operationTimeout = this.conf.getInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, -241 HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT); -242 this.syncWaitTimeout = this.conf.getInt( -243 "hbase.client.sync.wait.timeout.msec", 10 * 60000); // 10min -244 -245 this.rpcCallerFactory = connection.getRpcRetryingCallerFactory(); -246 this.rpcControllerFactory = connection.getRpcControllerFactory(); +218 private int rpcTimeout; +219 +220 private RpcRetryingCallerFactory rpcCallerFactory; +221 private RpcControllerFactory rpcControllerFactory; +222 +223 private NonceGenerator ng; +224 +225 @Override +226 public int getOperationTimeout() { +227 return operationTimeout; +228 } +229 +230 HBaseAdmin(ClusterConnection connection) throws IOException { +231 this.conf = connection.getConfiguration(); +232 this.connection = connection; +233 +234 // TODO: receive ConnectionConfiguration here rather than re-parsing these configs every time. +235 this.pause = this.conf.getLong(HConstants.HBASE_CLIENT_PAUSE, +236 HConstants.DEFAULT_HBASE_CLIENT_PAUSE); +237 this.numRetries = this.conf.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, +238 HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER); +239 this.retryLongerMultiplier = this.conf.getInt( +240 "hbase.client.retries.longer.multiplier", 10); +241 this.operationTimeout = this.conf.getInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, +242 HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT); +243 this.rpcTimeout = this.conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY, +244 HConstants.DEFAULT_HBASE_RPC_TIMEOUT); +245 this.syncWaitTimeout = this.conf.getInt( +246 "hbase.client.sync.wait.timeout.msec", 10 * 60000); // 10min 247 -248 this.ng = this.connection.getNonceGenerator(); -249 } +248 this.rpcCallerFactory = connection.getRpcRetryingCallerFactory(); +249 this.rpcControllerFactory = connection.getRpcControllerFactory(); 250 -251 @Override -252 public void abort(String why, Throwable e) { -253 // Currently does nothing but throw the passed message and exception -254 this.aborted = true; -255 throw new RuntimeException(why, e); -256 } -257 -258 @Override -259 public boolean isAborted(){ -260 return this.aborted; -261 } -262 -263 @Override -264 public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning) -265 throws IOException { -266 return get(abortProcedureAsync(procId, mayInterruptIfRunning), this.syncWaitTimeout, -267 TimeUnit.MILLISECONDS); -268 } -269 -270 @Override -271 public Future<Boolean> abortProcedureAsync( -272 final long procId, -273 final boolean mayInterruptIfRunning) throws IOException { -274 Boolean abortProcResponse = executeCallable( -275 new MasterCallable<AbortProcedureResponse>(getConnection()) { -276 @Override -277 public AbortProcedureResponse call(int callTimeout) throws ServiceException { -278 PayloadCarryingRpcController controller = rpcControllerFactory.newController(); -279 controller.setCallTimeout(callTimeout); -280 AbortProcedureRequest abortProcRequest = -281 AbortProcedureRequest.newBuilder().setProcId(procId).build(); -282 return master.abortProcedure(controller, abortProcRequest); -283 } -284 }).getIsProcedureAborted(); -285 -286 AbortProcedureFuture abortProcFuture = -287 new AbortProcedureFuture(this, procId, abortProcResponse); -288 return abortProcFuture; -289 } -290 -291 private static class AbortProcedureFuture extends ProcedureFuture<Boolean> { -292 private boolean isAbortInProgress; +251 this.ng = this.connection.getNonceGenerator(); +252 } +253 +254 @Override +255 public void abort(String why, Throwable e) { +256 // Currently does nothing but throw the passed message and exception +257 this.aborted = true; +258 throw new RuntimeException(why, e); +259 } +260 +261 @Override +262 public boolean isAborted(){ +263 return this.aborted; +264 } +265 +266 @Override +267 public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning) +268 throws IOException { +269 return get(abortProcedureAsync(procId, mayInterruptIfRunning), this.syncWaitTimeout, +270 TimeUnit.MILLISECONDS); +271 } +272 +273 @Override +274 public Future<Boolean> abortProcedureAsync( +275 final long procId, +276 final boolean mayInterruptIfRunning) throws IOException { +277 Boolean abortProcResponse = executeCallable( +278 new MasterCallable<AbortProcedureResponse>(getConnection()) { +279 @Override +280 public AbortProcedureResponse call(int callTimeout) throws ServiceException { +281 PayloadCarryingRpcController controller = rpcControllerFactory.newController(); +282 controller.setCallTimeout(callTimeout); +283 AbortProcedureRequest abortProcRequest = +284 AbortProcedureRequest.newBuilder().setProcId(procId).build(); +285 return master.abortProcedure(controller, abortProcRequest); +286 } +287 }).getIsProcedureAborted(); +288 +289 AbortProcedureFuture abortProcFuture = +290 new AbortProcedureFuture(this, procId, abortProcResponse); +291 return abortProcFuture; +292 } 293 -294 public AbortProcedureFuture( -295 final HBaseAdmin admin, -296 final Long procId, -297 final Boolean abortProcResponse) { -298 super(admin, procId); -299 this.isAbortInProgress = abortProcResponse; -300 } -301 -302 @Override -303 public Boolean get(long timeout, TimeUnit unit) -304 throws InterruptedException, ExecutionException, TimeoutException { -305 if (!this.isAbortInProgress) { -306 return false; -307 } -308 super.get(timeout, unit); -309 return true; -310 } -311 } -312 -313 /** @return HConnection used by this object. */ -314 @Override -315 public HConnection getConnection() { -316 return connection; -317 } -318 -319 @Override -320 public boolean tableExists(final TableName tableName) throws IOException { -321 return executeCallable(new ConnectionCallable<Boolean>(getConnection()) { -322 @Override -323 public Boolean call(int callTimeout) throws ServiceException, IOException { -324 return MetaTableAccessor.tableExists(connection, tableName); -325 } -326 }); -327 } -328 -329 @Override -330 public HTableDescriptor[] listTables() throws IOException { -331 return listTables((Pattern)null, false); -332 } -333 -334 @Override -335 public HTableDescriptor[] listTables(Pattern pattern) throws IOException { -336 return listTables(pattern, false); -337 } -338 -339 @Override -340 public HTableDescriptor[] listTables(String regex) throws IOException { -341 return listTables(Pattern.compile(regex), false); -342 } -343 -344 @Override -345 public HTableDescriptor[] listTables(final Pattern pattern, final boolean includeSysTables) -346 throws IOException { -347 return executeCallable(new MasterCallable<HTableDescriptor[]>(getConnection()) { -348 @Override -349 public HTableDescriptor[] call(int callTimeout) throws ServiceException { -350 PayloadCarryingRpcController controller = rpcControllerFactory.newController(); -351 controller.setCallTimeout(callTimeout); -352 GetTableDescriptorsRequest req = -353 RequestConverter.buildGetTableDescriptorsRequest(pattern, includeSysTables); -354 return ProtobufUtil.getHTableDescriptorArray(master.getTableDescriptors(controller, req)); -355 } -356 }); -357 } -358 -359 @Override -360 public HTableDescriptor[] listTables(String regex, boolean includeSysTables) -361 throws IOException { -362 return listTables(Pattern.compile(regex), includeSysTables); -363 } -364 -365 @Override -366 public TableName[] listTableNames() throws IOException { -367 return listTableNames((Pattern)null, false); -368 } -369 -370 @Override -371 public TableName[] listTableNames(Pattern pattern) throws IOException { -372 return listTableNames(pattern, false); -373 } -374 -375 @Override -376 public TableName[] listTableNames(String regex) throws IOException { -377 return listTableNames(Pattern.compile(regex), false); -378 } -379 -380 @Override -381 public TableName[] listTableNames(final Pattern pattern, final boolean includeSysTables) -382 throws IOException { -383 return executeCallable(new MasterCallable<TableName[]>(getConnection()) { -384 @Override -385 public TableName[] call(int callTimeout) throws ServiceException { -386 PayloadCarryingRpcController controller = rpcControllerFactory.newController(); -387 controller.setCallTimeout(callTimeout); -388 GetTableNamesRequest req = -389 RequestConverter.buildGetTableNamesRequest(pattern, includeSysTables); -390 return ProtobufUtil.getTableNameArray(master.getTableNames(controller, req) -391 .getTableNamesList()); -392 } -393 }); -394 } -395 -396 @Override -397 public TableName[] listTableNames(final String regex, final boolean includeSysTables) -398 throws IOException { -399 return listTableNames(Pattern.compile(regex), includeSysTables); -400 } -401 -402 @Override -403 public HTableDescriptor getTableDescriptor(final TableName tableName) throws IOException { -404 return getTableDescriptor(tableName, getConnection(), rpcCallerFactory, rpcControllerFactory, -405 operationTimeout); -406 } -407 -408 static HTableDescriptor getTableDescriptor(final TableName tableName, HConnection connection, -409 RpcRetryingCallerFactory rpcCallerFactory, final RpcControllerFactory rpcControllerFactory, -410 int operationTimeout) throws IOException { -411 if (tableName == null) return null; -412 HTableDescriptor htd = executeCallable(new MasterCallable<HTableDescriptor>(connection) { -413 @Override -414 public HTableDescriptor call(int callTimeout) throws ServiceException { -415 PayloadCarryingRpcController controller = rpcControllerFactory.newController(); -416 controller.setCallTimeout(callTimeout); -417 GetTableDescriptorsResponse htds; -418 GetTableDescriptorsRequest req = -419 RequestConverter.buildGetTableDescriptorsRequest(tableName); -420 htds = master.getTableDescriptors(controller, req); -421 -422 if (!htds.getTableSchemaList().isEmpty()) { -423 return ProtobufUtil.convertToHTableDesc(htds.getTableSchemaList().get(0)); -424 } -425 return null; -426 } -427 }, rpcCallerFactory, operationTimeout); -428 if (htd != null) { -429 return htd; -430 } -431 throw new TableNotFoundException(tableName.getNameAsString()); -432 } -433 -434 private long getPauseTime(int tries) { -435 int triesCount = tries; -436 if (triesCount >= HConstants.RETRY_BACKOFF.length) { -437 triesCount = HConstants.RETRY_BACKOFF.length - 1; -438 } -439 return this.pause * HConstants.RETRY_BACKOFF[triesCount]; -440 } -441 -442 @Override -443 public void createTable(HTableDescriptor desc) -444 throws IOException { -445 createTable(desc, null); -446 } -447 -448 @Override -449 public void createTable(HTableDescriptor desc, byte [] startKey, -450 byte [] endKey, int numRegions) -451 throws IOException { -452 if(numRegions < 3) { -453 throw new IllegalArgumentException("Must create at least three regions"); -454 } else if(Bytes.compareTo(startKey, endKey) >= 0) { -455 throw new IllegalArgumentException("Start key must be smaller than end key"); -456 } -457 if (numRegions == 3) { -458 createTable(desc, new byte[][]{startKey, endKey}); -459 return; -460 } -461 byte [][] splitKeys = Bytes.split(startKey, endKey, numRegions - 3); -462 if(splitKeys == null || splitKeys.length != numRegions - 1) { -463 throw new IllegalArgumentException("Unable to split key range into enough regions"); -464 } -465 createTable(desc, splitKeys); -466 } -467 -468 @Override -469 public void createTable(final HTableDescriptor desc, byte [][] splitKeys) -470 throws IOException { -471 get(createTableAsync(desc, splitKeys), syncWaitTimeout, TimeUnit.MILLISECONDS); -472 } -473 -474 @Override -475 public Future<Void> createTableAsync(final HTableDescriptor desc, final byte[][] splitKeys) -476 throws IOException { -477 if (desc.getTableName() == null) { -478 throw new IllegalArgumentException("TableName cannot be null"); -479 } -480 if (splitKeys != null && splitKeys.length > 0) { -481 Arrays.sort(splitKeys, Bytes.BYTES_COMPARATOR); -482 // Verify there are no duplicate split keys -483 byte[] lastKey = null; -484 for (byte[] splitKey : splitKeys) { -485 if (Bytes.compareTo(splitKey, HConstants.EMPTY_BYTE_ARRAY) == 0) { -486 throw new IllegalArgumentException( -487 "Empty split key must not be passed in the split keys."); -488 } -489 if (lastKey != null && Bytes.equals(splitKey, lastKey)) { -490 throw new IllegalArgumentException("All split keys must be unique, " + -491 "found duplicate: " + Bytes.toStringBinary(splitKey) + -492 ", " + Bytes.toStringBinary(lastKey)); -493 } -494 lastKey = splitKey; -495 } -496 } -497 -498 CreateTableResponse response = executeCallable( -499 new MasterCallable<CreateTableResponse>(getConnection()) { -500 @Override -501 public CreateTableResponse call(int callTimeout) throws ServiceException { -502 PayloadCarryingRpcController controller = rpcControllerFactory.newController(); -503 controller.setCallTimeout(callTimeout); -504 controller.setPriority(desc.getTableName()); -505 CreateTableRequest request = RequestConverter.buildCreateTableRequest( -506 desc, splitKeys, ng.getNonceGroup(), ng.newNonce()); -507 return master.createTable(controller, request); -508 } -509 }); -510 return new CreateTableFuture(this, desc, splitKeys, response); -511 } -512 -513 private static class CreateTableFuture extends TableFuture<Void> { -514 private final HTableDescriptor desc; -515 private final byte[][] splitKeys; -516 -517 public CreateTableFuture(final HBaseAdmin admin, final HTableDescriptor desc, -518 final byte[][] splitKeys, final CreateTableResponse response) { -519 super(admin, desc.getTableName(), -520 (response != null && response.hasProcId()) ? response.getProcId() : null); -521 this.splitKeys = splitKeys; -522 this.desc = desc; -523 } -524 -525 @Override -526 protected HTableDescriptor getTableDescriptor() { -527 return desc; -528 } -529 -530 @Override -531 public String getOperationType() { -532 return "CREATE"; -533 } -534 -535 @Override -536 protected Void waitOperationResult(final long deadlineTs) throws IOException, TimeoutException { -537 waitForTableEnabled(deadlineTs); -538 waitForAllRegionsOnline(deadlineTs, splitKeys); -539 return null; -540 } -541 } -542 -543 @Override -544 public void deleteTable(final TableName tableName) throws IOException { -545 get(deleteTableAsync(tableName), syncWaitTimeout, TimeUnit.MILLISECONDS); -546 } -547 -548 @Override -549 public Future<Void> deleteTableAsync(final TableName tableName) throws IOException { -550 DeleteTableResponse response = executeCallable( -551 new MasterCallable<DeleteTableResponse>(getConnection()) { -552 @Override -553 public DeleteTableResponse call(int callTimeout) throws ServiceException { -554 PayloadCarryingRpcController controller = rpcControllerFactory.newController(); -555 controller.setCallTimeout(callTimeout); -556 controller.setPriority(tableName); -557 DeleteTableRequest req = -558 RequestConverter.buildDeleteTableRequest(tableName, ng.getNonceGroup(),ng.newNonce()); -559 return master.deleteTable(controller,req); -560 } -561 }); -562 return new DeleteTableFuture(this, tableName, response); -563 } -564 -565 private static class DeleteTableFuture extends TableFuture<Void> { -566 public DeleteTableFuture(final HBaseAdmin admin, final TableName tableName, -567 final DeleteTableResponse response) { -568 super(admin, tableName, -569 (response != null && response.hasProcId()) ? response.getProcId() : null); -570 } -571 -572 @Override -573 public String getOperationType() { -574 return "DELETE"; -575 } -576 -577 @Override -578 protected Void waitOperationResult(final long deadlineTs) -579 throws IOException, TimeoutException { -580 waitTableNotFound(deadlineTs); -581 return null; -582 } -583 -584 @Override -585 protected Void postOperationResult(final Void result, final long deadlineTs) -586 throws IOException, TimeoutException { -587 // Delete cached information to prevent clients from using old locations -588 getAdmin().getConnection().clearRegionCache(getTableName()); -589 return super.postOperationResult(result, deadlineTs); -590 } -591 } -592 -593 @Override -594 public HTableDescriptor[] deleteTables(String regex) throws IOException { -595 return deleteTables(Pattern.compile(regex)); -596 } -597 -598 /** -599 * Delete tables matching the passed in pattern and wait on completion. -600 * -601 * Warning: Use this method carefully, there is no prompting and the effect is -602 * immediate. Consider using {@link #listTables(java.util.regex.Pattern) } and -603 * {@link #deleteTable(TableName)} -604 * -605 * @param pattern The pattern to match table names against -606 * @return Table descriptors for tables that couldn't be deleted -607 * @throws IOException -608 */ -609 @Override -610 public HTableDescriptor[] deleteTables(Pattern pattern) throws IOException { -611 List<HTableDescriptor> failed = new LinkedList<HTableDescriptor>(); -612 for (HTableDescriptor table : listTables(pattern)) { -613 try { -614 deleteTable(table.getTableName()); -615 } catch (IOException ex) { -616 LOG.info("Failed to delete table " + table.getTableName(), ex); -617 failed.add(table); -618 } -619 } -620 return failed.toArray(new HTableDescriptor[failed.size()]); -621 } -622 -623 @Override -624 public void truncateTable(final TableName tableName, final boolean preserveSplits) -625 throws IOException { -626 get(truncateTableAsync(tableName, preserveSplits), syncWaitTimeout, TimeUnit.MILLISECONDS); -627 } -628 -629 @Override -630 public Future<Void> truncateTableAsync(final TableName tableName, final boolean preserveSplits) -631 throws IOException { -632 TruncateTableResponse response = -633 executeCallable(new MasterCallable<TruncateTableResponse>(getConnection()) { -634 @Override -635 public TruncateTableResponse call(int callTimeout) throws ServiceException { -636 PayloadCarryingRpcController controller = rpcControllerFactory.newController(); -637 controller.setCallTimeout(callTimeout); -638 controller.setPriority(tableName); -639 LOG.info("Started truncating " + tableName); -640 TruncateTableRequest req = RequestConverter.buildTruncateTableRequest( -641 tableName, preserveSplits, ng.getNonceGroup(), ng.newNonce()); -642 return master.truncateTable(controller, req); -643 } -644 }); -645 return new TruncateTableFuture(this, tableName, preserveSplits, response); -646 } -647 -648 private static class TruncateTableFuture extends TableFuture<Void> { -649 private final boolean preserveSplits; +294 private static class AbortProcedureFuture extends ProcedureFuture<Boolean> { +295 private boolean isAbortInProgress; +296 +297 public AbortProcedureFuture( +298 final HBaseAdmin admin, +299 final Long procId, +300 final Boolean abortProcResponse) { +301 super(admin, procId); +302 this.isAbortInProgress = abortProcResponse; +303 } +304 +305 @Override +306 public Boolean get(long timeout, TimeUnit unit) +307 throws InterruptedException, ExecutionException, TimeoutException { +308 if (!this.isAbortInProgress) { +309 return false; +310 } +311 super.get(timeout, unit); +312 return true; +313 } +314 } +315 +316 /** @return HConnection used by this object. */ +317 @Override +318 public HConnection getConnection() { +319 return connection; +320 } +321 +322 @Override +323 public boolean tableExists(final TableName tableName) throws IOException { +324 return executeCallable(new ConnectionCallable<Boolean>(getConnection()) { +325 @Override +326 public Boolean call(int callTimeout) throws ServiceException, IOException { +327 return MetaTableAccessor.tableExists(connection, tableName); +328 } +329 }); +330 } +331 +332 @Override +333 public HTableDescriptor[] listTables() throws IOException { +334 return listTables((Pattern)null, false); +335 } +336 +337 @Override +338 public HTableDescriptor[] listTables(Pattern pattern) throws IOException { +339 return listTables(pattern, false); +340 } +341 +342 @Override +343 public HTableDescriptor[] listTables(String regex) throws IOException { +344 return listTables(Pattern.compile(regex), false); +345 } +346 +347 @Override +348 public HTableDescriptor[] listTables(final Pattern pattern, final boolean includeSysTables) +349 throws IOException { +350 return executeCallable(new MasterCallable<HTableDescriptor[]>(getConnection()) { +351 @Override +352 public HTableDescriptor[] call(int callTimeout) throws ServiceException { +353 PayloadCarryingRpcController controller = rpcControllerFactory.newController(); +354 controller.setCallTimeout(callTimeout); +355 GetTableDescriptorsRequest req = +356 RequestConverter.buildGetTableDescriptorsRequest(pattern, includeSysTables); +357 return ProtobufUtil.getHTableDescriptorArray(master.getTableDescriptors(controller, req)); +358 } +359 }); +360 } +361 +362 @Override +363 public HTableDescriptor[] listTables(String regex, boolean includeSysTables) +364 throws IOException { +365 return listTables(Pattern.compile(regex), includeSysTables); +366 } +367 +368 @Override +369 public TableName[] listTableNames() throws IOException { +370 return listTableNames((Pattern)null, false); +371 } +372 +373 @Override +374 public TableName[] listTableNames(Pattern pattern) throws IOException { +375 return listTableNames(pattern, false); +376 } +377 +378 @Override +379 public TableName[] listTableNames(String regex) throws IOException { +380 return listTableNames(Pattern.compile(regex), false); +381 } +382 +383 @Override +384 public TableName[] listTableNames(final Pattern pattern, final boolean includeSysTables) +385 throws IOException { +386 return executeCallable(new MasterCallable<TableName[]>(getConnection()) { +387 @Override +388 public TableName[] call(int callTimeout) throws ServiceException { +389 PayloadCarryingRpcController controller = rpcControllerFactory.newController(); +390 controller.setCallTimeout(callTimeout); +391 GetTableNamesRequest req = +392 RequestConverter.buildGetTableNamesRequest(pattern, includeSysTables); +393 return ProtobufUtil.getTableNameArray(master.getTableNames(controller, req) +394 .getTableNamesList()); +395 } +396 }); +397 } +398 +399 @Override +400 public TableName[] listTableNames(final String regex, final boolean includeSysTables) +401 throws IOException { +402 return listTableNames(Pattern.compile(regex), includeSysTables); +403 } +404 +405 @Override +406 public HTableDescriptor getTableDescriptor(final TableName tableName) throws IOException { +407 return getTableDescriptor(tableName, getConnection(), rpcCallerFactory, rpcControllerFactory, +408 operationTimeout, rpcTimeout); +409 } +410 +411 static HTableDescriptor getTableDescriptor(final TableName tableName, HConnection connection, +412 RpcRetryingCallerFactory rpcCallerFactory, final RpcControllerFactory rpcControllerFactory, +413 int operationTimeout, int rpcTimeout) throws IOException { +414 if (tableName == null) return null; +415 HTableDescriptor htd = executeCallable(new MasterCallable<HTableDescriptor>(connection) { +416 @Override +417 public HTableDescriptor call(int callTimeout) throws ServiceException { +418 PayloadCarryingRpcController controller = rpcControllerFactory.newController(); +419 controller.setCallTimeout(callTimeout); +420 GetTableDescriptorsResponse htds; +421 GetTableDescriptorsRequest req = +422 RequestConverter.buildGetTableDescriptorsRequest(tableName); +423 htds = master.getTableDescriptors(controller, req); +424 +425 if (!htds.getTableSchemaList().isEmpty()) { +426 return ProtobufUtil.convertToHTableDesc(htds.getTableSchemaList().get(0)); +427 } +428 return null; +429 } +430 }, rpcCallerFactory, operationTimeout, rpcTimeout); +431 if (htd != null) { +432 return htd; +433 } +434 throw new TableNotFoundException(tableName.getNameAsString()); +435 } +436 +437 private long getPauseTime(int tries) { +438 int triesCount = tries; +439 if (triesCount >= HConstants.RETRY_BACKOFF.length) { +440 triesCount = HConstants.RETRY_BACKOFF.length - 1; +441 } +442 return this.pause * HConstants.RETRY_BACKOFF[triesCount]; +443 } +444 +445 @Override +446 public void createTable(HTableDescriptor desc) +447 throws IOException { +448 createTable(desc, null); +449 } +450 +451 @Override +452 public void createTable(HTableDescriptor desc, byte [] startKey, +453 byte [] endKey, int numRegions) +454 throws IOException { +455 if(numRegions < 3) { +456 throw new IllegalArgumentException("Must create at least three regions"); +457 } else if(Bytes.compareTo(startKey, endKey) >= 0) { +458 throw new IllegalArgumentException("Start key must be smaller than end key"); +459 } +460 if (numRegions == 3) { +461 createTable(desc, new byte[][]{startKey, endKey}); +462 return; +463 } +464 byte [][] splitKeys = Bytes.split(startKey, endKey, numRegions - 3); +465 if(splitKeys == null || splitKeys.length != numRegions - 1) { +466 throw new IllegalArgumentException("Unable to split key range into enough regions"); +467 } +468 createTable(desc, splitKeys); +469 } +470 +471 @Override +472 public void createTable(final HTableDescriptor desc, byte [][] splitKeys) +473 throws IOException { +474 get(createTableAsync(desc, splitKeys), syncWaitTimeout, TimeUnit.MILLISECONDS); +475 } +476 +477 @Override +478 public Future<Void> createTableAsync(final HTableDescriptor desc, final byte[][] splitKeys) +479 throws IOException { +480 if (desc.getTableName() == null) { +481 throw new IllegalArgumentException("TableName cannot be null"); +482 } +483 if (splitKeys != null && splitKeys.length > 0) { +484 Arrays.sort(splitKeys, Bytes.BYTES_COMPARATOR); +485 // Verify there are no duplicate split keys +486 byte[] lastKey = null; +487 for (byte[] splitKey : splitKeys) { +488 if (Bytes.compareTo(splitKey, HConstants.EMPTY_BYTE_ARRAY) == 0) { +489 throw new IllegalArgumentException( +490 "Empty split key must not be passed in the split keys."); +491 } +492 if (lastKey != null && Bytes.equals(splitKey, lastKey)) { +493 throw new IllegalArgumentException("All split keys must be unique, " + +494 "found duplicate: " + Bytes.toStringBinary(splitKey) + +495 ", " + Bytes.toStringBinary(lastKey)); +496 } +497 lastKey = splitKey; +498 } +499 } +500 +501 CreateTableResponse response = executeCallable( +502 new MasterCallable<CreateTableResponse>(getConnection()) { +503 @Override +504 public CreateTableResponse call(int callTimeout) throws ServiceException { +505 PayloadCarryingRpcController controller = rpcControllerFactory.newController(); +506 controller.setCallTimeout(callTimeout); +507 controller.setPriority(desc.getTableName()); +508 CreateTableRequest request = RequestConverter.buildCreateTableRequest( +509 desc, splitKeys, ng.getNonceGroup(), ng.newNonce()); +510 return master.createTable(controller, request); +511 } +512 }); +513 return new CreateTableFuture(this, desc, splitKeys, response); +514 } +515 +516 private static class CreateTableFuture extends TableFuture<Void> { +517 private final HTableDescriptor desc; +518 private final byte[][] splitKeys; +519 +520 public CreateTableFuture(final HBaseAdmin admin, final HTableDescriptor desc, +521 final byte[][] splitKeys, final CreateTableResponse response) { +522 super(admin, desc.getTableName(), +523 (response != null && response.hasProcId()) ? response.getProcId() : null); +524 this.splitKeys = splitKeys; +525 this.desc = desc; +526 } +527 +528 @Override +529 protected HTableDescriptor getTableDescriptor() { +530 return desc; +531 } +532 +533 @Override +534 public String getOperationType() { +535 return "CREATE"; +536 } +537 +538 @Override +539 protected Void waitOperationResult(final long deadlineTs) throws IOException, TimeoutException { +540 waitForTableEnabled(deadlineTs); +541 waitForAllRegionsOnline(deadlineTs, splitKeys); +542 return null; +543 } +544 } +545 +546 @Override +547 public void deleteTable(final TableName tableName) throws IOException { +548 get(deleteTableAsync(tableName), syncWaitTimeout, TimeUnit.MILLISECONDS); +549 } +550 +551 @Override +552 public Future<Void> deleteTableAsync(final TableName tableName) throws IOException { +553 DeleteTableResponse response = executeCallable( +554 new MasterCallable<DeleteTableResponse>(getConnection()) { +555 @Override +556 public DeleteTableResponse call(int callTimeout) throws ServiceException { +557 PayloadCarryingRpcController controller = rpcControllerFactory.newController(); +558 controller.setCallTimeout(callTimeout); +559 controller.setPriority(tableName); +560 DeleteTableRequest req = +561 RequestConverter.buildDeleteTableRequest(tableName, ng.getNonceGroup(),ng.newNonce()); +562 return master.deleteTable(controller,req); +563 } +564 }); +565 return new DeleteTableFuture(this, tableName, response); +566 } +567 +568 private static class DeleteTableFuture extends TableFuture<Void> { +569 public DeleteTableFuture(final HBaseAdmin admin, final TableName tableName, +570 final DeleteTableResponse response) { +571 super(admin, tableName, +572 (response != null && response.hasProcId()) ? response.getProcId() : null); +573 } +574 +575 @Override +576 public String getOperationType() { +577 return "DELETE"; +578 } +579 +580 @Override +581 protected Void waitOperationResult(final long deadlineTs) +582 throws IOException, TimeoutException { +583 waitTableNotFound(deadlineTs); +584 return null; +585 } +586 +587 @Override +588 protected Void postOperationResult(final Void result, final long deadlineTs) +589 throws IOException, TimeoutException { +590 // Delete cached information to prevent clients from using old locations +591 getAdmin().getConnection().clearRegionCache(getTableName()); +592 return super.postOperationResult(result, deadlineTs); +593 } +594 } +595 +596 @Override +597 public HTableDescriptor[] deleteTables(String regex) throws IOException { +598 return deleteTables(Pattern.compile(regex)); +599 } +600 +601 /** +602 * Delete tables matching the passed in pattern and wait on completion. +603 * +604 * Warning: Use this method carefully, there is no prompting and the effect is +605 * immediate. Consider using {@link #listTables(java.util.regex.Pattern) } and +606 * {@link #deleteTable(TableName)} +607 * +608 * @param pattern The pattern to match table names against +609 * @return Table descriptors for tables that couldn't be deleted +610 * @throws IOException +611 */ +612 @Override +613 public HTableDescriptor[] deleteTables(Pattern pattern) throws IOException { +614 List<HTableDescriptor> failed = new LinkedList<HTableDescriptor>(); +615 for (HTableDescriptor table : listTables(pattern)) { +616 try { +617 deleteTable(table.getTableName()); +618 } catch (IOException ex) { +619 LOG.info("Failed to delete table " + table.getTableName(), ex); +620 failed.add(table); +621 } +622 } +623 return failed.toArray(new HTableDescriptor[failed.size()]); +624 } +625 +626 @Override +627 public void truncateTable(final TableName tableName, final boolean preserveSplits) +628 throws IOException { +629 get(truncateTableAsync(tableName, preserveSplits), syncWaitTimeout, TimeUnit.MILLISECONDS); +630 } +631 +632 @Override +633 public Future<Void> truncateTableAsync(final TableName tableName, final boolean preserveSplits) +634 throws IOException { +635 TruncateTableResponse response = +636 executeCallable(new MasterCallable<TruncateTableResponse>(getConnection()) { +637 @Override +638 public TruncateTableResponse call(int callTimeout) throws ServiceException { +639 PayloadCarryingRpcController controller = rpcControllerFactory.newController(); +640 controller.setCallTimeout(callTimeout); +641 controller.setPriority(tableName); +642 LOG.info("Started truncating " + tableName); +643 TruncateTableRequest req = RequestConverter.buildTruncateTableRequest( +644 tableName, preserveSplits, ng.getNonceGroup(), ng.newNonce()); +645 return master.truncateTable(controller, req); +646 } +647 }); +648 return new TruncateTableFuture(this, tableName, preserveSplits, response); +649 } 650 -651 public TruncateTableFuture(final HBaseAdmin admin, final TableName tableName, -652 final boolean preserveSplits, final TruncateTableResponse response) { -653 super(admin, tableName, -654 (response != null && response.hasProcId()) ? response.getProcId() : null); -655 this.preserveSplits = preserveSplits; -656 } -657 -658 @Override -659 public String getOperationType() { -660 return "TRUNCATE"; -661 } -662 -663 @Override -664 protected Void waitOperationResult(final long deadlineTs) throws IOException, TimeoutException { -665 waitForTableEnabled(deadlineTs); -666 // once the table is enabled, we know the operation is done. so we can fetch the splitKeys -667 byte[][] splitKeys = preserveSplits ? getAdmin().getTableSplits(getTableName()) : null; -668 waitForAllRegionsOnline(deadlineTs, splitKeys); -669 return null; -670 } -671 } -672 -673 private byte[][] getTableSplits(final TableName tableName) throws IOException { -674 byte[][] splits = null; -675 try (RegionLocator locator = getConnection().getRegionLocator(tableName)) { -676 byte[][] startKeys = locator.getStartKeys(); -677 if (startKeys.length == 1) { -678 return splits; -679 } -680 splits = new byte[startKeys.length - 1][]; -681 for (int i = 1; i < startKeys.length; i++) { -682 splits[i - 1] = startKeys[i]; -683 } -684 } -685 return splits; -686 } -