Skip to content

Commit 573e805

Browse files
author
Venu Reddy
committed
HIVE-29522: Prevent cleaner from creating COMPLETED_COMPACTIONS entries for soft-deleted ACID tables
1 parent 291cfd1 commit 573e805

5 files changed

Lines changed: 26 additions & 2 deletions

File tree

standalone-metastore/metastore-common/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/hive_metastoreConstants.java

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,4 +1344,9 @@ public static String getHttpPath(String httpPath) {
13441344
public static boolean isDatabaseRemote(Database db) {
13451345
return db != null && db.getType() == DatabaseType.REMOTE;
13461346
}
1347+
1348+
/**
1349+
* Soft delete operation types.
1350+
*/
1351+
public enum SoftDeleteOperation {DROP_DATABASE, DROP_TABLE}
13471352
}

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/AcidEventListener.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.hadoop.hive.metastore.events.DropTableEvent;
4040
import org.apache.hadoop.hive.metastore.txn.TxnStore;
4141
import org.apache.hadoop.hive.metastore.txn.TxnUtils;
42+
import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
4243

4344
import java.io.IOException;
4445
import java.util.Iterator;
@@ -91,6 +92,7 @@ public void onDropTable(DropTableEvent tableEvent) throws MetaException {
9192
rqst.setRunas(TxnUtils.findUserToRunAs(table.getSd().getLocation(), table, conf));
9293
rqst.putToProperties("location", table.getSd().getLocation());
9394
rqst.putToProperties("ifPurge", Boolean.toString(isMustPurge(tableEvent.getEnvironmentContext(), table)));
95+
addSoftDeletePropertiesToRequest(tableEvent.getEnvironmentContext(), rqst);
9496
txnHandler.submitForCleanup(rqst, table.getWriteId(), currentTxn);
9597
} catch (InterruptedException | IOException e) {
9698
throwMetaException(e);
@@ -244,4 +246,10 @@ private long getTxnId(EnvironmentContext context) {
244246
.map(Long::parseLong)
245247
.orElse(0L);
246248
}
249+
250+
private void addSoftDeletePropertiesToRequest(EnvironmentContext context, CompactionRequest request) {
251+
request.putToProperties(hive_metastoreConstants.SOFT_DELETE_OPERATION,
252+
Optional.ofNullable(context.getProperties().get(hive_metastoreConstants.SOFT_DELETE_OPERATION))
253+
.orElse(MetaStoreUtils.SoftDeleteOperation.DROP_TABLE.name()));
254+
}
247255
}

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/entities/CompactionInfo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.hadoop.hive.common.ValidCompactorWriteIdList;
2222
import org.apache.hadoop.hive.metastore.api.CompactionInfoStruct;
2323
import org.apache.hadoop.hive.metastore.api.CompactionType;
24+
import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants;
2425
import org.apache.hadoop.hive.metastore.api.MetaException;
2526
import org.apache.hadoop.hive.metastore.api.OptionalCompactionInfoStruct;
2627
import org.apache.hadoop.hive.metastore.api.TableValidWriteIds;
@@ -368,4 +369,8 @@ public void setWriteIds(boolean hasUncompactedAborts, Set<Long> writeIds) {
368369
public boolean isAbortedTxnCleanup() {
369370
return type == CompactionType.ABORT_TXN_CLEANUP;
370371
}
372+
373+
public boolean isSoftDelete() {
374+
return getProperty(hive_metastoreConstants.SOFT_DELETE_OPERATION) != null;
375+
}
371376
}

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/jdbc/functions/MarkCleanedFunction.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public MarkCleanedFunction(CompactionInfo info) {
5050
public Void execute(MultiDataSourceJdbcResource jdbcResource) throws MetaException {
5151
NamedParameterJdbcTemplate jdbcTemplate = jdbcResource.getJdbcTemplate();
5252
MapSqlParameterSource param;
53-
if (!info.isAbortedTxnCleanup()) {
53+
if (!info.isAbortedTxnCleanup() && !info.isSoftDelete()) {
5454
param = new MapSqlParameterSource()
5555
.addValue("id", info.id)
5656
.addValue("succeeded", Character.toString(SUCCEEDED_STATE), Types.CHAR);
@@ -85,6 +85,10 @@ public Void execute(MultiDataSourceJdbcResource jdbcResource) throws MetaExcepti
8585
*/
8686
removeCompactionAndAbortRetryEntries(info, jdbcTemplate);
8787

88+
if (info.isSoftDelete()) {
89+
return null;
90+
}
91+
8892
if (!info.isAbortedTxnCleanup()) {
8993
// Remove entries from completed_txn_components as well, so we don't start looking there
9094
// again but only up to the highest write ID include in this compaction job.
@@ -175,7 +179,7 @@ private void removeCompactionAndAbortRetryEntries(CompactionInfo info, NamedPara
175179
String deleteQuery = """
176180
DELETE FROM "COMPACTION_QUEUE" WHERE "CQ_ID" = :id
177181
""";
178-
if (!info.isAbortedTxnCleanup()) {
182+
if (!info.isAbortedTxnCleanup() && !info.isSoftDelete()) {
179183
deleteQuery += """
180184
OR ("CQ_DATABASE" = :db AND "CQ_TABLE" = :table
181185
AND (:partition is NULL OR "CQ_PARTITION" = :partition)

0 commit comments

Comments
 (0)