Skip to content
Closed
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 @@ -109,7 +109,10 @@ public OrphanFilesClean(FileStoreTable table, long olderThanMillis, boolean dryR
}

protected List<String> validBranches() {
List<String> branches = table.branchManager().branches();
// The branch manager may return an immutable list (the REST branch manager returns
// Collections.emptyList() for a branchless table), so copy it before adding the main
// branch.
List<String> branches = new ArrayList<>(table.branchManager().branches());

List<String> abnormalBranches = new ArrayList<>();
for (String branch : branches) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
import org.apache.paimon.types.DataTypes;
import org.apache.paimon.types.RowKind;
import org.apache.paimon.types.RowType;
import org.apache.paimon.utils.BranchManager;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

Expand All @@ -68,6 +70,36 @@ public void testOlderThanMillis() {
"The arg olderThan must be less than now, because dataFiles that are currently being written and not referenced by snapshots will be mistakenly cleaned up.");
}

@Test
public void testValidBranchesDoesNotMutateManagerList() throws Exception {
Path tablePath = new Path(tempDir.newFolder().toURI());
FileIO fileIO = LocalFileIO.create();
RowType rowType = RowType.of(DataTypes.INT(), DataTypes.STRING());
TableSchema tableSchema =
SchemaUtils.forceCommit(
new FileSystemSchemaManager(fileIO, tablePath),
new Schema(
rowType.getFields(),
Collections.<String>emptyList(),
Collections.<String>emptyList(),
new Options().toMap(),
""));
FileStoreTable real = FileStoreTableFactory.create(fileIO, tablePath, tableSchema);

// REST catalogs hand out an immutable empty list for branch-less tables; the
// cleaner must not try to add the main branch to that shared list
BranchManager branchManager = org.mockito.Mockito.mock(BranchManager.class);
org.mockito.Mockito.when(branchManager.branches()).thenReturn(Collections.emptyList());
FileStoreTable table =
org.mockito.Mockito.mock(
FileStoreTable.class, org.mockito.AdditionalAnswers.delegatesTo(real));
org.mockito.Mockito.doReturn(branchManager).when(table).branchManager();

List<String> valid = new LocalOrphanFilesClean(table).validBranches();

assertThat(valid).containsExactly("main");
}

@Test
public void testListPaimonFileDirsWithEmptyPartition() throws Exception {
Path tablePath = new Path(tempDir.newFolder().toURI());
Expand Down
Loading