@Experimental public class RateLimitedSourceReader<E,SplitT extends SourceSplit> extends Object implements SourceReader<E,SplitT>
SourceReader
and rate limits its data emission.Constructor and Description |
---|
RateLimitedSourceReader(SourceReader<E,SplitT> sourceReader,
RateLimiter rateLimiter)
Instantiates a new rate-limited source reader.
|
Modifier and Type | Method and Description |
---|---|
void |
addSplits(List<SplitT> splits)
Adds a list of splits for this reader to read.
|
void |
close() |
CompletableFuture<Void> |
isAvailable()
Returns a future that signals that data is available from the reader.
|
void |
notifyCheckpointComplete(long checkpointId)
We have an empty default implementation here because most source readers do not have to
implement the method.
|
void |
notifyNoMoreSplits()
This method is called when the reader is notified that it will not receive any further
splits.
|
InputStatus |
pollNext(ReaderOutput<E> output)
Poll the next available record into the
ReaderOutput . |
List<SplitT> |
snapshotState(long checkpointId)
Checkpoint on the state of the source.
|
void |
start()
Start the reader.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handleSourceEvents, pauseOrResumeSplits
notifyCheckpointAborted
public RateLimitedSourceReader(SourceReader<E,SplitT> sourceReader, RateLimiter rateLimiter)
sourceReader
- The actual source reader.rateLimiter
- The rate limiter.public void start()
SourceReader
start
in interface SourceReader<E,SplitT extends SourceSplit>
public InputStatus pollNext(ReaderOutput<E> output) throws Exception
SourceReader
ReaderOutput
.
The implementation must make sure this method is non-blocking.
Although the implementation can emit multiple records into the given ReaderOutput, it is
recommended not doing so. Instead, emit one record into the ReaderOutput and return a InputStatus.MORE_AVAILABLE
to let the caller thread know there are more records available.
pollNext
in interface SourceReader<E,SplitT extends SourceSplit>
Exception
public CompletableFuture<Void> isAvailable()
SourceReader
Once the future completes, the runtime will keep calling the SourceReader.pollNext(ReaderOutput)
method until that method returns a status other than InputStatus.MORE_AVAILABLE
. After that, the runtime will again call this method to obtain
the next future. Once that completes, it will again call SourceReader.pollNext(ReaderOutput)
and
so on.
The contract is the following: If the reader has data available, then all futures previously returned by this method must eventually complete. Otherwise the source might stall indefinitely.
It is not a problem to have occasional "false positives", meaning to complete a future
even if no data is available. However, one should not use an "always complete" future in
cases no data is available, because that will result in busy waiting loops calling pollNext(...)
even though no data is available.
isAvailable
in interface SourceReader<E,SplitT extends SourceSplit>
public void addSplits(List<SplitT> splits)
SourceReader
SplitEnumeratorContext.assignSplit(SourceSplit, int)
or SplitEnumeratorContext.assignSplits(SplitsAssignment)
.addSplits
in interface SourceReader<E,SplitT extends SourceSplit>
splits
- The splits assigned by the split enumerator.public void notifyNoMoreSplits()
SourceReader
It is triggered when the enumerator calls SplitEnumeratorContext.signalNoMoreSplits(int)
with the reader's parallel subtask.
notifyNoMoreSplits
in interface SourceReader<E,SplitT extends SourceSplit>
public List<SplitT> snapshotState(long checkpointId)
SourceReader
snapshotState
in interface SourceReader<E,SplitT extends SourceSplit>
public void close() throws Exception
close
in interface AutoCloseable
Exception
public void notifyCheckpointComplete(long checkpointId) throws Exception
SourceReader
notifyCheckpointComplete
in interface CheckpointListener
notifyCheckpointComplete
in interface SourceReader<E,SplitT extends SourceSplit>
checkpointId
- The ID of the checkpoint that has been completed.Exception
- This method can propagate exceptions, which leads to a failure/recovery for
the task. Note that this will NOT lead to the checkpoint being revoked.CheckpointListener.notifyCheckpointComplete(long)
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.