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 @@ -288,7 +288,7 @@ public void close() throws Exception {
for (DataFileMeta file : compactAfter) {
// appendOnlyCompactManager will rewrite the file and no file upgrade will occur, so we
// can directly delete the file in compactAfter.
fileIO.deleteQuietly(pathFactory.toPath(file));
file.collectFiles(pathFactory).forEach(fileIO::deleteQuietly);
}

sinkWriter.close();
Expand All @@ -315,7 +315,7 @@ public void toBufferedWriter() throws Exception {
} finally {
// remove small files
for (DataFileMeta file : files) {
fileIO.deleteQuietly(pathFactory.toPath(file));
file.collectFiles(pathFactory).forEach(fileIO::deleteQuietly);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ public void abort(List<CommitMessage> commitMessages) {
dataFilesToDelete.addAll(commitMessage.compactIncrement().changelogFiles());

for (DataFileMeta file : dataFilesToDelete) {
fileIO.deleteQuietly(dataPathFactory.toPath(file));
file.collectFiles(dataPathFactory).forEach(fileIO::deleteQuietly);
}

List<IndexFileMeta> indexFilesToDelete = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ public void testCloseUnexpectedly() throws Exception {
writer.write(row(j, String.format("%03d", j), PART));
}
writer.sync();
assertThat(Files.walk(tempDir).filter(Files::isRegularFile))
.anyMatch(path -> path.getFileName().toString().endsWith(".index"));

// writer closed unexpectedly
writer.close();
Expand Down Expand Up @@ -1321,6 +1323,8 @@ private DataFileMeta generateCompactAfter(List<DataFileMeta> toCompact) throws I
long maxSeq = toCompact.get(size - 1).maxSequenceNumber();
Path path = pathFactory.newPath("compact-");
LocalFileIO.create().newOutputStream(path, false).close();
Path extraPath = new Path(path.getParent(), path.getName() + ".index");
LocalFileIO.create().newOutputStream(extraPath, false).close();
return DataFileMeta.forAppend(
path.getName(),
toCompact.stream().mapToLong(DataFileMeta::fileSize).sum(),
Expand Down Expand Up @@ -1350,7 +1354,7 @@ private DataFileMeta generateCompactAfter(List<DataFileMeta> toCompact) throws I
minSeq,
maxSeq,
toCompact.get(0).schemaId(),
Collections.emptyList(),
Collections.singletonList(extraPath.getName()),
null,
FileSource.APPEND,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.paimon.index.IndexPathFactory;
import org.apache.paimon.io.CompactIncrement;
import org.apache.paimon.io.DataFileMeta;
import org.apache.paimon.io.DataFilePathFactory;
import org.apache.paimon.io.DataIncrement;
import org.apache.paimon.manifest.FileKind;
import org.apache.paimon.manifest.IndexManifestEntry;
Expand Down Expand Up @@ -1127,6 +1128,66 @@ public void testAbortIndexFiles() throws Exception {
assertThat(store.fileIO().exists(compactDeletedPath)).isTrue();
}

@Test
public void testAbortDataFileWithExtraFiles() throws Exception {
TestAppendFileStore store = TestAppendFileStore.createAppendStore(tempDir, new HashMap<>());
BinaryRow partition = gen.getPartition(gen.next());
DataFilePathFactory pathFactory =
store.pathFactory().createDataFilePathFactory(partition, 0);

Path dataNewPath = pathFactory.newPath();
DataFileMeta dataNew = createDataFileWithExtraFile(store, dataNewPath, false);
Path compactNewPath = new Path(tempDir.resolve("external-compact-new.orc").toUri());
DataFileMeta compactNew = createDataFileWithExtraFile(store, compactNewPath, true);

CommitMessage commitMessage =
new CommitMessageImpl(
partition,
0,
store.options().bucket(),
new DataIncrement(
Collections.singletonList(dataNew),
Collections.emptyList(),
Collections.emptyList()),
new CompactIncrement(
Collections.emptyList(),
Collections.singletonList(compactNew),
Collections.emptyList()));

try (FileStoreCommitImpl commit = store.newCommit()) {
commit.abort(Collections.singletonList(commitMessage));
}

for (Path path : dataNew.collectFiles(pathFactory)) {
assertThat(store.fileIO().exists(path)).isFalse();
}
for (Path path : compactNew.collectFiles(pathFactory)) {
assertThat(store.fileIO().exists(path)).isFalse();
}
}

private static DataFileMeta createDataFileWithExtraFile(
TestAppendFileStore store, Path path, boolean external) throws Exception {
store.fileIO().newOutputStream(path, false).close();
Path extraPath = new Path(path.getParent(), path.getName() + ".index");
store.fileIO().newOutputStream(extraPath, false).close();
return DataFileMeta.forAppend(
path.getName(),
0,
0,
EMPTY_STATS,
0,
0,
0,
Collections.singletonList(extraPath.getName()),
null,
null,
null,
external ? path.toString() : null,
null,
null);
}

private static IndexFileMeta createIndexFile(
TestAppendFileStore store, Path path, boolean external) throws Exception {
store.fileIO().newOutputStream(path, false).close();
Expand Down
Loading