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 74C7618471 for ; Mon, 29 Feb 2016 19:08:12 +0000 (UTC) Received: (qmail 33698 invoked by uid 500); 29 Feb 2016 19:08:11 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 33546 invoked by uid 500); 29 Feb 2016 19:08:11 -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 33005 invoked by uid 99); 29 Feb 2016 19:08: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; Mon, 29 Feb 2016 19:08:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A84ECE788D; Mon, 29 Feb 2016 19:08:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: misty@apache.org To: commits@hbase.apache.org Date: Mon, 29 Feb 2016 19:08:16 -0000 Message-Id: In-Reply-To: <8a6679a68b71466c96c944b62248c43f@git.apache.org> References: <8a6679a68b71466c96c944b62248c43f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [07/51] [partial] hbase-site git commit: Published site at 88f775996b3b52d784ad13ab07515134619316ba. http://git-wip-us.apache.org/repos/asf/hbase-site/blob/bdd1f3f0/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 fe129c6..1600051 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 @@ -97,3301 +97,3332 @@ 089import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType; 090import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; 091import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.TableSchema; -092import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.AbortProcedureRequest; -093import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.AbortProcedureResponse; -094import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.AddColumnRequest; -095import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.AddColumnResponse; -096import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.AssignRegionRequest; -097import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.CreateNamespaceRequest; -098import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.CreateNamespaceResponse; -099import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.CreateTableRequest; -100import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.CreateTableResponse; -101import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.DeleteColumnRequest; -102import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.DeleteColumnResponse; -103import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.DeleteNamespaceRequest; -104import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.DeleteNamespaceResponse; -105import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.DeleteSnapshotRequest; -106import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.DeleteTableRequest; -107import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.DeleteTableResponse; -108import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.DisableTableRequest; -109import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.DisableTableResponse; -110import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.DispatchMergingRegionsRequest; -111import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.EnableTableRequest; -112import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.EnableTableResponse; -113import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ExecProcedureRequest; -114import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ExecProcedureResponse; -115import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetClusterStatusRequest; -116import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetCompletedSnapshotsRequest; -117import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetNamespaceDescriptorRequest; -118import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetProcedureResultRequest; -119import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetProcedureResultResponse; -120import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetSchemaAlterStatusRequest; -121import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetSchemaAlterStatusResponse; -122import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableDescriptorsRequest; -123import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableDescriptorsResponse; -124import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableNamesRequest; -125import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsProcedureDoneRequest; -126import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsProcedureDoneResponse; -127import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsRestoreSnapshotDoneRequest; -128import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsRestoreSnapshotDoneResponse; -129import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsSnapshotDoneRequest; -130import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsSnapshotDoneResponse; -131import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ListNamespaceDescriptorsRequest; -132import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ListProceduresRequest; -133import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceRequest; -134import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ListTableNamesByNamespaceRequest; -135import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.MajorCompactionTimestampForRegionRequest; -136import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.MajorCompactionTimestampRequest; -137import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ModifyColumnRequest; -138import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ModifyColumnResponse; -139import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ModifyNamespaceRequest; -140import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ModifyNamespaceResponse; -141import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ModifyTableRequest; -142import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ModifyTableResponse; -143import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.MoveRegionRequest; -144import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.RestoreSnapshotRequest; -145import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.RestoreSnapshotResponse; -146import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SecurityCapabilitiesRequest; -147import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SetBalancerRunningRequest; -148import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SetNormalizerRunningRequest; -149import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ShutdownRequest; -150import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SnapshotRequest; -151import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SnapshotResponse; -152import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.StopMasterRequest; -153import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.TruncateTableRequest; -154import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.TruncateTableResponse; -155import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.UnassignRegionRequest; -156import org.apache.hadoop.hbase.protobuf.generated.ProcedureProtos; -157import org.apache.hadoop.hbase.quotas.QuotaFilter; -158import org.apache.hadoop.hbase.quotas.QuotaRetriever; -159import org.apache.hadoop.hbase.quotas.QuotaSettings; -160import org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException; -161import org.apache.hadoop.hbase.snapshot.ClientSnapshotDescriptionUtils; -162import org.apache.hadoop.hbase.snapshot.HBaseSnapshotException; -163import org.apache.hadoop.hbase.snapshot.RestoreSnapshotException; -164import org.apache.hadoop.hbase.snapshot.SnapshotCreationException; -165import org.apache.hadoop.hbase.snapshot.UnknownSnapshotException; -166import org.apache.hadoop.hbase.util.Addressing; -167import org.apache.hadoop.hbase.util.Bytes; -168import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -169import org.apache.hadoop.hbase.util.ForeignExceptionUtil; -170import org.apache.hadoop.hbase.util.Pair; -171import org.apache.hadoop.hbase.zookeeper.MasterAddressTracker; -172import org.apache.hadoop.hbase.zookeeper.MetaTableLocator; -173import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; -174import org.apache.hadoop.ipc.RemoteException; -175import org.apache.hadoop.util.StringUtils; -176import org.apache.zookeeper.KeeperException; -177 -178import com.google.common.annotations.VisibleForTesting; -179import com.google.protobuf.ByteString; -180import com.google.protobuf.ServiceException; -181 -182/** -183 * HBaseAdmin is no longer a client API. It is marked InterfaceAudience.Private indicating that -184 * this is an HBase-internal class as defined in -185 * https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/InterfaceClassification.html -186 * There are no guarantees for backwards source / binary compatibility and methods or class can -187 * change or go away without deprecation. -188 * Use {@link Connection#getAdmin()} to obtain an instance of {@link Admin} instead of constructing -189 * an HBaseAdmin directly. -190 * -191 * <p>Connection should be an <i>unmanaged</i> connection obtained via -192 * {@link ConnectionFactory#createConnection(Configuration)} -193 * -194 * @see ConnectionFactory -195 * @see Connection -196 * @see Admin -197 */ -198@InterfaceAudience.Private -199@InterfaceStability.Evolving -200public class HBaseAdmin implements Admin { -201 private static final Log LOG = LogFactory.getLog(HBaseAdmin.class); -202 -203 private static final String ZK_IDENTIFIER_PREFIX = "hbase-admin-on-"; -204 -205 private ClusterConnection connection; -206 -207 private volatile Configuration conf; -208 private final long pause; -209 private final int numRetries; -210 // Some operations can take a long time such as disable of big table. -211 // numRetries is for 'normal' stuff... Multiply by this factor when -212 // want to wait a long time. -213 private final int retryLongerMultiplier; -214 private final int syncWaitTimeout; -215 private boolean aborted; -216 private int operationTimeout; -217 -218 private RpcRetryingCallerFactory rpcCallerFactory; -219 -220 private NonceGenerator ng; -221 -222 @Override -223 public int getOperationTimeout() { -224 return operationTimeout; -225 } -226 -227 HBaseAdmin(ClusterConnection connection) throws IOException { -228 this.conf = connection.getConfiguration(); -229 this.connection = connection; -230 -231 this.pause = this.conf.getLong(HConstants.HBASE_CLIENT_PAUSE, -232 HConstants.DEFAULT_HBASE_CLIENT_PAUSE); -233 this.numRetries = this.conf.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, -234 HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER); -235 this.retryLongerMultiplier = this.conf.getInt( -236 "hbase.client.retries.longer.multiplier", 10); -237 this.operationTimeout = this.conf.getInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, -238 HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT); -239 this.syncWaitTimeout = this.conf.getInt( -240 "hbase.client.sync.wait.timeout.msec", 10 * 60000); // 10min -241 -242 this.rpcCallerFactory = RpcRetryingCallerFactory.instantiate(this.conf); -243 -244 this.ng = this.connection.getNonceGenerator(); -245 } -246 -247 @Override -248 public void abort(String why, Throwable e) { -249 // Currently does nothing but throw the passed message and exception -250 this.aborted = true; -251 throw new RuntimeException(why, e); -252 } -253 -254 @Override -255 public boolean isAborted(){ -256 return this.aborted; -257 } -258 -259 @Override -260 public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning) -261 throws IOException { -262 return get(abortProcedureAsync(procId, mayInterruptIfRunning), this.syncWaitTimeout, -263 TimeUnit.MILLISECONDS); -264 } -265 -266 @Override -267 public Future<Boolean> abortProcedureAsync( -268 final long procId, -269 final boolean mayInterruptIfRunning) throws IOException { -270 Boolean abortProcResponse = executeCallable( -271 new MasterCallable<AbortProcedureResponse>(getConnection()) { -272 @Override -273 public AbortProcedureResponse call(int callTimeout) throws ServiceException { -274 AbortProcedureRequest abortProcRequest = -275 AbortProcedureRequest.newBuilder().setProcId(procId).build(); -276 return master.abortProcedure(null,abortProcRequest); -277 } -278 }).getIsProcedureAborted(); -279 -280 AbortProcedureFuture abortProcFuture = -281 new AbortProcedureFuture(this, procId, abortProcResponse); -282 return abortProcFuture; -283 } -284 -285 private static class AbortProcedureFuture extends ProcedureFuture<Boolean> { -286 private boolean isAbortInProgress; -287 -288 public AbortProcedureFuture( -289 final HBaseAdmin admin, -290 final Long procId, -291 final Boolean abortProcResponse) { -292 super(admin, procId); -293 this.isAbortInProgress = abortProcResponse; -294 } -295 -296 @Override -297 public Boolean get(long timeout, TimeUnit unit) -298 throws InterruptedException, ExecutionException, TimeoutException { -299 if (!this.isAbortInProgress) { -300 return false; -301 } -302 super.get(timeout, unit); -303 return true; -304 } -305 } -306 -307 /** @return HConnection used by this object. */ -308 @Override -309 public HConnection getConnection() { -310 return connection; -311 } -312 -313 @Override -314 public boolean tableExists(final TableName tableName) throws IOException { -315 return executeCallable(new ConnectionCallable<Boolean>(getConnection()) { -316 @Override -317 public Boolean call(int callTimeout) throws ServiceException, IOException { -318 return MetaTableAccessor.tableExists(connection, tableName); -319 } -320 }); -321 } -322 -323 @Override -324 public HTableDescriptor[] listTables() throws IOException { -325 return listTables((Pattern)null, false); -326 } -327 -328 @Override -329 public HTableDescriptor[] listTables(Pattern pattern) throws IOException { -330 return listTables(pattern, false); -331 } -332 -333 @Override -334 public HTableDescriptor[] listTables(String regex) throws IOException { -335 return listTables(Pattern.compile(regex), false); -336 } -337 -338 @Override -339 public HTableDescriptor[] listTables(final Pattern pattern, final boolean includeSysTables) -340 throws IOException { -341 return executeCallable(new MasterCallable<HTableDescriptor[]>(getConnection()) { -342 @Override -343 public HTableDescriptor[] call(int callTimeout) throws ServiceException { -344 GetTableDescriptorsRequest req = -345 RequestConverter.buildGetTableDescriptorsRequest(pattern, includeSysTables); -346 return ProtobufUtil.getHTableDescriptorArray(master.getTableDescriptors(null, req)); -347 } -348 }); -349 } -350 -351 @Override -352 public HTableDescriptor[] listTables(String regex, boolean includeSysTables) -353 throws IOException { -354 return listTables(Pattern.compile(regex), includeSysTables); -355 } -356 -357 @Override -358 public TableName[] listTableNames() throws IOException { -359 return listTableNames((Pattern)null, false); -360 } -361 -362 @Override -363 public TableName[] listTableNames(Pattern pattern) throws IOException { -364 return listTableNames(pattern, false); -365 } -366 -367 @Override -368 public TableName[] listTableNames(String regex) throws IOException { -369 return listTableNames(Pattern.compile(regex), false); -370 } -371 -372 @Override -373 public TableName[] listTableNames(final Pattern pattern, final boolean includeSysTables) -374 throws IOException { -375 return executeCallable(new MasterCallable<TableName[]>(getConnection()) { -376 @Override -377 public TableName[] call(int callTimeout) throws ServiceException { -378 GetTableNamesRequest req = -379 RequestConverter.buildGetTableNamesRequest(pattern, includeSysTables); -380 return ProtobufUtil.getTableNameArray(master.getTableNames(null, req) -381 .getTableNamesList()); -382 } -383 }); -384 } -385 -386 @Override -387 public TableName[] listTableNames(final String regex, final boolean includeSysTables) -388 throws IOException { -389 return listTableNames(Pattern.compile(regex), includeSysTables); -390 } -391 -392 @Override -393 public HTableDescriptor getTableDescriptor(final TableName tableName) throws IOException { -394 return getTableDescriptor(tableName, getConnection(), rpcCallerFactory, operationTimeout); -395 } -396 -397 static HTableDescriptor getTableDescriptor(final TableName tableName, HConnection connection, -398 RpcRetryingCallerFactory rpcCallerFactory, int operationTimeout) throws IOException { -399 if (tableName == null) return null; -400 HTableDescriptor htd = executeCallable(new MasterCallable<HTableDescriptor>(connection) { -401 @Override -402 public HTableDescriptor call(int callTimeout) throws ServiceException { -403 GetTableDescriptorsResponse htds; -404 GetTableDescriptorsRequest req = -405 RequestConverter.buildGetTableDescriptorsRequest(tableName); -406 htds = master.getTableDescriptors(null, req); -407 -408 if (!htds.getTableSchemaList().isEmpty()) { -409 return HTableDescriptor.convert(htds.getTableSchemaList().get(0)); -410 } -411 return null; -412 } -413 }, rpcCallerFactory, operationTimeout); -414 if (htd != null) { -415 return htd; -416 } -417 throw new TableNotFoundException(tableName.getNameAsString()); -418 } -419 -420 private long getPauseTime(int tries) { -421 int triesCount = tries; -422 if (triesCount >= HConstants.RETRY_BACKOFF.length) { -423 triesCount = HConstants.RETRY_BACKOFF.length - 1; -424 } -425 return this.pause * HConstants.RETRY_BACKOFF[triesCount]; -426 } -427 -428 @Override -429 public void createTable(HTableDescriptor desc) -430 throws IOException { -431 createTable(desc, null); -432 } -433 -434 @Override -435 public void createTable(HTableDescriptor desc, byte [] startKey, -436 byte [] endKey, int numRegions) -437 throws IOException { -438 if(numRegions < 3) { -439 throw new IllegalArgumentException("Must create at least three regions"); -440 } else if(Bytes.compareTo(startKey, endKey) >= 0) { -441 throw new IllegalArgumentException("Start key must be smaller than end key"); -442 } -443 if (numRegions == 3) { -444 createTable(desc, new byte[][]{startKey, endKey}); -445 return; -446 } -447 byte [][] splitKeys = Bytes.split(startKey, endKey, numRegions - 3); -448 if(splitKeys == null || splitKeys.length != numRegions - 1) { -449 throw new IllegalArgumentException("Unable to split key range into enough regions"); -450 } -451 createTable(desc, splitKeys); -452 } -453 -454 @Override -455 public void createTable(final HTableDescriptor desc, byte [][] splitKeys) -456 throws IOException { -457 get(createTableAsync(desc, splitKeys), syncWaitTimeout, TimeUnit.MILLISECONDS); -458 } -459 -460 @Override -461 public Future<Void> createTableAsync(final HTableDescriptor desc, final byte[][] splitKeys) -462 throws IOException { -463 if (desc.getTableName() == null) { -464 throw new IllegalArgumentException("TableName cannot be null"); -465 } -466 if (splitKeys != null && splitKeys.length > 0) { -467 Arrays.sort(splitKeys, Bytes.BYTES_COMPARATOR); -468 // Verify there are no duplicate split keys -469 byte[] lastKey = null; -470 for (byte[] splitKey : splitKeys) { -471 if (Bytes.compareTo(splitKey, HConstants.EMPTY_BYTE_ARRAY) == 0) { -472 throw new IllegalArgumentException( -473 "Empty split key must not be passed in the split keys."); -474 } -475 if (lastKey != null && Bytes.equals(splitKey, lastKey)) { -476 throw new IllegalArgumentException("All split keys must be unique, " + -477 "found duplicate: " + Bytes.toStringBinary(splitKey) + -478 ", " + Bytes.toStringBinary(lastKey)); -479 } -480 lastKey = splitKey; -481 } -482 } -483 -484 CreateTableResponse response = executeCallable( -485 new MasterCallable<CreateTableResponse>(getConnection()) { -486 @Override -487 public CreateTableResponse call(int callTimeout) throws ServiceException { -488 CreateTableRequest request = RequestConverter.buildCreateTableRequest( -489 desc, splitKeys, ng.getNonceGroup(), ng.newNonce()); -490 return master.createTable(null, request); -491 } -492 }); -493 return new CreateTableFuture(this, desc, splitKeys, response); -494 } -495 -496 private static class CreateTableFuture extends TableFuture<Void> { -497 private final HTableDescriptor desc; -498 private final byte[][] splitKeys; -499 -500 public CreateTableFuture(final HBaseAdmin admin, final HTableDescriptor desc, -501 final byte[][] splitKeys, final CreateTableResponse response) { -502 super(admin, desc.getTableName(), -503 (response != null && response.hasProcId()) ? response.getProcId() : null); -504 this.splitKeys = splitKeys; -505 this.desc = desc; -506 } -507 -508 @Override -509 protected HTableDescriptor getTableDescriptor() { -510 return desc; -511 } -512 -513 @Override -514 public String getOperationType() { -515 return "CREATE"; -516 } -517 -518 @Override -519 protected Void waitOperationResult(final long deadlineTs) throws IOException, TimeoutException { -520 waitForTableEnabled(deadlineTs); -521 waitForAllRegionsOnline(deadlineTs, splitKeys); -522 return null; -523 } -524 } -525 -526 @Override -527 public void deleteTable(final TableName tableName) throws IOException { -528 get(deleteTableAsync(tableName), syncWaitTimeout, TimeUnit.MILLISECONDS); -529 } -530 -531 @Override -532 public Future<Void> deleteTableAsync(final TableName tableName) throws IOException { -533 DeleteTableResponse response = executeCallable( -534 new MasterCallable<DeleteTableResponse>(getConnection()) { -535 @Override -536 public DeleteTableResponse call(int callTimeout) throws ServiceException { -537 DeleteTableRequest req = -538 RequestConverter.buildDeleteTableRequest(tableName, ng.getNonceGroup(), ng.newNonce()); -539 return master.deleteTable(null,req); -540 } -541 }); -542 return new DeleteTableFuture(this, tableName, response); -543 } -544 -545 private static class DeleteTableFuture extends TableFuture<Void> { -546 public DeleteTableFuture(final HBaseAdmin admin, final TableName tableName, -547 final DeleteTableResponse response) { -548 super(admin, tableName, -549 (response != null && response.hasProcId()) ? response.getProcId() : null); -550 } -551 -552 @Override -553 public String getOperationType() { -554 return "DELETE"; -555 } -556 -557 @Override -558 protected Void waitOperationResult(final long deadlineTs) -559 throws IOException, TimeoutException { -560 waitTableNotFound(deadlineTs); -561 return null; -562 } -563 -564 @Override -565 protected Void postOperationResult(final Void result, final long deadlineTs) -566 throws IOException, TimeoutException { -567 // Delete cached information to prevent clients from using old locations -568 getAdmin().getConnection().clearRegionCache(getTableName()); -569 return super.postOperationResult(result, deadlineTs); -570 } -571 } -572 -573 @Override -574 public HTableDescriptor[] deleteTables(String regex) throws IOException { -575 return deleteTables(Pattern.compile(regex)); -576 } -577 -578 /** -579 * Delete tables matching the passed in pattern and wait on completion. -580 * -581 * Warning: Use this method carefully, there is no prompting and the effect is -582 * immediate. Consider using {@link #listTables(java.util.regex.Pattern) } and -583 * {@link #deleteTable(TableName)} -584 * -585 * @param pattern The pattern to match table names against -586 * @return Table descriptors for tables that couldn't be deleted -587 * @throws IOException -588 */ -589 @Override -590 public HTableDescriptor[] deleteTables(Pattern pattern) throws IOException { -591 List<HTableDescriptor> failed = new LinkedList<HTableDescriptor>(); -592 for (HTableDescriptor table : listTables(pattern)) { -593 try { -594 deleteTable(table.getTableName()); -595 } catch (IOException ex) { -596 LOG.info("Failed to delete table " + table.getTableName(), ex); -597 failed.add(table); -598 } -599 } -600 return failed.toArray(new HTableDescriptor[failed.size()]); -601 } -602 -603 @Override -604 public void truncateTable(final TableName tableName, final boolean preserveSplits) -605 throws IOException { -606 get(truncateTableAsync(tableName, preserveSplits), syncWaitTimeout, TimeUnit.MILLISECONDS); -607 } -608 -609 @Override -610 public Future<Void> truncateTableAsync(final TableName tableName, final boolean preserveSplits) -611 throws IOException { -612 TruncateTableResponse response = -613 executeCallable(new MasterCallable<TruncateTableResponse>(getConnection()) { -614 @Override -615 public TruncateTableResponse call(int callTimeout) throws ServiceException { -616 LOG.info("Started truncating " + tableName); -617 TruncateTableRequest req = RequestConverter.buildTruncateTableRequest( -618 tableName, preserveSplits, ng.getNonceGroup(), ng.newNonce()); -619 return master.truncateTable(null, req); -620 } -621 }); -622 return new TruncateTableFuture(this, tableName, preserveSplits, response); -623 } -624 -625 private static class TruncateTableFuture extends TableFuture<Void> { -626 private final boolean preserveSplits; -627 -628 public TruncateTableFuture(final HBaseAdmin admin, final TableName tableName, -629 final boolean preserveSplits, final TruncateTableResponse response) { -630 super(admin, tableName, -631 (response != null && response.hasProcId()) ? response.getProcId() : null); -632 this.preserveSplits = preserveSplits; -633 } -634 -635 @Override -636 public String getOperationType() { -637 return "TRUNCATE"; -638 } -639 -640 @Override -641 protected Void waitOperationResult(final long deadlineTs) throws IOException, TimeoutException { -642 waitForTableEnabled(deadlineTs); -643 // once the table is enabled, we know the operation is done. so we can fetch the splitKeys -644 byte[][] splitKeys = preserveSplits ? getAdmin().getTableSplits(getTableName()) : null; -645 waitForAllRegionsOnline(deadlineTs, splitKeys); -646 return null; -647 } -648 } -649 -650 private byte[][] getTableSplits(final TableName tableName) throws IOException { -651 byte[][] splits = null; -652 try (RegionLocator locator = getConnection().getRegionLocator(tableName)) { -653 byte[][] startKeys = locator.getStartKeys(); -654 if (startKeys.length == 1) { -655 return splits; -656 } -657 splits = new byte[startKeys.length - 1][]; -658 for (int i = 1; i < startKeys.length; i++) { -659 splits[i - 1] = startKeys[i]; -660 } -661 } -662 return splits; -663 } -664 -665 @Override -666 public void enableTable(final TableName tableName) -667 throws IOException { -668 get(enableTableAsync(tableName), syncWaitTimeout, TimeUnit.MILLISECONDS); -669 } -670 -671 /** -672 * Wait for the table to be enabled and available -673 * If enabling the table exceeds the retry period, an exception is thrown. -674 * @param tableName name of the table -675 * @throws IOException if a remote or network exception occurs or -676 * table is not enabled after the retries period. -677 */ -678 private void waitUntilTableIsEnabled(final TableName tableName) throws IOException { -679 boolean enabled = false; -680 long start = EnvironmentEdgeManager.currentTime(); -681 for (int tries = 0; tries < (this.numRetries * this.retryLongerMultiplier); tries++) { -682 try { -683 enabled = isTableEnabled(tableName); -684 } catch (TableNotFoundException tnfe) { -685 // wait for table to be created -686 enabled = false; -687 } -688 enabled = enabled && isTableAvailable(tableName); -689 if (enabled) { -690 break; -691 } -692 long sleep = getPauseTime(tries); -693 if (LOG.isDebugEnabled()) { -694 LOG.debug("Sleeping= " + sleep + "ms, waiting for all regions to be " + -695 "enabled in " + tableName); -696 } -697 try { -698 Thread.sleep(sleep); -699 } catch (InterruptedException e) { -700 // Do this conversion rather than let it out because do not want to -701 // change the method signature. -702 throw (InterruptedIOException)new InterruptedIOException("Interrupted").initCause(e); -703 } -704 } -705 if (!enabled) { -706 long msec = EnvironmentEdgeManager.currentTime() - start; -707 throw new IOException("Table '" + tableName + -708 "' not yet enabled, after " + msec + "ms."); -709 } -710 } -711 -712 @Override -713 public Future<Void> enableTableAsync(final TableName tableName) throws IOException { -714 TableName.isLegalFullyQualifiedTableName(tableName.getName()); -715 EnableTableResponse response = executeCallable( -716 new MasterCallable<EnableTableResponse>(getConnection()) { -717 @Override -718 public EnableTableResponse call(int callTimeout) throws ServiceException { -719 LOG.info("Started enable of " + tableName); -720 EnableTableRequest req = -721 RequestConverter.buildEnableTableRequest(tableName, ng.getNonceGroup(), ng.newNonce()); -722 return master.enableTable(null,req); -723 } -724 }); -725 return new EnableTableFuture(this, tableName, response); -726 } -727 -728 private static class EnableTableFuture extends TableFuture<Void> { -729 public EnableTableFuture(final HBaseAdmin admin, final TableName tableName, -730 final EnableTableResponse response) { -731 super(admin, tableName, -732 (response != null && response.hasProcId()) ? response.getProcId() : null); -733 } -734 -735 @Override -736 public String getOperationType() { -737 return "ENABLE"; -738 } -739 -740 @Override -741 protected Void waitOperationResult(final long deadlineTs) throws IOException, TimeoutException { -742 waitForTableEnabled(deadlineTs); -743 return null; -744 } -745 } -746 -747 @Override -748 public HTableDescriptor[] enableTables(String regex) throws IOException { -749 return enableTables(Pattern.compile(regex)); -750 } -751 -752 @Override -753 public HTableDescriptor[] enableTables(Pattern pattern) throws IOException { -754 List<HTableDescriptor> failed = new LinkedList<HTableDescriptor>(); -755 for (HTableDescriptor table : listTables(pattern)) { -756 if (isTableDisabled(table.getTableName())) { -757 try { -758 enableTable(table.getTableName()); -759 } catch (IOException ex) { -760 LOG.info("Failed to enable table " + table.getTableName(), ex); -761 failed.add(table); -762 } -763 } -764 } -765 return failed.toArray(new HTableDescriptor[failed.size()]); -766 } -767 -768 @Override -769 public void disableTable(final TableName tableName) -770 throws IOException { -771 get(disableTableAsync(tableName), syncWaitTimeout, TimeUnit.MILLISECONDS); -772 } -773 -774 @Override -775 public Future<Void> disableTableAsync(final TableName tableName) throws IOException { -776 TableName.isLegalFullyQualifiedTableName(tableName.getName()); -777 DisableTableResponse response = executeCallable( -778 new MasterCallable<DisableTableResponse>(getConnection()) { -779 @Override -780 public DisableTableResponse call(int callTimeout) throws ServiceException { -781 LOG.info("Started disable of " + tableName); -782 DisableTableRequest req = -783 RequestConverter.buildDisableTableRequest(tableName, ng.getNonceGroup(), ng.newNonce()); -784 return master.disableTable(null, req); -785 } -786 }); -787 return new DisableTableFuture(this, tableName, response); -788 } -789 -790 private static class DisableTableFuture extends TableFuture<Void> { -791 public DisableTableFuture(final HBaseAdmin admin, final TableName tableName, -792 final DisableTableResponse response) { -793 super(admin, tableName, -794 (response != null && response.hasProcId()) ? response.getProcId() : null); -795 } -796 -797 @Override -798 public String getOperationType() { -799 return "DISABLE"; -800 } -801 -802 @Override -803 protected Void waitOperationResult(long deadlineTs) throws IOException, TimeoutException { -804 waitForTableDisabled(deadlineTs); -805 return null; -806 } -807 } -808 -809 @Override -810 public HTableDescriptor[] disableTables(String regex) throws IOException { -811 return disableTables(Pattern.compile(regex)); -812 } -813 -814 @Override -815 public HTableDescriptor[] disableTables(Pattern pattern) throws IOException { -816 List<HTableDescriptor> failed = new LinkedList<HTableDescriptor>(); -817 for (HTableDescriptor table : listTables(pattern)) { -818 if (isTableEnabled(table.getTableName())) { -819 try { -820 disableTable(table.getTableName()); -821 } catch (IOException ex) { -822 LOG.info("Failed to disable table " + table.getTableName(), ex); -823 failed.add(table); -824 } -825 } -826 } -827 return failed.toArray(new HTableDescriptor[failed.size()]); -828 } -829 -830 @Override -831 public boolean isTableEnabled(final TableName tableName) throws IOException { -832 checkTableExists(tableName); -833 return executeCallable(new ConnectionCallable<Boolean>(getConnection()) { -834 @Override -835 public Boolean call(int callTimeout) throws ServiceException, IOException { -836 TableState tableState = MetaTableAccessor.getTableState(connection, tableName); -837 if (tableState == null) -838 throw new TableNotFoundException(tableName); -839 return tableState.inStates(TableState.State.ENABLED); -840 } -841 }); -842 } -843 -844 @Override -845 public boolean isTableDisabled(TableName tableName) throws IOException { -846 checkTableExists(tableName); -847 return connection.isTableDisabled(tableName); -848 } -849 -850 @Override -851 public boolean isTableAvailable(TableName tableName) throws IOException { -852 return connection.isTableAvailable(tableName); -853 } -854 -855 @Override -856 public boolean isTableAvailable(TableName tableName, byte[][] splitKeys) throws IOException { -857 return connection.isTableAvailable(tableName, splitKeys); -858 } -859 -860 @Override -861 public Pair<Integer, Integer> getAlterStatus(final TableName tableName) throws IOException { -862 return executeCallable(new MasterCallable<Pair<Integer, Integer>>(getConnection()) { -863 @Override -864 public Pair<Integer, Integer> call(int callTimeout) throws ServiceException { -865 GetSchemaAlterStatusRequest req = RequestConverter -866 .buildGetSchemaAlterStatusRequest(tableName); -867 GetSchemaAlterStatusResponse ret = master.getSchemaAlterStatus(null, req); -868 Pair<Integer, Integer> pair = new Pair<>(ret.getYetToUpdateRegions(), -869 ret.getTotalRegions()); -870 return pair; -871 } -872 }); -873 } -874 -875 @Override -876 public Pair<Integer, Integer> getAlterStatus(final byte[] tableName) throws IOException { -877 return getAlterStatus(TableName.valueOf(tableName)); -878 } -879 -880 /** -881 * {@inheritDoc} -882 * @deprecated Since 2.0. Will be removed in 3.0. Use -883 * {@link #addColumnFamily(TableName, HColumnDescriptor)} instead. -884 */ -885 @Override -886 @Deprecated -887 public void addColumn(final TableName tableName, final HColumnDescriptor columnFamily) -888 throws IOException { -889 addColumnFamily(tableName, columnFamily); -890 } -891 -892 @Override -893 public Future<Void> addColumnFamily(final TableName tableName, -894 final HColumnDescriptor columnFamily) throws IOException { -895 AddColumnResponse response = -896 executeCallable(new MasterCallable<AddColumnResponse>(getConnection()) { -897 @Override -898 public AddColumnResponse call(int callTimeout) throws ServiceException { -899 AddColumnRequest req = -900 RequestConverter.buildAddColumnRequest(tableName, columnFamily, ng.getNonceGroup(), -901 ng.newNonce()); -902 return master.addColumn(null, req); -903 } -904 }); -905 return new AddColumnFamilyFuture(this, tableName, response); -906 } -907 -908 private static class AddColumnFamilyFuture extends ModifyTableFuture { -909 public AddColumnFamilyFuture(final HBaseAdmin admin, final TableName tableName, -910 final AddColumnResponse response) { -911 super(admin, tableName, (response != null && response.hasProcId()) ? response.getProcId() -912 : null); -913 } -914 -915 @Override -916 public String getOperationType() { -917 return "ADD_COLUMN_FAMILY"; -918 } -919 } -920 -921 /** -922 * {@inheritDoc} -923 * @deprecated Since 2.0. Will be removed in 3.0. Use -924 * {@link #deleteColumnFamily(TableName, byte[])} instead. -925 */ -926 @Override -927 @Deprecated -928 public void deleteColumn(final TableName tableName, final byte[] columnFamily) -929 throws IOException { -930 deleteColumnFamily(tableName, columnFamily); -931 } -932 -933 @Override -934 public Future<Void> deleteColumnFamily(final TableName tableName, final byte[] columnFamily) -935 throws IOException { -936 DeleteColumnResponse response = -937 executeCallable(new MasterCallable<DeleteColumnResponse>(getConnection()) { -938 @Override -939 public DeleteColumnResponse call(int callTimeout) throws ServiceException { -940 DeleteColumnRequest req = -941 RequestConverter.buildDeleteColumnRequest(tableName, columnFamily, -942 ng.getNonceGroup(), ng.newNonce()); -943 master.deleteColumn(null, req); -944 return null; -945 } -946 }); -947 return new DeleteColumnFamilyFuture(this, tableName, response); -948 } -949 -950 private static class DeleteColumnFamilyFuture extends ModifyTableFuture { -951 public DeleteColumnFamilyFuture(final HBaseAdmin admin, final TableName tableName, -952 final DeleteColumnResponse response) { -953 super(admin, tableName, (response != null && response.hasProcId()) ? response.getProcId() -954 : null); -955 } -956 -957 @Override -958 public String getOperationType() { -959 return "DELETE_COLUMN_FAMILY"; -960 } -961 } -962 -963 /** -