Skip to content
Merged
Show file tree
Hide file tree
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 @@ -19,6 +19,7 @@

import org.apache.inlong.sdk.sort.entity.InLongTopic;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -65,4 +66,20 @@ public MultiTopicsFetcher(
this.executor = Executors.newSingleThreadScheduledExecutor();
}

protected boolean needUpdate(Collection<InLongTopic> newTopics) {
if (newTopics.size() != onlineTopics.size()) {
return true;
}
// all topic should share the same properties in one task
if (Objects.equals(newTopics.stream().findFirst(), onlineTopics.values().stream().findFirst())) {
return true;
}
for (InLongTopic topic : newTopics) {
if (!onlineTopics.containsKey(topic.getTopic())) {
return true;
}
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,32 @@
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;

public class AckOffsetOnRebalance implements ConsumerRebalanceListener {

private static final Logger LOGGER = LoggerFactory.getLogger(AckOffsetOnRebalance.class);
private final String clusterId;
private final Seeker seeker;
private final ConcurrentHashMap<TopicPartition, OffsetAndMetadata> commitOffsetMap;
private final ConcurrentHashMap<TopicPartition, ConcurrentSkipListMap<Long, Boolean>> ackOffsetMap;

public AckOffsetOnRebalance(String clusterId, Seeker seeker,
ConcurrentHashMap<TopicPartition, OffsetAndMetadata> commitOffsetMap) {
this(clusterId, seeker, commitOffsetMap, null);
}

public AckOffsetOnRebalance(
String clusterId,
Seeker seeker,
ConcurrentHashMap<TopicPartition, OffsetAndMetadata> commitOffsetMap,
ConcurrentHashMap<TopicPartition, ConcurrentSkipListMap<Long, Boolean>> ackOffsetMap) {
this.clusterId = clusterId;
this.seeker = seeker;
this.commitOffsetMap = commitOffsetMap;
this.ackOffsetMap = ackOffsetMap;
}

@Override
Expand All @@ -48,6 +60,30 @@ public void onPartitionsRevoked(Collection<TopicPartition> collection) {
collection.forEach((v) -> {
LOGGER.info("clusterId:{},onPartitionsRevoked:{}", clusterId, v.toString());
});
if (Objects.nonNull(ackOffsetMap) && Objects.nonNull(commitOffsetMap)) {
ackRevokedPartitions(collection);
}
}

private void ackRevokedPartitions(Collection<TopicPartition> collection) {
collection.forEach(tp -> {
if (!ackOffsetMap.containsKey(tp)) {
return;
}
ConcurrentSkipListMap<Long, Boolean> tpOffsetMap = ackOffsetMap.remove(tp);
long commitOffset = -1;
for (Long ackOffset : tpOffsetMap.keySet()) {
if (!tpOffsetMap.get(ackOffset)) {
break;
}
commitOffset = ackOffset;
}
// the first haven't ack, do nothing
if (commitOffset == -1) {
return;
}
commitOffsetMap.put(tp, new OffsetAndMetadata(commitOffset));
});
}

@Override
Expand Down
Loading