public class OffsetManager extends Object
Manages acked and committed offsets for a TopicPartition. This class is not thread safe
Constructor and Description |
---|
OffsetManager(org.apache.kafka.common.TopicPartition tp,
long initialFetchOffset)
Creates a new OffsetManager.
|
Modifier and Type | Method and Description |
---|---|
void |
addToAckMsgs(KafkaSpoutMessageId msgId) |
void |
addToEmitMsgs(long offset) |
long |
commit(org.apache.kafka.clients.consumer.OffsetAndMetadata committedOffsetAndMeta)
Marks an offset as committed.
|
boolean |
contains(KafkaSpoutMessageId msgId) |
org.apache.kafka.clients.consumer.OffsetAndMetadata |
findNextCommitOffset(String commitMetadata)
An offset can only be committed when all emitted records with lower offset have been acked.
|
long |
getCommittedOffset() |
long |
getLatestEmittedOffset() |
long |
getNthUncommittedOffsetAfterCommittedOffset(int index)
Gets the offset of the nth emitted message after the committed offset.
|
int |
getNumUncommittedOffsets() |
boolean |
hasCommitted()
Checks if this OffsetManager has committed to Kafka.
|
String |
toString() |
public OffsetManager(org.apache.kafka.common.TopicPartition tp, long initialFetchOffset)
Creates a new OffsetManager.
tp
- The TopicPartitioninitialFetchOffset
- The initial fetch offset for the given TopicPartitionpublic void addToAckMsgs(KafkaSpoutMessageId msgId)
public void addToEmitMsgs(long offset)
public int getNumUncommittedOffsets()
public long getNthUncommittedOffsetAfterCommittedOffset(int index)
Gets the offset of the nth emitted message after the committed offset. Example: If the committed offset is 0 and offsets 1, 2, 8, 10 have been emitted, getNthUncommittedOffsetAfterCommittedOffset(3) returns 8.
index
- The index of the message to get the offset forNoSuchElementException
- if the index is out of rangepublic org.apache.kafka.clients.consumer.OffsetAndMetadata findNextCommitOffset(String commitMetadata)
An offset can only be committed when all emitted records with lower offset have been acked. This guarantees that all offsets smaller than the committedOffset have been delivered, or that those offsets no longer exist in Kafka.
The returned offset points to the earliest uncommitted offset, and matches the semantics of the KafkaConsumer.commitSync API.commitMetadata
- Metadata information to commit to Kafka. It is constant per KafkaSpout instance per topologypublic long commit(org.apache.kafka.clients.consumer.OffsetAndMetadata committedOffsetAndMeta)
Marks an offset as committed. This method has side effects - it sets the internal state in such a way that future calls to findNextCommitOffset(String)
will return offsets greater than or equal to the offset specified, if any.
committedOffsetAndMeta
- The committed offset. All lower offsets are expected to have been committed.public boolean hasCommitted()
Checks if this OffsetManager has committed to Kafka.
public boolean contains(KafkaSpoutMessageId msgId)
public long getLatestEmittedOffset()
public long getCommittedOffset()
Copyright © 2020 The Apache Software Foundation. All rights reserved.