Skip to content

Commit

Permalink
use correct identity to initiate delete in HDFS
Browse files Browse the repository at this point in the history
  • Loading branch information
wliufle authored and phd3 committed Sep 8, 2022
1 parent c4434ed commit 134d14b
Showing 1 changed file with 4 additions and 4 deletions.
Expand Up @@ -139,8 +139,6 @@ public class ThriftHiveMetastore

private static final String DEFAULT_METASTORE_USER = "presto";

private final HdfsContext hdfsContext = new HdfsContext(ConnectorIdentity.ofUser(DEFAULT_METASTORE_USER));

private final Optional<ConnectorIdentity> identity;
private final HdfsEnvironment hdfsEnvironment;
private final IdentityAwareMetastoreClientFactory metastoreClientFactory;
Expand Down Expand Up @@ -955,7 +953,7 @@ public void dropTable(String databaseName, String tableName, boolean deleteData)
client.dropTable(databaseName, tableName, deleteData);
String tableLocation = table.getSd().getLocation();
if (deleteFilesOnDrop && deleteData && isManagedTable(table) && !isNullOrEmpty(tableLocation)) {
deleteDirRecursive(hdfsContext, hdfsEnvironment, new Path(tableLocation));
deleteDirRecursive(new Path(tableLocation));
}
}
return null;
Expand All @@ -972,9 +970,11 @@ public void dropTable(String databaseName, String tableName, boolean deleteData)
}
}

private static void deleteDirRecursive(HdfsContext context, HdfsEnvironment hdfsEnvironment, Path path)
private void deleteDirRecursive(Path path)
{
try {
HdfsContext context = new HdfsContext(identity.orElseGet(() ->
ConnectorIdentity.ofUser(DEFAULT_METASTORE_USER)));
hdfsEnvironment.getFileSystem(context, path).delete(path, true);
}
catch (IOException | RuntimeException e) {
Expand Down

0 comments on commit 134d14b

Please sign in to comment.