use of org.apache.kafka.streams.processor.internals.Task in project kafka by apache.
the class ClientState method initializePrevActiveTasksFromOwnedPartitions.
private void initializePrevActiveTasksFromOwnedPartitions(final Map<TopicPartition, TaskId> taskForPartitionMap) {
// 3) stateless tasks are not encoded in the task lags, and must be figured out from the ownedPartitions
for (final Map.Entry<TopicPartition, String> partitionEntry : ownedPartitions.entrySet()) {
final TopicPartition tp = partitionEntry.getKey();
final TaskId task = taskForPartitionMap.get(tp);
if (task != null) {
addPreviousActiveTask(task);
previousActiveTasks.consumerToTaskIds().computeIfAbsent(partitionEntry.getValue(), k -> new HashSet<>()).add(task);
} else {
LOG.error("No task found for topic partition {}", tp);
}
}
}
use of org.apache.kafka.streams.processor.internals.Task in project kafka by apache.
the class AssignmentTestUtils method analyzeTaskAssignmentBalance.
static TaskSkewReport analyzeTaskAssignmentBalance(final Map<UUID, ClientState> clientStates) {
final Function<Integer, Map<UUID, AtomicInteger>> initialClientCounts = i -> clientStates.keySet().stream().collect(Collectors.toMap(c -> c, c -> new AtomicInteger(0)));
final Map<Integer, Map<UUID, AtomicInteger>> subtopologyToClientsWithPartition = new TreeMap<>();
for (final Map.Entry<UUID, ClientState> entry : clientStates.entrySet()) {
final UUID client = entry.getKey();
final ClientState clientState = entry.getValue();
for (final TaskId task : clientState.activeTasks()) {
final int subtopology = task.subtopology();
subtopologyToClientsWithPartition.computeIfAbsent(subtopology, initialClientCounts).get(client).incrementAndGet();
}
}
int maxTaskSkew = 0;
final Set<Integer> skewedSubtopologies = new TreeSet<>();
for (final Map.Entry<Integer, Map<UUID, AtomicInteger>> entry : subtopologyToClientsWithPartition.entrySet()) {
final Map<UUID, AtomicInteger> clientsWithPartition = entry.getValue();
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
for (final AtomicInteger count : clientsWithPartition.values()) {
max = Math.max(max, count.get());
min = Math.min(min, count.get());
}
final int taskSkew = max - min;
maxTaskSkew = Math.max(maxTaskSkew, taskSkew);
if (taskSkew > 1) {
skewedSubtopologies.add(entry.getKey());
}
}
return new TaskSkewReport(maxTaskSkew, skewedSubtopologies, subtopologyToClientsWithPartition);
}
Aggregations