Skip to content

Commit cdc1124

Browse files
author
Venu Reddy
committed
Reworked for comments
1 parent 7dc7832 commit cdc1124

8 files changed

Lines changed: 27 additions & 27 deletions

File tree

ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/CleanupRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public CleanupRequest(CleanupRequestBuilder builder) {
4040
this.location = builder.location;
4141
this.obsoleteDirs = builder.obsoleteDirs;
4242
this.purge = builder.purge;
43-
this.softDelete = builder.isSoftDelete;
43+
this.softDelete = builder.softDelete;
4444
this.sourceOfReplication = builder.sourceOfReplication;
4545
this.runAs = builder.runAs;
4646
this.dbName = builder.dbName;
@@ -86,7 +86,7 @@ public static class CleanupRequestBuilder {
8686
private String location;
8787
private List<Path> obsoleteDirs;
8888
private boolean purge;
89-
private boolean isSoftDelete;
89+
private boolean softDelete;
9090
private boolean sourceOfReplication;
9191
private String runAs;
9292
private String dbName;
@@ -108,7 +108,7 @@ public CleanupRequestBuilder setPurge(boolean purge) {
108108
}
109109

110110
public CleanupRequestBuilder setSoftDelete(boolean softDelete) {
111-
this.isSoftDelete = softDelete;
111+
this.softDelete = softDelete;
112112
return this;
113113
}
114114

ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/FSRemover.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
*/
1818
package org.apache.hadoop.hive.ql.txn.compactor;
1919

20-
import org.apache.hadoop.fs.FileStatus;
2120
import org.apache.hadoop.fs.FileSystem;
2221
import org.apache.hadoop.fs.Path;
23-
import org.apache.hadoop.hive.common.AcidConstants;
2422
import org.apache.hadoop.hive.conf.HiveConf;
2523
import org.apache.hadoop.hive.metastore.ReplChangeManager;
2624
import org.apache.hadoop.hive.metastore.api.Database;
@@ -138,15 +136,11 @@ private void removeDatabaseDirIfNecessary(Database db, CleanupRequest cr, FileSy
138136
return;
139137
}
140138
Path databasePath = new Path(cr.getLocation()).getParent();
141-
for (FileStatus status : fs.listStatus(databasePath)) {
142-
if (status.isDirectory() &&
143-
status.getPath().getName().matches("(.*)" + AcidConstants.SOFT_DELETE_TABLE_PATTERN)) {
144-
return;
139+
if (FileUtils.isDirEmpty(fs, databasePath)) {
140+
if (cr.isSourceOfReplication()) {
141+
replChangeManager.recycle(databasePath, ReplChangeManager.RecycleType.MOVE, cr.isPurge());
145142
}
143+
FileUtils.deleteDir(fs, databasePath, cr.isPurge(), conf);
146144
}
147-
if (cr.isSourceOfReplication()) {
148-
replChangeManager.recycle(databasePath, ReplChangeManager.RecycleType.MOVE, cr.isPurge());
149-
}
150-
FileUtils.deleteDir(fs, databasePath, cr.isPurge(), conf);
151145
}
152146
}

ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.hadoop.hive.ql;
1919

2020
import java.io.File;
21+
import java.io.FileNotFoundException;
2122
import java.io.FileOutputStream;
2223
import java.io.IOException;
2324
import java.util.ArrayList;
@@ -1827,11 +1828,9 @@ private void dropDatabaseCascadeNonBlocking() throws Exception {
18271828

18281829
runCleaner(hiveConf);
18291830

1830-
stat = fs.listStatus(new Path(getWarehouseDir(), database + ".db"),
1831-
t -> t.getName().matches("(mv_)?" + tableName + "2" + SOFT_DELETE_TABLE_PATTERN));
1832-
if (stat.length != 0) {
1833-
Assert.fail("Table data was not removed from FS");
1834-
}
1831+
Assert.assertThrows(database + ".db directory should not exist", FileNotFoundException.class, () -> {
1832+
fs.listStatus(new Path(getWarehouseDir(), database + ".db"));
1833+
});
18351834
}
18361835

18371836
@Test

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

Lines changed: 1 addition & 1 deletion
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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.hadoop.hive.metastore.events.DropTableEvent;
4141
import org.apache.hadoop.hive.metastore.txn.TxnStore;
4242
import org.apache.hadoop.hive.metastore.txn.TxnUtils;
43+
import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
4344

4445
import java.io.IOException;
4546
import java.util.Iterator;
@@ -248,11 +249,11 @@ private long getTxnId(EnvironmentContext context) {
248249
}
249250

250251
private void addSoftDeletePropertiesToRequest(EnvironmentContext context, CompactionRequest request) {
251-
if ("true".equalsIgnoreCase(context.getProperties().get(hive_metastoreConstants.SOFT_DELETE_DATABASE))) {
252-
request.putToProperties(hive_metastoreConstants.SOFT_DELETE_DATABASE, Boolean.TRUE.toString());
253-
if ("true".equalsIgnoreCase(context.getProperties().get(ReplConst.SOURCE_OF_REPLICATION))) {
254-
request.putToProperties(ReplConst.SOURCE_OF_REPLICATION, Boolean.TRUE.toString());
255-
}
252+
request.putToProperties(hive_metastoreConstants.SOFT_DELETE_OPERATION,
253+
Optional.ofNullable(context.getProperties().get(hive_metastoreConstants.SOFT_DELETE_OPERATION))
254+
.orElse(MetaStoreUtils.SoftDeleteOperation.drop_table.name()));
255+
if (Boolean.parseBoolean(context.getProperties().get(ReplConst.SOURCE_OF_REPLICATION))) {
256+
request.putToProperties(ReplConst.SOURCE_OF_REPLICATION, Boolean.TRUE.toString());
256257
}
257258
}
258259
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ public DropDatabaseResult execute() throws TException, IOException {
137137
if (isSoftDelete) {
138138
context = new EnvironmentContext();
139139
context.putToProperties(hive_metastoreConstants.TXN_ID, String.valueOf(request.getTxnId()));
140-
context.putToProperties(hive_metastoreConstants.SOFT_DELETE_DATABASE, Boolean.TRUE.toString());
140+
context.putToProperties(hive_metastoreConstants.SOFT_DELETE_OPERATION,
141+
MetaStoreUtils.SoftDeleteOperation.drop_database.name());
141142
if (ReplChangeManager.isSourceOfReplication(db)) {
142143
context.putToProperties(ReplConst.SOURCE_OF_REPLICATION, Boolean.TRUE.toString());
143144
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,10 @@ public boolean isAbortedTxnCleanup() {
372372
}
373373

374374
public boolean isSoftDelete() {
375-
return "true".equalsIgnoreCase(getProperty(hive_metastoreConstants.SOFT_DELETE_DATABASE));
375+
return getProperty(hive_metastoreConstants.SOFT_DELETE_OPERATION) != null;
376376
}
377377

378378
public boolean isSourceOfReplication() {
379-
return "true".equalsIgnoreCase(getProperty(ReplConst.SOURCE_OF_REPLICATION));
379+
return Boolean.parseBoolean(getProperty(ReplConst.SOURCE_OF_REPLICATION));
380380
}
381381
}

0 commit comments

Comments
 (0)