Search in sources :

Example 1 with PulsarOrderedFetcherManager

use of org.apache.flink.connector.pulsar.source.reader.fetcher.PulsarOrderedFetcherManager in project flink by apache.

the class PulsarOrderedSourceReader method cumulativeAcknowledgmentMessage.

/**
 * Acknowledge the pulsar topic partition cursor by the last consumed message id.
 */
private void cumulativeAcknowledgmentMessage() {
    Map<TopicPartition, MessageId> cursors = new HashMap<>(cursorsOfFinishedSplits);
    // We reuse snapshotState for acquiring a consume status snapshot.
    // So the checkpoint didn't really happen, so we just pass a fake checkpoint id.
    List<PulsarPartitionSplit> splits = super.snapshotState(1L);
    for (PulsarPartitionSplit split : splits) {
        MessageId latestConsumedId = split.getLatestConsumedId();
        if (latestConsumedId != null) {
            cursors.put(split.getPartition(), latestConsumedId);
        }
    }
    try {
        ((PulsarOrderedFetcherManager<OUT>) splitFetcherManager).acknowledgeMessages(cursors);
        // Clean up the finish splits.
        cursorsOfFinishedSplits.keySet().removeAll(cursors.keySet());
    } catch (Exception e) {
        LOG.error("Fail in auto cursor commit.", e);
        cursorCommitThrowable.compareAndSet(null, e);
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TopicPartition(org.apache.flink.connector.pulsar.source.enumerator.topic.TopicPartition) PulsarOrderedFetcherManager(org.apache.flink.connector.pulsar.source.reader.fetcher.PulsarOrderedFetcherManager) PulsarPartitionSplit(org.apache.flink.connector.pulsar.source.split.PulsarPartitionSplit) MessageId(org.apache.pulsar.client.api.MessageId)

Aggregations

HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TopicPartition (org.apache.flink.connector.pulsar.source.enumerator.topic.TopicPartition)1 PulsarOrderedFetcherManager (org.apache.flink.connector.pulsar.source.reader.fetcher.PulsarOrderedFetcherManager)1 PulsarPartitionSplit (org.apache.flink.connector.pulsar.source.split.PulsarPartitionSplit)1 MessageId (org.apache.pulsar.client.api.MessageId)1