Skip to content
Merged
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 @@ -276,6 +276,7 @@
import static io.trino.plugin.hive.util.HiveUtil.toPartitionValues;
import static io.trino.plugin.hive.util.HiveUtil.verifyPartitionTypeSupported;
import static io.trino.plugin.hive.util.HiveWriteUtils.checkTableIsWritable;
import static io.trino.plugin.hive.util.HiveWriteUtils.checkedDelete;
import static io.trino.plugin.hive.util.HiveWriteUtils.initializeSerializer;
import static io.trino.plugin.hive.util.HiveWriteUtils.isFileCreatedByQuery;
import static io.trino.plugin.hive.util.HiveWriteUtils.isS3FileSystem;
Expand Down Expand Up @@ -1966,7 +1967,7 @@ private void removeNonCurrentQueryFiles(ConnectorSession session, Path partition
while (iterator.hasNext()) {
Path file = iterator.next().getPath();
if (!isFileCreatedByQuery(file.getName(), queryId)) {
fileSystem.delete(file, false);
checkedDelete(fileSystem, file, false);
}
}
}
Expand Down Expand Up @@ -2247,7 +2248,10 @@ private void finishOptimize(ConnectorSession session, ConnectorTableExecuteHandl
if (firstScannedPath.isEmpty()) {
firstScannedPath = Optional.of(scannedPath);
}
retry().run("delete " + scannedPath, () -> fs.delete(scannedPath, false));
retry().run("delete " + scannedPath, () -> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have an integration test based on minio showcasing this fix?

https://docs.min.io/docs/minio-multi-user-quickstart-guide.html

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice - but I do not have resources to do that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the tricky part is that this delete call spots themselves are in error handling code paths - which would make test setup cumbersome.

checkedDelete(fs, scannedPath, false);
return null;
});
someDeleted = true;
remainingFilesToDelete.remove(scannedPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
import static io.trino.plugin.hive.metastore.MetastoreUtil.buildInitialPrivilegeSet;
import static io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.NUM_ROWS;
import static io.trino.plugin.hive.util.HiveUtil.toPartitionValues;
import static io.trino.plugin.hive.util.HiveWriteUtils.checkedDelete;
import static io.trino.plugin.hive.util.HiveWriteUtils.createDirectory;
import static io.trino.plugin.hive.util.HiveWriteUtils.isFileCreatedByQuery;
import static io.trino.plugin.hive.util.HiveWriteUtils.pathExists;
Expand Down Expand Up @@ -3660,7 +3661,7 @@ public static void cleanExtraOutputFiles(HdfsEnvironment hdfsEnvironment, HdfsCo
while (filesToDeleteIterator.hasNext()) {
String fileName = filesToDeleteIterator.next();
log.debug("Deleting failed attempt file %s/%s for query %s", path, fileName, queryId);
fileSystem.delete(new Path(path, fileName), false);
checkedDelete(fileSystem, new Path(path, fileName), false);
deletedFilesBuilder.add(fileName);
filesToDeleteIterator.remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import org.apache.hadoop.mapred.Reporter;
import org.joda.time.DateTimeZone;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
Expand Down Expand Up @@ -605,6 +606,22 @@ public static void createDirectory(HdfsContext context, HdfsEnvironment hdfsEnvi
}
}

public static void checkedDelete(FileSystem fileSystem, Path file, boolean recursive)
throws IOException
{
try {
if (!fileSystem.delete(file, recursive)) {
if (fileSystem.exists(file)) {
// only throw exception if file still exists
throw new IOException("Failed to delete " + file);
}
}
}
catch (FileNotFoundException ignored) {
// ok
}
}

public static boolean isWritableType(HiveType hiveType)
{
return isWritableType(hiveType.getTypeInfo());
Expand Down