Skip to content

Commit e455b50

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

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.hadoop.hive.metastore;
2020

2121
import org.apache.hadoop.conf.Configuration;
22+
import org.apache.hadoop.hive.common.AcidConstants;
2223
import org.apache.hadoop.hive.metastore.api.CompactionRequest;
2324
import org.apache.hadoop.hive.metastore.api.CompactionType;
2425
import org.apache.hadoop.hive.metastore.api.Database;
@@ -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+
rqst.putToProperties(AcidConstants.SOFT_DELETE_TABLE, Boolean.TRUE.toString());
9496
txnHandler.submitForCleanup(rqst, table.getWriteId(), currentTxn);
9597
} catch (InterruptedException | IOException e) {
9698
throwMetaException(e);

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
@@ -18,6 +18,7 @@
1818
package org.apache.hadoop.hive.metastore.txn.entities;
1919

2020
import org.apache.commons.lang3.builder.ToStringBuilder;
21+
import org.apache.hadoop.hive.common.AcidConstants;
2122
import org.apache.hadoop.hive.common.ValidCompactorWriteIdList;
2223
import org.apache.hadoop.hive.metastore.api.CompactionInfoStruct;
2324
import org.apache.hadoop.hive.metastore.api.CompactionType;
@@ -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 "true".equalsIgnoreCase(getProperty(AcidConstants.SOFT_DELETE_TABLE));
375+
}
371376
}

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

Lines changed: 6 additions & 4 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,7 +85,7 @@ public Void execute(MultiDataSourceJdbcResource jdbcResource) throws MetaExcepti
8585
*/
8686
removeCompactionAndAbortRetryEntries(info, jdbcTemplate);
8787

88-
if (!info.isAbortedTxnCleanup()) {
88+
if (!info.isAbortedTxnCleanup() && !info.isSoftDelete()) {
8989
// Remove entries from completed_txn_components as well, so we don't start looking there
9090
// again but only up to the highest write ID include in this compaction job.
9191
//highestWriteId will be NULL in upgrade scenarios
@@ -121,7 +121,9 @@ public Void execute(MultiDataSourceJdbcResource jdbcResource) throws MetaExcepti
121121
}
122122

123123
// Do cleanup of metadata in TXN_COMPONENTS table.
124-
removeTxnComponents(info, jdbcResource);
124+
if (!info.isSoftDelete()) {
125+
removeTxnComponents(info, jdbcResource);
126+
}
125127
return null;
126128
}
127129

@@ -175,7 +177,7 @@ private void removeCompactionAndAbortRetryEntries(CompactionInfo info, NamedPara
175177
String deleteQuery = """
176178
DELETE FROM "COMPACTION_QUEUE" WHERE "CQ_ID" = :id
177179
""";
178-
if (!info.isAbortedTxnCleanup()) {
180+
if (!info.isAbortedTxnCleanup() && !info.isSoftDelete()) {
179181
deleteQuery += """
180182
OR ("CQ_DATABASE" = :db AND "CQ_TABLE" = :table
181183
AND (:partition is NULL OR "CQ_PARTITION" = :partition)

0 commit comments

Comments
 (0)