Class FileWriter<IN>
- java.lang.Object
-
- org.apache.flink.connector.file.sink.writer.FileWriter<IN>
-
- Type Parameters:
IN- The type of input elements.
- All Implemented Interfaces:
AutoCloseable,org.apache.flink.api.common.operators.ProcessingTimeService.ProcessingTimeCallback,org.apache.flink.api.connector.sink2.CommittingSinkWriter<IN,FileSinkCommittable>,org.apache.flink.api.connector.sink2.SinkWriter<IN>,org.apache.flink.api.connector.sink2.StatefulSinkWriter<IN,FileWriterBucketState>
@Internal public class FileWriter<IN> extends Object implements org.apache.flink.api.connector.sink2.StatefulSinkWriter<IN,FileWriterBucketState>, org.apache.flink.api.connector.sink2.CommittingSinkWriter<IN,FileSinkCommittable>, org.apache.flink.api.connector.sink2.SinkWriter<IN>, org.apache.flink.api.common.operators.ProcessingTimeService.ProcessingTimeCallback
-
-
Constructor Summary
Constructors Constructor Description FileWriter(org.apache.flink.core.fs.Path basePath, org.apache.flink.metrics.groups.SinkWriterMetricGroup metricGroup, org.apache.flink.streaming.api.functions.sink.filesystem.BucketAssigner<IN,String> bucketAssigner, FileWriterBucketFactory<IN> bucketFactory, org.apache.flink.streaming.api.functions.sink.filesystem.BucketWriter<IN,String> bucketWriter, org.apache.flink.streaming.api.functions.sink.filesystem.RollingPolicy<IN,String> rollingPolicy, org.apache.flink.streaming.api.functions.sink.filesystem.OutputFileConfig outputFileConfig, org.apache.flink.api.common.operators.ProcessingTimeService processingTimeService, long bucketCheckInterval)A constructor creating a new empty bucket manager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush(boolean endOfInput)voidinitializeState(Collection<FileWriterBucketState> bucketStates)Initializes the state after recovery from a failure.voidonProcessingTime(long time)Collection<FileSinkCommittable>prepareCommit()List<FileWriterBucketState>snapshotState(long checkpointId)voidwrite(IN element, org.apache.flink.api.connector.sink2.SinkWriter.Context context)
-
-
-
Constructor Detail
-
FileWriter
public FileWriter(org.apache.flink.core.fs.Path basePath, org.apache.flink.metrics.groups.SinkWriterMetricGroup metricGroup, org.apache.flink.streaming.api.functions.sink.filesystem.BucketAssigner<IN,String> bucketAssigner, FileWriterBucketFactory<IN> bucketFactory, org.apache.flink.streaming.api.functions.sink.filesystem.BucketWriter<IN,String> bucketWriter, org.apache.flink.streaming.api.functions.sink.filesystem.RollingPolicy<IN,String> rollingPolicy, org.apache.flink.streaming.api.functions.sink.filesystem.OutputFileConfig outputFileConfig, org.apache.flink.api.common.operators.ProcessingTimeService processingTimeService, long bucketCheckInterval)A constructor creating a new empty bucket manager.- Parameters:
basePath- The base path for our buckets.metricGroup-SinkWriterMetricGroupto set sink writer specific metrics.bucketAssigner- TheBucketAssignerprovided by the user.bucketFactory- TheFileWriterBucketFactoryto be used to create buckets.bucketWriter- TheBucketWriterto be used when writing data.rollingPolicy- TheRollingPolicyas specified by the user.
-
-
Method Detail
-
initializeState
public void initializeState(Collection<FileWriterBucketState> bucketStates) throws IOException
Initializes the state after recovery from a failure.During this process:
- we set the initial value for part counter to the maximum value used before across all tasks and buckets. This guarantees that we do not overwrite valid data,
- we commit any pending files for previous checkpoints (previous to the last successful one from which we restore),
- we resume writing to the previous in-progress file of each bucket, and
- if we receive multiple states for the same bucket, we merge them.
- Parameters:
bucketStates- the state holding recovered state about active buckets.- Throws:
IOException- if anything goes wrong during retrieving the state or restoring/committing of any in-progress/pending part files
-
write
public void write(IN element, org.apache.flink.api.connector.sink2.SinkWriter.Context context) throws IOException, InterruptedException
- Specified by:
writein interfaceorg.apache.flink.api.connector.sink2.SinkWriter<IN>- Throws:
IOExceptionInterruptedException
-
flush
public void flush(boolean endOfInput) throws IOException, InterruptedException- Specified by:
flushin interfaceorg.apache.flink.api.connector.sink2.SinkWriter<IN>- Throws:
IOExceptionInterruptedException
-
prepareCommit
public Collection<FileSinkCommittable> prepareCommit() throws IOException
- Specified by:
prepareCommitin interfaceorg.apache.flink.api.connector.sink2.CommittingSinkWriter<IN,FileSinkCommittable>- Throws:
IOException
-
snapshotState
public List<FileWriterBucketState> snapshotState(long checkpointId) throws IOException
- Specified by:
snapshotStatein interfaceorg.apache.flink.api.connector.sink2.StatefulSinkWriter<IN,FileWriterBucketState>- Throws:
IOException
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
onProcessingTime
public void onProcessingTime(long time) throws IOException- Specified by:
onProcessingTimein interfaceorg.apache.flink.api.common.operators.ProcessingTimeService.ProcessingTimeCallback- Throws:
IOException
-
-