Class ExternalSorter<E>
- java.lang.Object
-
- org.apache.flink.runtime.operators.sort.ExternalSorter<E>
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Sorter<E>
,CloseableInputProvider<E>
public class ExternalSorter<E> extends Object implements Sorter<E>
TheExternalSorter
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 theMemoryManager
interface. Thus the component will not exceed the provided memory limits.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Shuts down all the threads initiated by this sort/merger.MutableObjectIterator<E>
getIterator()
Gets the iterator over this input.boolean
isClosed()
static <E> ExternalSorterBuilder<E>
newBuilder(MemoryManager memoryManager, AbstractInvokable parentTask, TypeSerializer<E> serializer, TypeComparator<E> comparator)
Creates a builder for theExternalSorter
.static <E> ExternalSorterBuilder<E>
newBuilder(MemoryManager memoryManager, TaskInvokable parentTask, TypeSerializer<E> serializer, TypeComparator<E> comparator, ExecutionConfig executionConfig)
Creates a builder for theExternalSorter
.
-
-
-
Method Detail
-
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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- See Also:
Closeable.close()
-
isClosed
public boolean isClosed()
-
getIterator
public MutableObjectIterator<E> getIterator() throws InterruptedException
Description copied from interface:CloseableInputProvider
Gets the iterator over this input.- Specified by:
getIterator
in interfaceCloseableInputProvider<E>
- Returns:
- The iterator provided by this iterator provider.
- Throws:
InterruptedException
-
newBuilder
public static <E> ExternalSorterBuilder<E> newBuilder(MemoryManager memoryManager, TaskInvokable parentTask, TypeSerializer<E> serializer, TypeComparator<E> comparator, ExecutionConfig executionConfig)
Creates a builder for theExternalSorter
.
-
newBuilder
public static <E> ExternalSorterBuilder<E> newBuilder(MemoryManager memoryManager, AbstractInvokable parentTask, TypeSerializer<E> serializer, TypeComparator<E> comparator)
Creates a builder for theExternalSorter
.
-
-