Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,28 @@ default void createTable(TableDescriptor desc, byte[][] splitKeys) throws IOExce
* @throws IOException if a remote or network exception occurs
*/
default void deleteTable(TableName tableName) throws IOException {
get(deleteTableAsync(tableName), getSyncWaitTimeout(), TimeUnit.MILLISECONDS);
get(deleteTableAsync(tableName, true), getSyncWaitTimeout(), TimeUnit.MILLISECONDS);
}

/**
* Deletes a table. Synchronous operation.
* @param tableName name of table to delete
* @param archive if archive the table
* @throws IOException if a remote or network exception occurs
*/
default void deleteTable(TableName tableName, boolean archive) throws IOException {
get(deleteTableAsync(tableName, archive), getSyncWaitTimeout(), TimeUnit.MILLISECONDS);
}

/**
* backward compatible
* @param tableName name of table to delete
* @throws IOException if a remote or network exception occurs
* @return the result of the async delete. You can use Future.get(long, TimeUnit) to wait on the
* operation to complete.
*/
default Future<Void> deleteTableAsync(TableName tableName) throws IOException {
return deleteTableAsync(tableName, true);
}

/**
Expand All @@ -300,11 +321,12 @@ default void deleteTable(TableName tableName) throws IOException {
* ExecutionException if there was an error while executing the operation or TimeoutException in
* case the wait timeout was not long enough to allow the operation to complete.
* @param tableName name of table to delete
* @param archive if archive the table
* @throws IOException if a remote or network exception occurs
* @return the result of the async delete. You can use Future.get(long, TimeUnit) to wait on the
* operation to complete.
*/
Future<Void> deleteTableAsync(TableName tableName) throws IOException;
Future<Void> deleteTableAsync(TableName tableName, boolean archive) throws IOException;

/**
* Truncate a table. Synchronous operation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ public Future<Void> deleteTableAsync(TableName tableName) throws IOException {
return admin.deleteTable(tableName);
}

@Override
public Future<Void> deleteTableAsync(TableName tableName, boolean archive) throws IOException {
return admin.deleteTable(tableName, archive);
}

@Override
public Future<Void> truncateTableAsync(TableName tableName, boolean preserveSplits)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,16 @@ CompletableFuture<Void> createTable(TableDescriptor desc, byte[] startKey, byte[
* Deletes a table.
* @param tableName name of table to delete
*/
CompletableFuture<Void> deleteTable(TableName tableName);
default CompletableFuture<Void> deleteTable(TableName tableName) {
return deleteTable(tableName, true);
}

/**
* Deletes a table.
* @param tableName name of table to delete
* @param archive if need to archive the table
*/
CompletableFuture<Void> deleteTable(TableName tableName, boolean archive);

