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 @@ -83,4 +83,7 @@ public void discard(FileIO fileIO) throws IOException {
public Path targetFilePath() {
return new Path(objectName);
}

@Override
public void clean(FileIO fileIO) throws IOException {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/
@Public
public class RenamingTwoPhaseOutputStream extends TwoPhaseOutputStream {
private static final String TEMP_DIR_NAME = "_temporary";

private final Path targetPath;
private final Path tempPath;
Expand Down Expand Up @@ -87,12 +88,12 @@ public Committer closeForCommit() throws IOException {
* directory as the target with a unique suffix.
*/
private Path generateTempPath(Path targetPath) {
String tempFileName = ".tmp." + UUID.randomUUID();
String tempFileName = TEMP_DIR_NAME + "/.tmp." + UUID.randomUUID();
return new Path(targetPath.getParent(), tempFileName);
}

/** Committer implementation that renames temporary file to target path. */
private static class TempFileCommitter implements Committer {
public static class TempFileCommitter implements Committer {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -132,5 +133,13 @@ public void discard(FileIO fileIO) throws IOException {
public Path targetFilePath() {
return targetPath;
}

@Override
public void clean(FileIO fileIO) throws IOException {
Path path = tempPath.getParent();
if (fileIO.exists(path)) {
fileIO.deleteQuietly(path);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you should use deleteDirectoryQuietly.

}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ public interface Committer extends Serializable {
void discard(FileIO fileIO) throws IOException;

Path targetFilePath();

void clean(FileIO fileIO) throws IOException;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ public void discard(FileIO fileIO) throws IOException {
public Path targetFilePath() {
return new Path(objectName);
}

@Override
public void clean(FileIO fileIO) throws IOException {}
}

private static final class TestPart {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public void commit(List<CommitMessage> commitMessages) {
for (TwoPhaseOutputStream.Committer committer : committers) {
committer.commit(this.fileIO);
}
for (TwoPhaseOutputStream.Committer committer : committers) {
committer.clean(this.fileIO);
}

} catch (Exception e) {
this.abort(commitMessages);
throw new RuntimeException(e);
Expand Down
Loading