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,29 @@ 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 +322,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 @@ -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,14 +147,13 @@ public CompletableFuture<Void> modifyTable(TableDescriptor desc) {
}

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

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

@Override
public CompletableFuture<Void> truncateTable(TableName tableName, boolean preserveSplits) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,9 @@ 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 @@ -1017,12 +1017,16 @@ 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) {
public static DeleteTableRequest buildDeleteTableRequest(
final TableName tableName,
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,27 +2431,57 @@ 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();

return MasterProcedureUtil
.submitProcedure(new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, nonce) {
@Override
protected void run() throws IOException {
getMaster().getMasterCoprocessorHost().preDeleteTable(tableName);
//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
protected void run() throws IOException {
getMaster().getMasterCoprocessorHost().preDeleteTable(tableName);

LOG.info(getClientIdAuditPrefix() + " delete " + tableName);

// TODO: We can handle/merge duplicate request
//
// 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));
latch.await();
// TODO: We can handle/merge duplicate request
//
// 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, archive));
latch.await();

getMaster().getMasterCoprocessorHost().postDeleteTable(tableName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,8 @@ public DeleteSnapshotResponse deleteSnapshot(RpcController controller,
public DeleteTableResponse deleteTable(RpcController controller, DeleteTableRequest request)
throws ServiceException {
try {
long procId = server.deleteTable(ProtobufUtil.toTableName(request.getTableName()),
request.getNonceGroup(), request.getNonce());
long procId = master.deleteTable(ProtobufUtil.toTableName(
request.getTableName()), 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 @@ -137,12 +137,33 @@ long createTable(final TableDescriptor desc, final byte[][] splitKeys, final lon
*/
long createSystemTable(final TableDescriptor tableDescriptor) throws IOException;

/**
* Delete a table, this is used for backcompitible Unit test.
* @param tableName The table name
* @param nonceGroup
* @param 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 nnn
*/
long deleteTable(final TableName tableName, final long nonceGroup, final long nonce)
throws IOException;
* @param tableName The table name
* @param nonceGroup
* @param nonce
* @param archive
* @throws IOException
*/
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 @@ -72,9 +73,15 @@ public DeleteTableProcedure(final MasterProcedureEnv env, final TableName tableN
}

public DeleteTableProcedure(final MasterProcedureEnv env, final TableName tableName,
final ProcedurePrepareLatch syncLatch) {
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 +115,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 +305,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 @@ -248,8 +248,20 @@ public long deleteTable(final TableName tableName, final long nonceGroup, final
}

@Override
public long truncateTable(final TableName tableName, final boolean preserveSplits,
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 {
return -1;
}

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

Expand Down
Loading