protected class UnilateralSortMerger.SpillingThread extends UnilateralSortMerger.ThreadBase<E>
Thread.State, Thread.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
protected TypeComparator<E> |
comparator |
protected IOManager |
ioManager |
protected int |
maxFanIn |
protected MemoryManager |
memManager |
protected List<MemorySegment> |
mergeReadMemory |
protected int |
numWriteBuffersToCluster |
protected TypeSerializer<E> |
serializer |
protected List<MemorySegment> |
writeMemory |
queues
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
SpillingThread(ExceptionHandler<IOException> exceptionHandler,
UnilateralSortMerger.CircularQueues<E> queues,
AbstractInvokable parentTask,
MemoryManager memManager,
IOManager ioManager,
TypeSerializer<E> serializer,
TypeComparator<E> comparator,
List<MemorySegment> sortReadMemory,
List<MemorySegment> writeMemory,
int maxNumFileHandles)
Creates the spilling thread.
|
Modifier and Type | Method and Description |
---|---|
protected void |
disposeSortBuffers(boolean releaseMemory)
Releases the memory that is registered for in-memory sorted run generation.
|
protected MergeIterator<E> |
getMergingIterator(List<UnilateralSortMerger.ChannelWithBlockCount> channelIDs,
List<List<MemorySegment>> inputSegments,
List<FileIOChannel> readerList,
MutableObjectIterator<E> largeRecords)
Returns an iterator that iterates over the merged result from all given channels.
|
protected void |
getSegmentsForReaders(List<List<MemorySegment>> target,
List<MemorySegment> memory,
int numChannels)
Divides the given collection of memory buffers among
numChannels sublists. |
void |
go()
Entry point of the thread.
|
protected List<UnilateralSortMerger.ChannelWithBlockCount> |
mergeChannelList(List<UnilateralSortMerger.ChannelWithBlockCount> channelIDs,
List<MemorySegment> allReadBuffers,
List<MemorySegment> writeBuffers)
Merges the given sorted runs to a smaller number of sorted runs.
|
protected UnilateralSortMerger.ChannelWithBlockCount |
mergeChannels(List<UnilateralSortMerger.ChannelWithBlockCount> channelIDs,
List<List<MemorySegment>> readBuffers,
List<MemorySegment> writeBuffers)
Merges the sorted runs described by the given Channel IDs into a single sorted run.
|
protected void |
registerChannelToBeRemovedAtShudown(FileIOChannel.ID channel)
Adds a channel to the list of channels that are to be removed at shutdown.
|
protected void |
registerOpenChannelToBeRemovedAtShudown(FileIOChannel channel)
Adds a channel reader/writer to the list of channels that are to be removed at shutdown.
|
protected UnilateralSortMerger.CircularElement<E> |
takeNext(BlockingQueue<UnilateralSortMerger.CircularElement<E>> queue,
Queue<UnilateralSortMerger.CircularElement<E>> cache) |
protected void |
unregisterChannelToBeRemovedAtShudown(FileIOChannel.ID channel)
Removes a channel from the list of channels that are to be removed at shutdown.
|
protected void |
unregisterOpenChannelToBeRemovedAtShudown(FileIOChannel channel)
Removes a channel reader/writer from the list of channels that are to be removed at
shutdown.
|
internalHandleException, isRunning, run, shutdown, uncaughtException
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
protected final MemoryManager memManager
protected final IOManager ioManager
protected final TypeSerializer<E> serializer
protected final TypeComparator<E> comparator
protected final List<MemorySegment> writeMemory
protected final List<MemorySegment> mergeReadMemory
protected final int maxFanIn
protected final int numWriteBuffersToCluster
public SpillingThread(ExceptionHandler<IOException> exceptionHandler, UnilateralSortMerger.CircularQueues<E> queues, AbstractInvokable parentTask, MemoryManager memManager, IOManager ioManager, TypeSerializer<E> serializer, TypeComparator<E> comparator, List<MemorySegment> sortReadMemory, List<MemorySegment> writeMemory, int maxNumFileHandles)
exceptionHandler
- The exception handler to call for all exceptions.queues
- The queues used to pass buffers between the threads.parentTask
- The task that started this thread. If non-null, it is used to register
this thread.memManager
- The memory manager used to allocate buffers for the readers and
writers.ioManager
- The I/I manager used to instantiate readers and writers from.serializer
- comparator
- sortReadMemory
- writeMemory
- maxNumFileHandles
- public void go() throws IOException
go
in class UnilateralSortMerger.ThreadBase<E>
IOException
- Exceptions that prohibit correct completion of the work may be thrown
by the thread.protected final void disposeSortBuffers(boolean releaseMemory)
protected final UnilateralSortMerger.CircularElement<E> takeNext(BlockingQueue<UnilateralSortMerger.CircularElement<E>> queue, Queue<UnilateralSortMerger.CircularElement<E>> cache) throws InterruptedException
InterruptedException
protected final MergeIterator<E> getMergingIterator(List<UnilateralSortMerger.ChannelWithBlockCount> channelIDs, List<List<MemorySegment>> inputSegments, List<FileIOChannel> readerList, MutableObjectIterator<E> largeRecords) throws IOException
channelIDs
- The channels that are to be merged and returned.inputSegments
- The buffers to be used for reading. The list contains for each
channel one list of input segments. The size of the inputSegments
list
must be equal to that of the channelIDs
list.IOException
- Thrown, if the readers encounter an I/O problem.protected final List<UnilateralSortMerger.ChannelWithBlockCount> mergeChannelList(List<UnilateralSortMerger.ChannelWithBlockCount> channelIDs, List<MemorySegment> allReadBuffers, List<MemorySegment> writeBuffers) throws IOException
channelIDs
- The IDs of the sorted runs that need to be merged.allReadBuffers
- writeBuffers
- The buffers to be used by the writers.IOException
- Thrown, if the readers or writers encountered an I/O problem.protected UnilateralSortMerger.ChannelWithBlockCount mergeChannels(List<UnilateralSortMerger.ChannelWithBlockCount> channelIDs, List<List<MemorySegment>> readBuffers, List<MemorySegment> writeBuffers) throws IOException
channelIDs
- The IDs of the runs' channels.readBuffers
- The buffers for the readers that read the sorted runs.writeBuffers
- The buffers for the writer that writes the merged channel.IOException
protected final void getSegmentsForReaders(List<List<MemorySegment>> target, List<MemorySegment> memory, int numChannels)
numChannels
sublists.target
- The list into which the lists with buffers for the channels are put.memory
- A list containing the memory buffers to be distributed. The buffers are not
removed from this list.numChannels
- The number of channels for which to allocate buffers. Must not be
zero.protected void registerChannelToBeRemovedAtShudown(FileIOChannel.ID channel)
channel
- The channel id.protected void unregisterChannelToBeRemovedAtShudown(FileIOChannel.ID channel)
channel
- The channel id.protected void registerOpenChannelToBeRemovedAtShudown(FileIOChannel channel)
channel
- The channel reader/writer.protected void unregisterOpenChannelToBeRemovedAtShudown(FileIOChannel channel)
channel
- The channel reader/writer.Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.