/**
* Truncate a table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ public CompletableFuture<Void> modifyTable(TableDescriptor desc) {
}

@Override
public CompletableFuture<Void> modifyTableStoreFileTracker(TableName tableName, String dstSFT) {
return wrap(rawAdmin.modifyTableStoreFileTracker(tableName, dstSFT));
public CompletableFuture<Void> deleteTable(TableName tableName, boolean archive) {
return wrap(rawAdmin.deleteTable(tableName, archive));
}

@Override
public CompletableFuture<Void> deleteTable(TableName tableName) {
return wrap(rawAdmin.deleteTable(tableName));
public CompletableFuture<Void> modifyTableStoreFileTracker(TableName tableName, String dstSFT) {
return wrap(rawAdmin.modifyTableStoreFileTracker(tableName, dstSFT));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,10 @@ ModifyTableStoreFileTrackerResponse> procedureCall(tableName,
}

@Override
public CompletableFuture<Void> deleteTable(TableName tableName) {
public CompletableFuture<Void> deleteTable(TableName tableName, boolean archive) {
return this.<DeleteTableRequest, DeleteTableResponse> procedureCall(tableName,
RequestConverter.buildDeleteTableRequest(tableName, ng.getNonceGroup(), ng.newNonce()),
RequestConverter.buildDeleteTableRequest(tableName, ng.getNonceGroup(), ng.newNonce(),
archive),
(s, c, req, done) -> s.deleteTable(c, req, done), (resp) -> resp.getProcId(),
new DeleteTableProcedureBiConsumer(tableName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ public static ReplicationProtos.TableCF[] convert(String tableCFsConfig) {
}
// 2 split to "table" and "cf1,cf2"
// for each table: "table#cf1,cf2" or "table"
Iterator<String> i = Splitter.on(':').split(tab).iterator();
List<String> pair = Splitter.on(':').splitToList(tab);
if (pair.size() > 2) {
LOG.info("incorrect format:" + tableCFsConfig);
continue;
}
assert pair.size() > 0;
Iterator<String> i = pair.iterator();
String tabName = i.next().trim();
if (tabName.length() == 0) {
LOG.info("incorrect format:" + tableCFsConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,11 +1018,12 @@ public static OfflineRegionRequest buildOfflineRegionRequest(final byte[] region
* Creates a protocol buffer DeleteTableRequest n * @return a DeleteTableRequest
*/
public static DeleteTableRequest buildDeleteTableRequest(final TableName tableName,
final long nonceGroup, final long nonce) {
final long nonceGroup, final long nonce, final boolean archive) {
DeleteTableRequest.Builder builder = DeleteTableRequest.newBuilder();
builder.setTableName(ProtobufUtil.toProtoTableName(tableName));
builder.setNonceGroup(nonceGroup);
builder.setNonce(nonce);
builder.setArchive(archive);
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ message DeleteTableRequest {
required TableName table_name = 1;
optional uint64 nonce_group = 2 [default = 0];
optional uint64 nonce = 3 [default = 0];
optional bool archive = 4 [default = true];
}

message DeleteTableResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2431,11 +2431,35 @@ private static boolean isCatalogTable(final TableName tableName) {
return tableName.equals(TableName.META_TABLE_NAME);
}

private void checkSnapshot(TableName tableName, boolean archive) throws IOException {
/*
* If decide to delete the table without archive, need to make sure the table has no snapshot
* Meanwhile, the check will scan the snapshots which will do list and open, if there is lots of
* snapshot, the performance may be impacted, should evaluate the performance between directly
* archive and snapshot scan TODO: find some any way to get if the table snapshotted or not
*/
if (!archive) {
LOG.debug(
"Scan the snapshot to check if there is snapshot for:" + tableName.getNameAsString());

// List all the snapshots
List<SnapshotDescription> snapShotslist = snapshotManager.getCompletedSnapshots();
List<String> tableList = snapShotslist.stream().map(n -> n.getTable())
.filter(c -> c.equals(tableName.getNameAsString())).collect(Collectors.toList());
if (!tableList.isEmpty() || snapshotManager.isTakingSnapshot(tableName)) {
throw new DoNotRetryIOException("There is snapshot for the table and archive is needed");
}
}
}

@Override
public long deleteTable(final TableName tableName, final long nonceGroup, final long nonce)
throws IOException {
public long deleteTable(final TableName tableName, final long nonceGroup, final long nonce,
final boolean archive) throws IOException {
checkInitialized();

// Check if there is snapshot for the table if without archive called for deleteTable
checkSnapshot(tableName, archive);

return MasterProcedureUtil
.submitProcedure(new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, nonce) {
@Override
Expand All @@ -2449,8 +2473,8 @@ protected void run() throws IOException {
// We need to wait for the procedure to potentially fail due to "prepare" sanity
// checks. This will block only the beginning of the procedure. See HBASE-19953.
ProcedurePrepareLatch latch = ProcedurePrepareLatch.createBlockingLatch();
submitProcedure(
new DeleteTableProcedure(procedureExecutor.getEnvironment(), tableName, latch));
submitProcedure(new DeleteTableProcedure(procedureExecutor.getEnvironment(), tableName,
latch, archive));
latch.await();

getMaster().getMasterCoprocessorHost().postDeleteTable(tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ public DeleteTableResponse deleteTable(RpcController controller, DeleteTableRequ
throws ServiceException {
try {
long procId = server.deleteTable(ProtobufUtil.toTableName(request.getTableName()),
request.getNonceGroup(), request.getNonce());
request.getNonceGroup(), request.getNonce(), request.getArchive());
return DeleteTableResponse.newBuilder().setProcId(procId).build();
} catch (IOException ioe) {
throw new ServiceException(ioe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,20 @@ long createTable(final TableDescriptor desc, final byte[][] splitKeys, final lon
long createSystemTable(final TableDescriptor tableDescriptor) throws IOException;

/**
* Delete a table
* Delete a table, this is used for backcompitible Unit test.
* @param tableName The table name nnn
*/
long deleteTable(final TableName tableName, final long nonceGroup, final long nonce)
throws IOException;
default long deleteTable(final TableName tableName, final long nonceGroup, final long nonce)
throws IOException {
return deleteTable(tableName, nonceGroup, nonce, true);
}

/**
* Delete a table
* @param tableName The table name nnnn
*/
long deleteTable(final TableName tableName, final long nonceGroup, final long nonce,
final boolean archive) throws IOException;

/**
* Truncate a table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class DeleteTableProcedure extends AbstractStateMachineTableProcedure<Del

private List<RegionInfo> regions;
private TableName tableName;
private boolean archive;

public DeleteTableProcedure() {
// Required by the Procedure framework to create the procedure on replay
Expand All @@ -73,8 +74,15 @@ public DeleteTableProcedure(final MasterProcedureEnv env, final TableName tableN

public DeleteTableProcedure(final MasterProcedureEnv env, final TableName tableName,
final ProcedurePrepareLatch syncLatch) {
this(env, tableName, syncLatch, true);
}

public DeleteTableProcedure(final MasterProcedureEnv env, final TableName tableName,
final ProcedurePrepareLatch syncLatch, final boolean archive) {

super(env, syncLatch);
this.tableName = tableName;
this.archive = archive;
}

@Override
Expand Down Expand Up @@ -108,7 +116,7 @@ protected Flow executeFromState(final MasterProcedureEnv env, DeleteTableState s
break;
case DELETE_TABLE_CLEAR_FS_LAYOUT:
LOG.debug("Deleting regions from filesystem for {}", this);
DeleteTableProcedure.deleteFromFs(env, getTableName(), regions, true);
DeleteTableProcedure.deleteFromFs(env, getTableName(), regions, archive);
setNextState(DeleteTableState.DELETE_TABLE_REMOVE_FROM_META);
break;
case DELETE_TABLE_REMOVE_FROM_META:
Expand Down Expand Up @@ -298,7 +306,7 @@ protected static void deleteFromFs(final MasterProcedureEnv env, final TableName
Path mobTableDir =
CommonFSUtils.getTableDir(new Path(mfs.getRootDir(), MobConstants.MOB_DIR_NAME), tableName);
Path regionDir = new Path(mobTableDir, MobUtils.getMobRegionInfo(tableName).getEncodedName());
if (fs.exists(regionDir)) {
if (fs.exists(regionDir) && archive) {
HFileArchiver.archiveRegion(fs, mfs.getRootDir(), mobTableDir, regionDir);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,20 @@ public void deleteTable(TableName tableName) throws IOException {
getAdmin().deleteTable(tableName);
}

/**
* Drop an existing table
* @param tableName existing table
* @param archive if archive the data when delete the table
*/
public void deleteTable(TableName tableName, boolean archive) throws IOException {
try {
getAdmin().disableTable(tableName);
} catch (TableNotEnabledException e) {
LOG.debug("Table: " + tableName + " already disabled, so just deleting it.");
}
getAdmin().deleteTable(tableName, archive);
}

/**
* Drop an existing table
* @param tableName existing table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ public long deleteTable(final TableName tableName, final long nonceGroup, final
return -1;
}

@Override
public long deleteTable(final TableName tableName, final long nonceGroup, final long nonce,
final boolean archive) throws IOException {
return -1;
}

@Override
public long truncateTable(final TableName tableName, final boolean preserveSplits,
final long nonceGroup, final long nonce) throws IOException {
Expand Down
Loading