use of org.apache.kafka.streams.internals.generated.SubscriptionInfoData.TaskOffsetSum in project kafka by apache.
the class SubscriptionInfo method setTaskOffsetSumDataWithNamedTopologiesFromTaskOffsetSumMap.
// For version > MIN_NAMED_TOPOLOGY_VERSION
private void setTaskOffsetSumDataWithNamedTopologiesFromTaskOffsetSumMap(final Map<TaskId, Long> taskOffsetSums) {
data.setTaskOffsetSums(taskOffsetSums.entrySet().stream().map(t -> {
final SubscriptionInfoData.TaskOffsetSum taskOffsetSum = new SubscriptionInfoData.TaskOffsetSum();
final TaskId task = t.getKey();
taskOffsetSum.setTopicGroupId(task.subtopology());
taskOffsetSum.setPartition(task.partition());
taskOffsetSum.setNamedTopology(task.topologyName());
taskOffsetSum.setOffsetSum(t.getValue());
return taskOffsetSum;
}).collect(Collectors.toList()));
}
use of org.apache.kafka.streams.internals.generated.SubscriptionInfoData.TaskOffsetSum in project kafka by apache.
the class SubscriptionInfo method setTaskOffsetSumDataFromTaskOffsetSumMap.
// For MIN_NAMED_TOPOLOGY_VERSION > version > MIN_VERSION_OFFSET_SUM_SUBSCRIPTION
private void setTaskOffsetSumDataFromTaskOffsetSumMap(final Map<TaskId, Long> taskOffsetSums) {
final Map<Integer, List<SubscriptionInfoData.PartitionToOffsetSum>> topicGroupIdToPartitionOffsetSum = new HashMap<>();
for (final Map.Entry<TaskId, Long> taskEntry : taskOffsetSums.entrySet()) {
final TaskId task = taskEntry.getKey();
if (task.topologyName() != null) {
throw new TaskAssignmentException("Named topologies are not compatible with older protocol versions");
}
topicGroupIdToPartitionOffsetSum.computeIfAbsent(task.subtopology(), t -> new ArrayList<>()).add(new SubscriptionInfoData.PartitionToOffsetSum().setPartition(task.partition()).setOffsetSum(taskEntry.getValue()));
}
data.setTaskOffsetSums(topicGroupIdToPartitionOffsetSum.entrySet().stream().map(t -> {
final SubscriptionInfoData.TaskOffsetSum taskOffsetSum = new SubscriptionInfoData.TaskOffsetSum();
taskOffsetSum.setTopicGroupId(t.getKey());
taskOffsetSum.setPartitionToOffsetSum(t.getValue());
return taskOffsetSum;
}).collect(Collectors.toList()));
}
use of org.apache.kafka.streams.internals.generated.SubscriptionInfoData.TaskOffsetSum in project kafka by apache.
the class SubscriptionInfo method taskOffsetSums.
public Map<TaskId, Long> taskOffsetSums() {
if (taskOffsetSumsCache == null) {
taskOffsetSumsCache = new HashMap<>();
if (data.version() >= MIN_VERSION_OFFSET_SUM_SUBSCRIPTION) {
for (final TaskOffsetSum taskOffsetSum : data.taskOffsetSums()) {
if (data.version() >= MIN_NAMED_TOPOLOGY_VERSION) {
taskOffsetSumsCache.put(new TaskId(taskOffsetSum.topicGroupId(), taskOffsetSum.partition(), taskOffsetSum.namedTopology()), taskOffsetSum.offsetSum());
} else {
for (final PartitionToOffsetSum partitionOffsetSum : taskOffsetSum.partitionToOffsetSum()) {
taskOffsetSumsCache.put(new TaskId(taskOffsetSum.topicGroupId(), partitionOffsetSum.partition()), partitionOffsetSum.offsetSum());
}
}
}
} else {
prevTasks().forEach(taskId -> taskOffsetSumsCache.put(taskId, Task.LATEST_OFFSET));
standbyTasks().forEach(taskId -> taskOffsetSumsCache.put(taskId, UNKNOWN_OFFSET_SUM));
}
}
return taskOffsetSumsCache;
}
Aggregations