Skip to content
Open
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 @@ -18,6 +18,7 @@

package org.apache.paimon.sort;

import org.apache.paimon.CoreOptions;
import org.apache.paimon.compression.BlockCompressionFactory;
import org.apache.paimon.data.AbstractPagedOutputView;
import org.apache.paimon.disk.ChannelReaderInputView;
Expand All @@ -37,6 +38,8 @@
import java.util.Comparator;
import java.util.List;

import static org.apache.paimon.utils.Preconditions.checkArgument;

/**
* Spilled files Merger of {@link BinaryExternalSortBuffer}. It merges {@link #maxFanIn} spilled
* files at most once.
Expand Down Expand Up @@ -64,6 +67,12 @@ public AbstractBinaryExternalMerger(
SpillChannelManager channelManager,
BlockCompressionFactory compressionCodecFactory,
int compressionBlockSize) {
checkArgument(
maxFanIn >= 2,
"The fan-in for external merge sort must be at least 2, but was %s. "
+ "Please adjust '%s'.",
maxFanIn,
CoreOptions.LOCAL_SORT_MAX_NUM_FILE_HANDLES.key());
this.ioManager = ioManager;
this.pageSize = pageSize;
this.maxFanIn = maxFanIn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,13 @@ public BinaryRow next() {
return row;
}
}

@Test
void testFanInBelowTwoFailsFast() {
// a fan-in of 1 previously overflowed the merge arithmetic at flush time and
// restart-looped on the same config; it must be rejected up front
assertThatThrownBy(() -> createBuffer(1))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("fan-in for external merge sort must be at least 2");
}
}
Loading