Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.doris.load.routineload;

import org.apache.doris.common.Config;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.Pair;
import org.apache.doris.common.util.DebugUtil;
Expand All @@ -36,6 +37,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.ReentrantLock;

/**
* this is description of kafka routine load progress
Expand All @@ -58,6 +60,8 @@ public class KafkaProgress extends RoutineLoadProgress {
@SerializedName(value = "pito")
private ConcurrentMap<Integer, Long> partitionIdToOffset = Maps.newConcurrentMap();

private ReentrantLock lock = new ReentrantLock(true);

public KafkaProgress() {
super(LoadDataSourceType.KAFKA);
}
Expand Down Expand Up @@ -208,9 +212,24 @@ public String toJsonString() {
@Override
public void update(RLTaskTxnCommitAttachment attachment) {
KafkaProgress newProgress = (KafkaProgress) attachment.getProgress();

// + 1 to point to the next msg offset to be consumed
newProgress.partitionIdToOffset.entrySet().stream()
.forEach(entity -> this.partitionIdToOffset.put(entity.getKey(), entity.getValue() + 1));
if (Config.isCloudMode()) {
lock.lock();
try {
newProgress.partitionIdToOffset.forEach((partitionId, newOffset) -> {
this.partitionIdToOffset.compute(partitionId, (key, oldOffset) -> {
return (oldOffset == null || newOffset + 1 > oldOffset) ? newOffset + 1 : oldOffset;
});
});
} finally {
lock.unlock();
}
} else {
newProgress.partitionIdToOffset.entrySet().stream()
.forEach(entity -> this.partitionIdToOffset.put(entity.getKey(), entity.getValue() + 1));
}

if (LOG.isDebugEnabled()) {
LOG.debug("update kafka progress: {}, task: {}, job: {}",
newProgress.toJsonString(), DebugUtil.printId(attachment.getTaskId()), attachment.getJobId());
Expand Down