Class ExternalSorter<E>
java.lang.Object
org.apache.flink.runtime.operators.sort.ExternalSorter<E>
- All Implemented Interfaces:
Closeable,AutoCloseable,Sorter<E>,CloseableInputProvider<E>
The
ExternalSorter is a full fledged sorter. It implements a multi-way merge sort.
Internally, the logic is factored into two or three threads (read, sort, spill) which communicate
through a set of blocking queues, forming a closed loop. Memory is allocated using the MemoryManager interface. Thus the component will not exceed the provided memory limits.-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Shuts down all the threads initiated by this sort/merger.org.apache.flink.util.MutableObjectIterator<E>Gets the iterator over this input.booleanisClosed()static <E> ExternalSorterBuilder<E>newBuilder(MemoryManager memoryManager, AbstractInvokable parentTask, org.apache.flink.api.common.typeutils.TypeSerializer<E> serializer, org.apache.flink.api.common.typeutils.TypeComparator<E> comparator) Creates a builder for theExternalSorter.static <E> ExternalSorterBuilder<E>newBuilder(MemoryManager memoryManager, TaskInvokable parentTask, org.apache.flink.api.common.typeutils.TypeSerializer<E> serializer, org.apache.flink.api.common.typeutils.TypeComparator<E> comparator, org.apache.flink.api.common.ExecutionConfig executionConfig) Creates a builder for theExternalSorter.
-
Method Details
-
close
public void close()Shuts down all the threads initiated by this sort/merger. Also releases all previously allocated memory, if it has not yet been released by the threads, and closes and deletes all channels (removing the temporary files).The threads are set to exit directly, but depending on their operation, it may take a while to actually happen. The sorting thread will for example not finish before the current batch is sorted. This method attempts to wait for the working thread to exit. If it is however interrupted, the method exits immediately and is not guaranteed how long the threads continue to exist and occupy resources afterwards.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- See Also:
-
isClosed
public boolean isClosed() -
getIterator
Description copied from interface:CloseableInputProviderGets the iterator over this input.- Specified by:
getIteratorin interfaceCloseableInputProvider<E>- Returns:
- The iterator provided by this iterator provider.
- Throws:
InterruptedException
-
newBuilder
public static <E> ExternalSorterBuilder<E> newBuilder(MemoryManager memoryManager, TaskInvokable parentTask, org.apache.flink.api.common.typeutils.TypeSerializer<E> serializer, org.apache.flink.api.common.typeutils.TypeComparator<E> comparator, org.apache.flink.api.common.ExecutionConfig executionConfig) Creates a builder for theExternalSorter. -
newBuilder
public static <E> ExternalSorterBuilder<E> newBuilder(MemoryManager memoryManager, AbstractInvokable parentTask, org.apache.flink.api.common.typeutils.TypeSerializer<E> serializer, org.apache.flink.api.common.typeutils.TypeComparator<E> comparator) Creates a builder for theExternalSorter.
-