IN
- The type of input elements.@Internal public class FileWriter<IN> extends Object implements StatefulSink.StatefulSinkWriter<IN,FileWriterBucketState>, TwoPhaseCommittingSink.PrecommittingSinkWriter<IN,FileSinkCommittable>, SinkWriter<IN>, ProcessingTimeService.ProcessingTimeCallback
SinkWriter
implementation for FileSink
.
It writes data to and manages the different active buckes
in the
FileSink
.
SinkWriter.Context
Constructor and Description |
---|
FileWriter(Path basePath,
SinkWriterMetricGroup metricGroup,
BucketAssigner<IN,String> bucketAssigner,
FileWriterBucketFactory<IN> bucketFactory,
BucketWriter<IN,String> bucketWriter,
RollingPolicy<IN,String> rollingPolicy,
OutputFileConfig outputFileConfig,
ProcessingTimeService processingTimeService,
long bucketCheckInterval)
A constructor creating a new empty bucket manager.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush(boolean endOfInput)
Called on checkpoint or end of input so that the writer to flush all pending data for
at-least-once.
|
void |
initializeState(Collection<FileWriterBucketState> bucketStates)
Initializes the state after recovery from a failure.
|
void |
onProcessingTime(long time)
This method is invoked with the time which the callback register for.
|
Collection<FileSinkCommittable> |
prepareCommit()
Prepares for a commit.
|
List<FileWriterBucketState> |
snapshotState(long checkpointId) |
void |
write(IN element,
SinkWriter.Context context)
Adds an element to the writer.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
writeWatermark
public FileWriter(Path basePath, SinkWriterMetricGroup metricGroup, BucketAssigner<IN,String> bucketAssigner, FileWriterBucketFactory<IN> bucketFactory, BucketWriter<IN,String> bucketWriter, RollingPolicy<IN,String> rollingPolicy, OutputFileConfig outputFileConfig, ProcessingTimeService processingTimeService, long bucketCheckInterval)
basePath
- The base path for our buckets.metricGroup
- SinkWriterMetricGroup
to set sink writer specific metrics.bucketAssigner
- The BucketAssigner
provided by the user.bucketFactory
- The FileWriterBucketFactory
to be used to create buckets.bucketWriter
- The BucketWriter
to be used when writing data.rollingPolicy
- The RollingPolicy
as specified by the user.public void initializeState(Collection<FileWriterBucketState> bucketStates) throws IOException
During this process:
bucketStates
- the state holding recovered state about active buckets.IOException
- if anything goes wrong during retrieving the state or
restoring/committing of any in-progress/pending part filespublic void write(IN element, SinkWriter.Context context) throws IOException, InterruptedException
SinkWriter
write
in interface SinkWriter<IN>
element
- The input recordcontext
- The additional information about the input recordIOException
- if fail to add an element.InterruptedException
public void flush(boolean endOfInput) throws IOException, InterruptedException
SinkWriter
flush
in interface SinkWriter<IN>
IOException
InterruptedException
public Collection<FileSinkCommittable> prepareCommit() throws IOException
TwoPhaseCommittingSink.PrecommittingSinkWriter
This method will be called after SinkWriter.flush(boolean)
and before StatefulSink.StatefulSinkWriter.snapshotState(long)
.
prepareCommit
in interface TwoPhaseCommittingSink.PrecommittingSinkWriter<IN,FileSinkCommittable>
IOException
- if fail to prepare for a commit.public List<FileWriterBucketState> snapshotState(long checkpointId) throws IOException
snapshotState
in interface StatefulSink.StatefulSinkWriter<IN,FileWriterBucketState>
IOException
- if fail to snapshot writer's state.public void close()
close
in interface AutoCloseable
public void onProcessingTime(long time) throws IOException
ProcessingTimeService.ProcessingTimeCallback
onProcessingTime
in interface ProcessingTimeService.ProcessingTimeCallback
time
- The time this callback was registered for.IOException
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.