Class PartitionedFileWriter
- java.lang.Object
-
- org.apache.flink.runtime.io.network.partition.PartitionedFileWriter
-
- All Implemented Interfaces:
AutoCloseable
@NotThreadSafe public class PartitionedFileWriter extends Object implements AutoCloseable
File writer which can write buffers and generatePartitionedFile. Data is written region by region. Before writing a new region, the methodstartNewRegion(boolean)must be called. After writing all data, the methodfinish()must be called to close all opened files and return the targetPartitionedFile.
-
-
Constructor Summary
Constructors Constructor Description PartitionedFileWriter(int numSubpartitions, int maxIndexBufferSize, String basePath, int[] writeOrder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()PartitionedFilefinish()Finishes writing thePartitionedFilewhich closes the file channel and returns the correspondingPartitionedFile.voidreleaseQuietly()Used to close and delete the failedPartitionedFilewhen any exception occurs.voidstartNewRegion(boolean isBroadcastRegion)Persists the region index of the current data region and starts a new region to write.voidwriteBuffers(List<BufferWithSubpartition> bufferWithSubpartitions)Writes a list ofBuffers to thisPartitionedFile.
-
-
-
Constructor Detail
-
PartitionedFileWriter
public PartitionedFileWriter(int numSubpartitions, int maxIndexBufferSize, String basePath, int[] writeOrder) throws IOException- Throws:
IOException
-
-
Method Detail
-
startNewRegion
public void startNewRegion(boolean isBroadcastRegion) throws IOExceptionPersists the region index of the current data region and starts a new region to write.Note: The caller is responsible for releasing the failed
PartitionedFileif any exception occurs.- Parameters:
isBroadcastRegion- Whether it's a broadcast region. SeeisBroadcastRegion.- Throws:
IOException
-
writeBuffers
public void writeBuffers(List<BufferWithSubpartition> bufferWithSubpartitions) throws IOException
Writes a list ofBuffers to thisPartitionedFile. It guarantees that after the return of this method, the target buffers can be released. In a data region, all data of the same subpartition must be written together.Note: The caller is responsible for recycling the target buffers and releasing the failed
PartitionedFileif any exception occurs.- Throws:
IOException
-
finish
public PartitionedFile finish() throws IOException
Finishes writing thePartitionedFilewhich closes the file channel and returns the correspondingPartitionedFile.Note: The caller is responsible for releasing the failed
PartitionedFileif any exception occurs.- Throws:
IOException
-
releaseQuietly
public void releaseQuietly()
Used to close and delete the failedPartitionedFilewhen any exception occurs.
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
-