You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2022/04/08 17:18:26 UTC
[GitHub] [kafka] C0urante opened a new pull request, #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
C0urante opened a new pull request, #12019:
URL: https://github.com/apache/kafka/pull/12019
[Jira](https://issues.apache.org/jira/browse/KAFKA-13764)
Depends on https://github.com/apache/kafka/pull/11983
The primary goal of this PR is to address several outstanding issues with incremental rebalancing that lead to stable-but-unbalanced clusters. However, other small bug fixes are also applied, and some liberty is taken with refactoring to improve readability and flexibility in the code base.
This should also address [KAFKA-12495](https://issues.apache.org/jira/browse/KAFKA-12495), and includes an adapted [test case](https://github.com/apache/kafka/pull/10367/files#diff-244a837479b827768c3daaabee8c7ad2064731377f1ad26a11bd890214252b7fR211-R358) from https://github.com/apache/kafka/pull/10367, which addresses that issue but with a different approach.
High-level changes:
- Refine the logic for load-balancing revocations:
- - Perform load-balancing revocations any time the cluster appears imbalanced and there are still connectors and tasks that can be revoked from workers, instead of only when the number of workers in the cluster changes
- - Remove the "rough estimation" logic and replace it with a precise calculation of exactly how to allocate all currently-configured connectors and tasks as evenly as possible across a cluster
- - Account for load-balancing revocations when assigning new and lost connectors and tasks across the cluster
- Improve code quality:
- - Extract the `ConnectorsAndTasks` class into its own file, enrich it and its builder class with developer-friendly methods, make its contents completely immutable, and use `Set` instead of generic `Collection` instances to store connectors and tasks
- - Where possible, identify logic that is shared for connectors and tasks (`IncrementalCooperativeAssignor::assignConnectors` and `IncrementalCooperativeAssignor::assignTasks`, for example) and abstract it into a single reusable method
- - Use the `final` keyword for base and derived sets in `IncrementalCooperativeAssignor::performTaskAssignment` (tracking mutations across a 100+ line method is difficult)
- - Reword unnecessary and confusing comments ("... is a derived set from the set difference of ..." is not very informative)
- - Reorganize the grouping of methods in `IncrementalCooperativeAssignor` to place static utility methods together at the bottom of the class
- - Demote visibility of testing-only methods and fields from `protected` to package-private (`protected` implies that the field/method is intended for use by subclasses, which is not the case for any of these)
- Testing:
- - Add several new tests to cover a variety of new cases, many of which result in imbalanced allocation with the current rebalancing logic, but which are all correctly handled with the improvements in this PR
- - Add a few testing utility methods to help "hand wave" test cases without having to specify fine-grained expectations like how many rounds of rebalance are required to reach stability after some changes have been applied to the cluster
- - Add coverage to all tests that ensures that no connectors or tasks are both revoked and assigned from the sam worker, and that the leader's view of the complete assignment of connectors and tasks across the cluster appears to be correct after each rebalance
- Miscellaneous:
- - Demote a ton of noisy `DEBUG`-level log messages to `TRACE`
### Committer Checklist (excluded from commit message)
- [ ] Verify design and implementation
- [ ] Verify test coverage and CI build status
- [ ] Verify documentation (including upgrade notes)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r862493447
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -526,165 +421,174 @@ private List<WorkerLoad> pickCandidateWorkerForReassignment(List<WorkerLoad> com
}
/**
- * Task revocation is based on an rough estimation of the lower average number of tasks before
- * and after new workers join the group. If no new workers join, no revocation takes place.
- * Based on this estimation, tasks are revoked until the new floor average is reached for
- * each existing worker. The revoked tasks, once assigned to the new workers will maintain
- * a balanced load among the group.
- *
- * @param activeAssignments
- * @param completeWorkerAssignment
- * @return
+ * Revoke connectors and tasks from each worker in the cluster until no worker is running more than it would be if:
+ * <ul>
+ * <li>The allocation of connectors and tasks across the cluster were as balanced as possible (i.e., the difference in allocation size between any two workers is at most one)</li>
+ * <li>Any workers that left the group within the scheduled rebalance delay permanently left the group</li>
+ * <li>All currently-configured connectors and tasks were allocated (including instances that may be revoked in this round because they are duplicated across workers)</li>
+ * </ul>
+ * @param configured the set of configured connectors and tasks across the entire cluster
+ * @param workers the workers in the cluster, whose assignments should not include any deleted or duplicated connectors or tasks
+ * that are already due to be revoked from the worker in this rebalance
+ * @return which connectors and tasks should be revoked from which workers; never null, but may be empty
+ * if no load-balancing revocations are necessary or possible
*/
- private Map<String, ConnectorsAndTasks> performTaskRevocation(ConnectorsAndTasks activeAssignments,
- Collection<WorkerLoad> completeWorkerAssignment) {
- int totalActiveConnectorsNum = activeAssignments.connectors().size();
- int totalActiveTasksNum = activeAssignments.tasks().size();
- Collection<WorkerLoad> existingWorkers = completeWorkerAssignment.stream()
- .filter(wl -> wl.size() > 0)
- .collect(Collectors.toList());
- int existingWorkersNum = existingWorkers.size();
- int totalWorkersNum = completeWorkerAssignment.size();
- int newWorkersNum = totalWorkersNum - existingWorkersNum;
-
- if (log.isDebugEnabled()) {
- completeWorkerAssignment.forEach(wl -> log.debug(
+ private Map<String, ConnectorsAndTasks> performLoadBalancingRevocations(
+ final ConnectorsAndTasks configured,
+ final Collection<WorkerLoad> workers
+ ) {
+ if (log.isTraceEnabled()) {
+ workers.forEach(wl -> log.trace(
"Per worker current load size; worker: {} connectors: {} tasks: {}",
wl.worker(), wl.connectorsSize(), wl.tasksSize()));
}
- Map<String, ConnectorsAndTasks> revoking = new HashMap<>();
- // If there are no new workers, or no existing workers to revoke tasks from return early
- // after logging the status
- if (!(newWorkersNum > 0 && existingWorkersNum > 0)) {
- log.debug("No task revocation required; workers with existing load: {} workers with "
- + "no load {} total workers {}",
- existingWorkersNum, newWorkersNum, totalWorkersNum);
- // This is intentionally empty but mutable, because the map is used to include deleted
- // connectors and tasks as well
- return revoking;
+ if (workers.stream().allMatch(WorkerLoad::isEmpty)) {
+ log.trace("No load-balancing revocations required; all workers are either new "
+ + "or will have all currently-assigned connectors and tasks revoked during this round"
+ );
+ return Collections.emptyMap();
+ }
+ if (configured.isEmpty()) {
+ log.trace("No load-balancing revocations required; no connectors are currently configured on this cluster");
+ return Collections.emptyMap();
}
- log.debug("Task revocation is required; workers with existing load: {} workers with "
- + "no load {} total workers {}",
- existingWorkersNum, newWorkersNum, totalWorkersNum);
-
- // We have at least one worker assignment (the leader itself) so totalWorkersNum can't be 0
- log.debug("Previous rounded down (floor) average number of connectors per worker {}", totalActiveConnectorsNum / existingWorkersNum);
- int floorConnectors = totalActiveConnectorsNum / totalWorkersNum;
- int ceilConnectors = floorConnectors + ((totalActiveConnectorsNum % totalWorkersNum == 0) ? 0 : 1);
- log.debug("New average number of connectors per worker rounded down (floor) {} and rounded up (ceil) {}", floorConnectors, ceilConnectors);
-
-
- log.debug("Previous rounded down (floor) average number of tasks per worker {}", totalActiveTasksNum / existingWorkersNum);
- int floorTasks = totalActiveTasksNum / totalWorkersNum;
- int ceilTasks = floorTasks + ((totalActiveTasksNum % totalWorkersNum == 0) ? 0 : 1);
- log.debug("New average number of tasks per worker rounded down (floor) {} and rounded up (ceil) {}", floorTasks, ceilTasks);
- int numToRevoke;
-
- for (WorkerLoad existing : existingWorkers) {
- Iterator<String> connectors = existing.connectors().iterator();
- numToRevoke = existing.connectorsSize() - ceilConnectors;
- for (int i = existing.connectorsSize(); i > floorConnectors && numToRevoke > 0; --i, --numToRevoke) {
- ConnectorsAndTasks resources = revoking.computeIfAbsent(
- existing.worker(),
- w -> new ConnectorsAndTasks.Builder().build());
- resources.connectors().add(connectors.next());
- }
+ final Map<String, ConnectorsAndTasks.Builder> result = new HashMap<>();
+
+ Map<String, Set<String>> connectorRevocations = loadBalancingRevocations(
+ "connector",
+ configured.connectors().size(),
+ workers,
+ WorkerLoad::connectors
+ );
+ Map<String, Set<ConnectorTaskId>> taskRevocations = loadBalancingRevocations(
+ "task",
+ configured.tasks().size(),
+ workers,
+ WorkerLoad::tasks
+ );
+
+ connectorRevocations.forEach((worker, revoked) ->
+ result.computeIfAbsent(worker, w -> ConnectorsAndTasks.builder())
+ .addConnectors(revoked)
+ );
+ taskRevocations.forEach((worker, revoked) ->
+ result.computeIfAbsent(worker, w -> ConnectorsAndTasks.builder())
+ .addTasks(revoked)
+ );
+
+ return buildAll(result);
+ }
+
+ private <E> Map<String, Set<E>> loadBalancingRevocations(
+ final String allocatedResourceName,
+ final int totalToAllocate,
+ final Collection<WorkerLoad> workers,
+ final Function<WorkerLoad, Collection<E>> workerAllocation
+ ) {
+ final int totalWorkers = workers.size();
+ // The minimum instances of this resource that should be assigned to each worker
+ final int minAllocatedPerWorker = totalToAllocate / totalWorkers;
+ // How many workers are going to have to be allocated exactly one extra instance
+ // (since the total number to allocate may not be a perfect multiple of the number of workers)
+ final int extrasToAllocate = totalToAllocate % totalWorkers;
+ // Useful function to determine exactly how many instances of the resource a given worker is currently allocated
+ final Function<WorkerLoad, Integer> workerAllocationSize = workerAllocation.andThen(Collection::size);
+
+ final long workersAllocatedMinimum = workers.stream()
+ .map(workerAllocationSize)
+ .filter(n -> n == minAllocatedPerWorker)
+ .count();
+ final long workersAllocatedSingleExtra = workers.stream()
+ .map(workerAllocationSize)
+ .filter(n -> n == minAllocatedPerWorker + 1)
+ .count();
+ if (workersAllocatedSingleExtra == extrasToAllocate
+ && workersAllocatedMinimum + workersAllocatedSingleExtra == totalWorkers) {
+ log.trace(
+ "No load-balancing {} revocations required; the current allocations, when combined with any newly-created {}, should be balanced",
+ allocatedResourceName,
+ allocatedResourceName
+ );
+ return Collections.emptyMap();
}
- for (WorkerLoad existing : existingWorkers) {
- Iterator<ConnectorTaskId> tasks = existing.tasks().iterator();
- numToRevoke = existing.tasksSize() - ceilTasks;
- log.debug("Tasks on worker {} is higher than ceiling, so revoking {} tasks", existing, numToRevoke);
- for (int i = existing.tasksSize(); i > floorTasks && numToRevoke > 0; --i, --numToRevoke) {
- ConnectorsAndTasks resources = revoking.computeIfAbsent(
- existing.worker(),
- w -> new ConnectorsAndTasks.Builder().build());
- resources.tasks().add(tasks.next());
+ final Map<String, Set<E>> result = new HashMap<>();
+ // How many workers we've allocated a single extra resource instance to
+ int allocatedExtras = 0;
+ for (WorkerLoad worker : workers) {
+ int currentAllocationSizeForWorker = workerAllocationSize.apply(worker);
+ if (currentAllocationSizeForWorker <= minAllocatedPerWorker) {
+ // This worker isn't allocated more than the minimum; no need to revoke anything
+ continue;
+ }
+ int maxAllocationForWorker;
+ if (allocatedExtras < extrasToAllocate) {
+ // We'll allocate one of the extra resource instances to this worker
+ allocatedExtras++;
+ if (currentAllocationSizeForWorker == minAllocatedPerWorker + 1) {
+ // If the worker's running exactly one more than the minimum, and we're allowed to
+ // allocate an extra to it, there's no need to revoke anything
+ continue;
+ }
+ maxAllocationForWorker = minAllocatedPerWorker + 1;
+ } else {
+ maxAllocationForWorker = minAllocatedPerWorker;
+ }
+
+ Set<E> revokedFromWorker = new LinkedHashSet<>();
+ result.put(worker.worker(), revokedFromWorker);
+
+ Iterator<E> currentWorkerAllocation = workerAllocation.apply(worker).iterator();
+ // Revoke resources from the worker until it isn't allocated any more than it should be
+ while (workerAllocationSize.apply(worker) > maxAllocationForWorker) {
+ if (!currentWorkerAllocation.hasNext()) {
+ // Should never happen, but better to log a warning and move on than die and fail the whole rebalance if it does
+ log.warn(
+ "Unexpectedly ran out of {}s to revoke from worker {} while performing load-balancing revocations; " +
+ "worker appears to still be allocated {} instances, which is more than the intended allocation of {}",
+ allocatedResourceName,
+ worker.worker(),
+ workerAllocationSize.apply(worker),
+ maxAllocationForWorker
+ );
+ break;
+ }
+ E revocation = currentWorkerAllocation.next();
+ revokedFromWorker.add(revocation);
+ // Make sure to remove the resource from the worker load so that later operations
+ // (such as assigning newly-created connectors and tasks) can take that into account
+ currentWorkerAllocation.remove();
}
}
+ return result;
+ }
- return revoking;
+ private int calculateDelay(long now) {
Review Comment:
I could see using many final parameters in Kafka code. So this just for code convention and safety.
```suggestion
private int calculateDelay(final long now) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r846804952
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
+ log.trace("Lost assignments: {}", lostAssignments);
- // Per worker task assignments without removing deleted connectors yet
- Map<String, Collection<ConnectorTaskId>> taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- log.debug("Complete (ignoring deletions) task assignments: {}", taskAssignments);
+ // The connectors and tasks that have been created since the last rebalance
+ final ConnectorsAndTasks created = ConnectorsAndTasks.diff(configured, previousAssignment, activeAssignments);
+ log.trace("New assignments: {}", created);
- // A collection of the current assignment excluding the connectors-and-tasks to be deleted
- List<WorkerLoad> currentWorkerAssignment = workerAssignment(memberConfigs, deleted);
+ final Map<String, ConnectorsAndTasks.Builder> toRevoke = new HashMap<>();
- Map<String, ConnectorsAndTasks> toRevoke = computeDeleted(deleted, connectorAssignments, taskAssignments);
- log.debug("Connector and task to delete assignments: {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> deletedAndRevoked = intersection(deleted, memberAssignments);
+ log.trace("Deleted connectors and tasks to revoke from each worker: {}", deletedAndRevoked);
+ addAll(toRevoke, deletedAndRevoked);
// Revoking redundant connectors/tasks if the workers have duplicate assignments
- toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
- log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> duplicatedAndRevoked = intersection(duplicated, memberAssignments);
+ log.trace("Duplicated connectors and tasks to revoke from each worker: {}", duplicatedAndRevoked);
+ addAll(toRevoke, duplicatedAndRevoked);
- // Recompute the complete assignment excluding the deleted connectors-and-tasks
- completeWorkerAssignment = workerAssignment(memberConfigs, deleted);
- connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
+ // Compute the assignment that will be applied across the cluster after this round of rebalance
+ // Later on, new submissions and lost-and-reassigned connectors and tasks will be added to these assignments,
+ // and load-balancing revocations will be removed from them.
+ final List<WorkerLoad> nextWorkerAssignment = workerLoads(memberAssignments, ConnectorsAndTasks.combine(deleted, duplicated));
- handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
+ final ConnectorsAndTasks.Builder lostAssignmentsToReassign = ConnectorsAndTasks.builder();
+ handleLostAssignments(lostAssignments, lostAssignmentsToReassign, nextWorkerAssignment);
// Do not revoke resources for re-assignment while a delayed rebalance is active
- // Also we do not revoke in two consecutive rebalances by the same leader
- canRevoke = delay == 0 && canRevoke;
+ // Also we do not revoke in two consecutive rebalances by the same leader, which
+ // should be fine since workers immediately rejoin the group after a rebalance
+ // if connectors and/or tasks were revoked from them
+ canRevoke = canRevoke && delay == 0;
// Compute the connectors-and-tasks to be revoked for load balancing without taking into
// account the deleted ones.
- log.debug("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
+ log.trace("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
if (canRevoke) {
- Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
-
- toExplicitlyRevoke.forEach(
- (worker, assignment) -> {
- ConnectorsAndTasks existing = toRevoke.computeIfAbsent(
- worker,
- v -> new ConnectorsAndTasks.Builder().build());
- existing.connectors().addAll(assignment.connectors());
- existing.tasks().addAll(assignment.tasks());
- }
- );
- canRevoke = toExplicitlyRevoke.size() == 0;
+ Map<String, ConnectorsAndTasks> loadBalancingRevocations =
+ performLoadBalancingRevocations(configured, nextWorkerAssignment);
+
+ log.trace("Load-balancing revocations for each worker: {}", loadBalancingRevocations);
+ addAll(toRevoke, loadBalancingRevocations);
+ canRevoke = ConnectorsAndTasks.combine(loadBalancingRevocations.values()).isEmpty();
} else {
canRevoke = delay == 0;
}
- assignConnectors(completeWorkerAssignment, newSubmissions.connectors());
- assignTasks(completeWorkerAssignment, newSubmissions.tasks());
- log.debug("Current complete assignments: {}", currentWorkerAssignment);
- log.debug("New complete assignments: {}", completeWorkerAssignment);
+ final ConnectorsAndTasks toAssign = ConnectorsAndTasks.combine(created, lostAssignmentsToReassign.build());
+ assignConnectors(nextWorkerAssignment, toAssign.connectors());
+ assignTasks(nextWorkerAssignment, toAssign.tasks());
- Map<String, Collection<String>> currentConnectorAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- Map<String, Collection<ConnectorTaskId>> currentTaskAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- Map<String, Collection<String>> incrementalConnectorAssignments =
- diff(connectorAssignments, currentConnectorAssignments);
- Map<String, Collection<ConnectorTaskId>> incrementalTaskAssignments =
- diff(taskAssignments, currentTaskAssignments);
+ // The complete set of connectors and tasks that will be running on each worker after this rebalance
+ final Map<String, ConnectorsAndTasks> nextAssignments = assignments(nextWorkerAssignment);
- log.debug("Incremental connector assignments: {}", incrementalConnectorAssignments);
- log.debug("Incremental task assignments: {}", incrementalTaskAssignments);
+ log.debug("Current complete assignments: {}", memberAssignments);
+ log.debug("New complete assignments: {}", nextAssignments);
Review Comment:
Just minor suggestion and could be ignored. What about changing `New` to `Next`? Because using variable `nextAssignments` for parameter, so logging `Next` looks more clear.
```suggestion
log.debug("Next complete assignments: {}", nextAssignments);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r862491251
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -723,44 +610,175 @@ protected void assignConnectors(List<WorkerLoad> workerAssignment, Collection<St
* @param workerAssignment the current worker assignment; assigned tasks are added to this list
* @param tasks the tasks to be assigned
*/
- protected void assignTasks(List<WorkerLoad> workerAssignment, Collection<ConnectorTaskId> tasks) {
- workerAssignment.sort(WorkerLoad.taskComparator());
- WorkerLoad first = workerAssignment.get(0);
+ // Visible for testing
+ void assignTasks(List<WorkerLoad> workerAssignment, Collection<ConnectorTaskId> tasks) {
+ assign(workerAssignment, tasks, WorkerLoad::tasks, WorkerLoad::assign);
+ }
- Iterator<ConnectorTaskId> load = tasks.iterator();
+ private <E> void assign(
+ List<WorkerLoad> workers,
+ Collection<E> toAssign,
+ Function<WorkerLoad, Collection<E>> currentAllocation,
+ BiConsumer<WorkerLoad, E> assignToWorker
+ ) {
+ Function<WorkerLoad, Integer> allocationSize = currentAllocation.andThen(Collection::size);
+ workers.sort(Comparator.comparing(allocationSize));
+ WorkerLoad first = workers.get(0);
+
+ Iterator<E> load = toAssign.stream().sorted().iterator();
while (load.hasNext()) {
- int firstLoad = first.tasksSize();
- int upTo = IntStream.range(0, workerAssignment.size())
- .filter(i -> workerAssignment.get(i).tasksSize() > firstLoad)
+ int firstLoad = allocationSize.apply(first);
+ int upTo = IntStream.range(0, workers.size())
Review Comment:
This is minor suggestion and could be ignored.
If calculate `workers.size` in while loop it has to be calculated all the time until it is true.
What about calculating size one time then use it many times.
```
int workersSize = workers.size();
IntStream.range(0, workersSize)
```
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -723,44 +610,175 @@ protected void assignConnectors(List<WorkerLoad> workerAssignment, Collection<St
* @param workerAssignment the current worker assignment; assigned tasks are added to this list
* @param tasks the tasks to be assigned
*/
- protected void assignTasks(List<WorkerLoad> workerAssignment, Collection<ConnectorTaskId> tasks) {
- workerAssignment.sort(WorkerLoad.taskComparator());
- WorkerLoad first = workerAssignment.get(0);
+ // Visible for testing
+ void assignTasks(List<WorkerLoad> workerAssignment, Collection<ConnectorTaskId> tasks) {
+ assign(workerAssignment, tasks, WorkerLoad::tasks, WorkerLoad::assign);
+ }
- Iterator<ConnectorTaskId> load = tasks.iterator();
+ private <E> void assign(
+ List<WorkerLoad> workers,
+ Collection<E> toAssign,
+ Function<WorkerLoad, Collection<E>> currentAllocation,
+ BiConsumer<WorkerLoad, E> assignToWorker
+ ) {
+ Function<WorkerLoad, Integer> allocationSize = currentAllocation.andThen(Collection::size);
+ workers.sort(Comparator.comparing(allocationSize));
+ WorkerLoad first = workers.get(0);
+
+ Iterator<E> load = toAssign.stream().sorted().iterator();
while (load.hasNext()) {
- int firstLoad = first.tasksSize();
- int upTo = IntStream.range(0, workerAssignment.size())
- .filter(i -> workerAssignment.get(i).tasksSize() > firstLoad)
+ int firstLoad = allocationSize.apply(first);
+ int upTo = IntStream.range(0, workers.size())
Review Comment:
This is minor suggestion and could be ignored.
If calculate `workers.size` in while loop it has to be calculated all the time while it is true.
What about calculating size one time then use it many times.
```
int workersSize = workers.size();
IntStream.range(0, workersSize)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] C0urante closed pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
C0urante closed pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
URL: https://github.com/apache/kafka/pull/12019
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on PR #12019:
URL: https://github.com/apache/kafka/pull/12019#issuecomment-1200166542
> Converting this to a draft since I haven't had time to prioritize it (sorry @YeonCheolGit!) and the changes here are not safe to merge as-are.
No worries @C0urante! All good and thanks for letting me know this:)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r847446537
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
+ log.trace("Lost assignments: {}", lostAssignments);
- // Per worker task assignments without removing deleted connectors yet
- Map<String, Collection<ConnectorTaskId>> taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- log.debug("Complete (ignoring deletions) task assignments: {}", taskAssignments);
+ // The connectors and tasks that have been created since the last rebalance
+ final ConnectorsAndTasks created = ConnectorsAndTasks.diff(configured, previousAssignment, activeAssignments);
+ log.trace("New assignments: {}", created);
- // A collection of the current assignment excluding the connectors-and-tasks to be deleted
- List<WorkerLoad> currentWorkerAssignment = workerAssignment(memberConfigs, deleted);
+ final Map<String, ConnectorsAndTasks.Builder> toRevoke = new HashMap<>();
- Map<String, ConnectorsAndTasks> toRevoke = computeDeleted(deleted, connectorAssignments, taskAssignments);
- log.debug("Connector and task to delete assignments: {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> deletedAndRevoked = intersection(deleted, memberAssignments);
+ log.trace("Deleted connectors and tasks to revoke from each worker: {}", deletedAndRevoked);
+ addAll(toRevoke, deletedAndRevoked);
// Revoking redundant connectors/tasks if the workers have duplicate assignments
- toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
- log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> duplicatedAndRevoked = intersection(duplicated, memberAssignments);
+ log.trace("Duplicated connectors and tasks to revoke from each worker: {}", duplicatedAndRevoked);
+ addAll(toRevoke, duplicatedAndRevoked);
- // Recompute the complete assignment excluding the deleted connectors-and-tasks
- completeWorkerAssignment = workerAssignment(memberConfigs, deleted);
- connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
+ // Compute the assignment that will be applied across the cluster after this round of rebalance
+ // Later on, new submissions and lost-and-reassigned connectors and tasks will be added to these assignments,
+ // and load-balancing revocations will be removed from them.
+ final List<WorkerLoad> nextWorkerAssignment = workerLoads(memberAssignments, ConnectorsAndTasks.combine(deleted, duplicated));
- handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
+ final ConnectorsAndTasks.Builder lostAssignmentsToReassign = ConnectorsAndTasks.builder();
+ handleLostAssignments(lostAssignments, lostAssignmentsToReassign, nextWorkerAssignment);
// Do not revoke resources for re-assignment while a delayed rebalance is active
- // Also we do not revoke in two consecutive rebalances by the same leader
- canRevoke = delay == 0 && canRevoke;
+ // Also we do not revoke in two consecutive rebalances by the same leader, which
+ // should be fine since workers immediately rejoin the group after a rebalance
+ // if connectors and/or tasks were revoked from them
+ canRevoke = canRevoke && delay == 0;
// Compute the connectors-and-tasks to be revoked for load balancing without taking into
// account the deleted ones.
- log.debug("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
+ log.trace("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
if (canRevoke) {
- Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
-
- toExplicitlyRevoke.forEach(
- (worker, assignment) -> {
- ConnectorsAndTasks existing = toRevoke.computeIfAbsent(
- worker,
- v -> new ConnectorsAndTasks.Builder().build());
- existing.connectors().addAll(assignment.connectors());
- existing.tasks().addAll(assignment.tasks());
- }
- );
- canRevoke = toExplicitlyRevoke.size() == 0;
+ Map<String, ConnectorsAndTasks> loadBalancingRevocations =
+ performLoadBalancingRevocations(configured, nextWorkerAssignment);
+
+ log.trace("Load-balancing revocations for each worker: {}", loadBalancingRevocations);
+ addAll(toRevoke, loadBalancingRevocations);
+ canRevoke = ConnectorsAndTasks.combine(loadBalancingRevocations.values()).isEmpty();
} else {
canRevoke = delay == 0;
}
- assignConnectors(completeWorkerAssignment, newSubmissions.connectors());
- assignTasks(completeWorkerAssignment, newSubmissions.tasks());
- log.debug("Current complete assignments: {}", currentWorkerAssignment);
- log.debug("New complete assignments: {}", completeWorkerAssignment);
+ final ConnectorsAndTasks toAssign = ConnectorsAndTasks.combine(created, lostAssignmentsToReassign.build());
+ assignConnectors(nextWorkerAssignment, toAssign.connectors());
+ assignTasks(nextWorkerAssignment, toAssign.tasks());
- Map<String, Collection<String>> currentConnectorAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- Map<String, Collection<ConnectorTaskId>> currentTaskAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- Map<String, Collection<String>> incrementalConnectorAssignments =
- diff(connectorAssignments, currentConnectorAssignments);
- Map<String, Collection<ConnectorTaskId>> incrementalTaskAssignments =
- diff(taskAssignments, currentTaskAssignments);
+ // The complete set of connectors and tasks that will be running on each worker after this rebalance
+ final Map<String, ConnectorsAndTasks> nextAssignments = assignments(nextWorkerAssignment);
- log.debug("Incremental connector assignments: {}", incrementalConnectorAssignments);
- log.debug("Incremental task assignments: {}", incrementalTaskAssignments);
+ log.debug("Current complete assignments: {}", memberAssignments);
+ log.debug("New complete assignments: {}", nextAssignments);
Review Comment:
@C0urante
Thank you for the reply:)
Maybe keeping `next` is looking better for me. Because if we change `new` to `next`, we need to change all variable names and consider huge side effects.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r862455239
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ protected Map<String, ByteBuffer> performTaskAssignment(String leaderId, long ma
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
Review Comment:
Could you explain what `lost` assignment meaning is?
As far as i know `ConnectorsAndTasks.diff` returns remainder after subtracted assignments.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r846804952
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
+ log.trace("Lost assignments: {}", lostAssignments);
- // Per worker task assignments without removing deleted connectors yet
- Map<String, Collection<ConnectorTaskId>> taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- log.debug("Complete (ignoring deletions) task assignments: {}", taskAssignments);
+ // The connectors and tasks that have been created since the last rebalance
+ final ConnectorsAndTasks created = ConnectorsAndTasks.diff(configured, previousAssignment, activeAssignments);
+ log.trace("New assignments: {}", created);
- // A collection of the current assignment excluding the connectors-and-tasks to be deleted
- List<WorkerLoad> currentWorkerAssignment = workerAssignment(memberConfigs, deleted);
+ final Map<String, ConnectorsAndTasks.Builder> toRevoke = new HashMap<>();
- Map<String, ConnectorsAndTasks> toRevoke = computeDeleted(deleted, connectorAssignments, taskAssignments);
- log.debug("Connector and task to delete assignments: {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> deletedAndRevoked = intersection(deleted, memberAssignments);
+ log.trace("Deleted connectors and tasks to revoke from each worker: {}", deletedAndRevoked);
+ addAll(toRevoke, deletedAndRevoked);
// Revoking redundant connectors/tasks if the workers have duplicate assignments
- toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
- log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> duplicatedAndRevoked = intersection(duplicated, memberAssignments);
+ log.trace("Duplicated connectors and tasks to revoke from each worker: {}", duplicatedAndRevoked);
+ addAll(toRevoke, duplicatedAndRevoked);
- // Recompute the complete assignment excluding the deleted connectors-and-tasks
- completeWorkerAssignment = workerAssignment(memberConfigs, deleted);
- connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
+ // Compute the assignment that will be applied across the cluster after this round of rebalance
+ // Later on, new submissions and lost-and-reassigned connectors and tasks will be added to these assignments,
+ // and load-balancing revocations will be removed from them.
+ final List<WorkerLoad> nextWorkerAssignment = workerLoads(memberAssignments, ConnectorsAndTasks.combine(deleted, duplicated));
- handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
+ final ConnectorsAndTasks.Builder lostAssignmentsToReassign = ConnectorsAndTasks.builder();
+ handleLostAssignments(lostAssignments, lostAssignmentsToReassign, nextWorkerAssignment);
// Do not revoke resources for re-assignment while a delayed rebalance is active
- // Also we do not revoke in two consecutive rebalances by the same leader
- canRevoke = delay == 0 && canRevoke;
+ // Also we do not revoke in two consecutive rebalances by the same leader, which
+ // should be fine since workers immediately rejoin the group after a rebalance
+ // if connectors and/or tasks were revoked from them
+ canRevoke = canRevoke && delay == 0;
// Compute the connectors-and-tasks to be revoked for load balancing without taking into
// account the deleted ones.
- log.debug("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
+ log.trace("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
if (canRevoke) {
- Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
-
- toExplicitlyRevoke.forEach(
- (worker, assignment) -> {
- ConnectorsAndTasks existing = toRevoke.computeIfAbsent(
- worker,
- v -> new ConnectorsAndTasks.Builder().build());
- existing.connectors().addAll(assignment.connectors());
- existing.tasks().addAll(assignment.tasks());
- }
- );
- canRevoke = toExplicitlyRevoke.size() == 0;
+ Map<String, ConnectorsAndTasks> loadBalancingRevocations =
+ performLoadBalancingRevocations(configured, nextWorkerAssignment);
+
+ log.trace("Load-balancing revocations for each worker: {}", loadBalancingRevocations);
+ addAll(toRevoke, loadBalancingRevocations);
+ canRevoke = ConnectorsAndTasks.combine(loadBalancingRevocations.values()).isEmpty();
} else {
canRevoke = delay == 0;
}
- assignConnectors(completeWorkerAssignment, newSubmissions.connectors());
- assignTasks(completeWorkerAssignment, newSubmissions.tasks());
- log.debug("Current complete assignments: {}", currentWorkerAssignment);
- log.debug("New complete assignments: {}", completeWorkerAssignment);
+ final ConnectorsAndTasks toAssign = ConnectorsAndTasks.combine(created, lostAssignmentsToReassign.build());
+ assignConnectors(nextWorkerAssignment, toAssign.connectors());
+ assignTasks(nextWorkerAssignment, toAssign.tasks());
- Map<String, Collection<String>> currentConnectorAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- Map<String, Collection<ConnectorTaskId>> currentTaskAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- Map<String, Collection<String>> incrementalConnectorAssignments =
- diff(connectorAssignments, currentConnectorAssignments);
- Map<String, Collection<ConnectorTaskId>> incrementalTaskAssignments =
- diff(taskAssignments, currentTaskAssignments);
+ // The complete set of connectors and tasks that will be running on each worker after this rebalance
+ final Map<String, ConnectorsAndTasks> nextAssignments = assignments(nextWorkerAssignment);
- log.debug("Incremental connector assignments: {}", incrementalConnectorAssignments);
- log.debug("Incremental task assignments: {}", incrementalTaskAssignments);
+ log.debug("Current complete assignments: {}", memberAssignments);
+ log.debug("New complete assignments: {}", nextAssignments);
Review Comment:
Just minor suggestion and can be ignored. What about changing `New` to `Next`? Because using variable `nextAssignments` for parameter, so logging `Next` looks more clear.
```suggestion
log.debug("New complete assignments: {}", nextAssignments);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] C0urante commented on pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
C0urante commented on PR #12019:
URL: https://github.com/apache/kafka/pull/12019#issuecomment-1107868975
Hi @YeonCheolGit! There's always more PRs to review than there are reviewers (especially with Connect), so feel free to give this (or probably https://github.com/apache/kafka/pull/11983, which this PR depends on) a review if you'd like to help.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r862491251
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -723,44 +610,175 @@ protected void assignConnectors(List<WorkerLoad> workerAssignment, Collection<St
* @param workerAssignment the current worker assignment; assigned tasks are added to this list
* @param tasks the tasks to be assigned
*/
- protected void assignTasks(List<WorkerLoad> workerAssignment, Collection<ConnectorTaskId> tasks) {
- workerAssignment.sort(WorkerLoad.taskComparator());
- WorkerLoad first = workerAssignment.get(0);
+ // Visible for testing
+ void assignTasks(List<WorkerLoad> workerAssignment, Collection<ConnectorTaskId> tasks) {
+ assign(workerAssignment, tasks, WorkerLoad::tasks, WorkerLoad::assign);
+ }
- Iterator<ConnectorTaskId> load = tasks.iterator();
+ private <E> void assign(
+ List<WorkerLoad> workers,
+ Collection<E> toAssign,
+ Function<WorkerLoad, Collection<E>> currentAllocation,
+ BiConsumer<WorkerLoad, E> assignToWorker
+ ) {
+ Function<WorkerLoad, Integer> allocationSize = currentAllocation.andThen(Collection::size);
+ workers.sort(Comparator.comparing(allocationSize));
+ WorkerLoad first = workers.get(0);
+
+ Iterator<E> load = toAssign.stream().sorted().iterator();
while (load.hasNext()) {
- int firstLoad = first.tasksSize();
- int upTo = IntStream.range(0, workerAssignment.size())
- .filter(i -> workerAssignment.get(i).tasksSize() > firstLoad)
+ int firstLoad = allocationSize.apply(first);
+ int upTo = IntStream.range(0, workers.size())
Review Comment:
This is minor suggestion and could be ignored.
If calculate `workers.size` in while loop it has to be calculated all the time while it is true.
What about calculating size one time then use it many times.
```
final int workersSize = workers.size();
IntStream.range(0, workersSize)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r862388033
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -110,14 +114,18 @@ public Map<String, ByteBuffer> performAssignment(String leaderId, String protoco
: CONNECT_PROTOCOL_V1;
Long leaderOffset = ensureLeaderConfig(maxOffset, coordinator);
+ Map<String, ExtendedAssignment> assignments;
if (leaderOffset == null) {
- Map<String, ExtendedAssignment> assignments = fillAssignments(
+ assignments = fillAssignments(
memberConfigs.keySet(), Assignment.CONFIG_MISMATCH,
- leaderId, memberConfigs.get(leaderId).url(), maxOffset, Collections.emptyMap(),
- Collections.emptyMap(), Collections.emptyMap(), 0, protocolVersion);
- return serializeAssignments(assignments);
+ leaderId, memberConfigs.get(leaderId).url(), maxOffset,
+ ClusterAssignment.EMPTY, 0, protocolVersion);
+ } else {
+ assignments = performTaskAssignment(leaderId, leaderOffset, memberConfigs, coordinator, protocolVersion);
}
- return performTaskAssignment(leaderId, leaderOffset, memberConfigs, coordinator, protocolVersion);
+ Map<String, ByteBuffer> result = serializeAssignments(assignments);
+ log.debug("Finished assignment");
Review Comment:
This works with `Map<String, ExtendedAssignment> assignment's'`.
So maybe this?
```suggestion
log.debug("Finished assignments");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r846804952
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
+ log.trace("Lost assignments: {}", lostAssignments);
- // Per worker task assignments without removing deleted connectors yet
- Map<String, Collection<ConnectorTaskId>> taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- log.debug("Complete (ignoring deletions) task assignments: {}", taskAssignments);
+ // The connectors and tasks that have been created since the last rebalance
+ final ConnectorsAndTasks created = ConnectorsAndTasks.diff(configured, previousAssignment, activeAssignments);
+ log.trace("New assignments: {}", created);
- // A collection of the current assignment excluding the connectors-and-tasks to be deleted
- List<WorkerLoad> currentWorkerAssignment = workerAssignment(memberConfigs, deleted);
+ final Map<String, ConnectorsAndTasks.Builder> toRevoke = new HashMap<>();
- Map<String, ConnectorsAndTasks> toRevoke = computeDeleted(deleted, connectorAssignments, taskAssignments);
- log.debug("Connector and task to delete assignments: {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> deletedAndRevoked = intersection(deleted, memberAssignments);
+ log.trace("Deleted connectors and tasks to revoke from each worker: {}", deletedAndRevoked);
+ addAll(toRevoke, deletedAndRevoked);
// Revoking redundant connectors/tasks if the workers have duplicate assignments
- toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
- log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> duplicatedAndRevoked = intersection(duplicated, memberAssignments);
+ log.trace("Duplicated connectors and tasks to revoke from each worker: {}", duplicatedAndRevoked);
+ addAll(toRevoke, duplicatedAndRevoked);
- // Recompute the complete assignment excluding the deleted connectors-and-tasks
- completeWorkerAssignment = workerAssignment(memberConfigs, deleted);
- connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
+ // Compute the assignment that will be applied across the cluster after this round of rebalance
+ // Later on, new submissions and lost-and-reassigned connectors and tasks will be added to these assignments,
+ // and load-balancing revocations will be removed from them.
+ final List<WorkerLoad> nextWorkerAssignment = workerLoads(memberAssignments, ConnectorsAndTasks.combine(deleted, duplicated));
- handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
+ final ConnectorsAndTasks.Builder lostAssignmentsToReassign = ConnectorsAndTasks.builder();
+ handleLostAssignments(lostAssignments, lostAssignmentsToReassign, nextWorkerAssignment);
// Do not revoke resources for re-assignment while a delayed rebalance is active
- // Also we do not revoke in two consecutive rebalances by the same leader
- canRevoke = delay == 0 && canRevoke;
+ // Also we do not revoke in two consecutive rebalances by the same leader, which
+ // should be fine since workers immediately rejoin the group after a rebalance
+ // if connectors and/or tasks were revoked from them
+ canRevoke = canRevoke && delay == 0;
// Compute the connectors-and-tasks to be revoked for load balancing without taking into
// account the deleted ones.
- log.debug("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
+ log.trace("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
if (canRevoke) {
- Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
-
- toExplicitlyRevoke.forEach(
- (worker, assignment) -> {
- ConnectorsAndTasks existing = toRevoke.computeIfAbsent(
- worker,
- v -> new ConnectorsAndTasks.Builder().build());
- existing.connectors().addAll(assignment.connectors());
- existing.tasks().addAll(assignment.tasks());
- }
- );
- canRevoke = toExplicitlyRevoke.size() == 0;
+ Map<String, ConnectorsAndTasks> loadBalancingRevocations =
+ performLoadBalancingRevocations(configured, nextWorkerAssignment);
+
+ log.trace("Load-balancing revocations for each worker: {}", loadBalancingRevocations);
+ addAll(toRevoke, loadBalancingRevocations);
+ canRevoke = ConnectorsAndTasks.combine(loadBalancingRevocations.values()).isEmpty();
} else {
canRevoke = delay == 0;
}
- assignConnectors(completeWorkerAssignment, newSubmissions.connectors());
- assignTasks(completeWorkerAssignment, newSubmissions.tasks());
- log.debug("Current complete assignments: {}", currentWorkerAssignment);
- log.debug("New complete assignments: {}", completeWorkerAssignment);
+ final ConnectorsAndTasks toAssign = ConnectorsAndTasks.combine(created, lostAssignmentsToReassign.build());
+ assignConnectors(nextWorkerAssignment, toAssign.connectors());
+ assignTasks(nextWorkerAssignment, toAssign.tasks());
- Map<String, Collection<String>> currentConnectorAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- Map<String, Collection<ConnectorTaskId>> currentTaskAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- Map<String, Collection<String>> incrementalConnectorAssignments =
- diff(connectorAssignments, currentConnectorAssignments);
- Map<String, Collection<ConnectorTaskId>> incrementalTaskAssignments =
- diff(taskAssignments, currentTaskAssignments);
+ // The complete set of connectors and tasks that will be running on each worker after this rebalance
+ final Map<String, ConnectorsAndTasks> nextAssignments = assignments(nextWorkerAssignment);
- log.debug("Incremental connector assignments: {}", incrementalConnectorAssignments);
- log.debug("Incremental task assignments: {}", incrementalTaskAssignments);
+ log.debug("Current complete assignments: {}", memberAssignments);
+ log.debug("New complete assignments: {}", nextAssignments);
Review Comment:
Just minor suggestion and coulbe be ignored. What about changing `New` to `Next`? Because using variable `nextAssignments` for parameter, so logging `Next` looks more clear.
```suggestion
log.debug("New complete assignments: {}", nextAssignments);
```
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
+ log.trace("Lost assignments: {}", lostAssignments);
- // Per worker task assignments without removing deleted connectors yet
- Map<String, Collection<ConnectorTaskId>> taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- log.debug("Complete (ignoring deletions) task assignments: {}", taskAssignments);
+ // The connectors and tasks that have been created since the last rebalance
+ final ConnectorsAndTasks created = ConnectorsAndTasks.diff(configured, previousAssignment, activeAssignments);
+ log.trace("New assignments: {}", created);
- // A collection of the current assignment excluding the connectors-and-tasks to be deleted
- List<WorkerLoad> currentWorkerAssignment = workerAssignment(memberConfigs, deleted);
+ final Map<String, ConnectorsAndTasks.Builder> toRevoke = new HashMap<>();
- Map<String, ConnectorsAndTasks> toRevoke = computeDeleted(deleted, connectorAssignments, taskAssignments);
- log.debug("Connector and task to delete assignments: {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> deletedAndRevoked = intersection(deleted, memberAssignments);
+ log.trace("Deleted connectors and tasks to revoke from each worker: {}", deletedAndRevoked);
+ addAll(toRevoke, deletedAndRevoked);
// Revoking redundant connectors/tasks if the workers have duplicate assignments
- toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
- log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> duplicatedAndRevoked = intersection(duplicated, memberAssignments);
+ log.trace("Duplicated connectors and tasks to revoke from each worker: {}", duplicatedAndRevoked);
+ addAll(toRevoke, duplicatedAndRevoked);
- // Recompute the complete assignment excluding the deleted connectors-and-tasks
- completeWorkerAssignment = workerAssignment(memberConfigs, deleted);
- connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
+ // Compute the assignment that will be applied across the cluster after this round of rebalance
+ // Later on, new submissions and lost-and-reassigned connectors and tasks will be added to these assignments,
+ // and load-balancing revocations will be removed from them.
+ final List<WorkerLoad> nextWorkerAssignment = workerLoads(memberAssignments, ConnectorsAndTasks.combine(deleted, duplicated));
- handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
+ final ConnectorsAndTasks.Builder lostAssignmentsToReassign = ConnectorsAndTasks.builder();
+ handleLostAssignments(lostAssignments, lostAssignmentsToReassign, nextWorkerAssignment);
// Do not revoke resources for re-assignment while a delayed rebalance is active
- // Also we do not revoke in two consecutive rebalances by the same leader
- canRevoke = delay == 0 && canRevoke;
+ // Also we do not revoke in two consecutive rebalances by the same leader, which
+ // should be fine since workers immediately rejoin the group after a rebalance
+ // if connectors and/or tasks were revoked from them
+ canRevoke = canRevoke && delay == 0;
// Compute the connectors-and-tasks to be revoked for load balancing without taking into
// account the deleted ones.
- log.debug("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
+ log.trace("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
if (canRevoke) {
- Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
-
- toExplicitlyRevoke.forEach(
- (worker, assignment) -> {
- ConnectorsAndTasks existing = toRevoke.computeIfAbsent(
- worker,
- v -> new ConnectorsAndTasks.Builder().build());
- existing.connectors().addAll(assignment.connectors());
- existing.tasks().addAll(assignment.tasks());
- }
- );
- canRevoke = toExplicitlyRevoke.size() == 0;
+ Map<String, ConnectorsAndTasks> loadBalancingRevocations =
+ performLoadBalancingRevocations(configured, nextWorkerAssignment);
+
+ log.trace("Load-balancing revocations for each worker: {}", loadBalancingRevocations);
+ addAll(toRevoke, loadBalancingRevocations);
+ canRevoke = ConnectorsAndTasks.combine(loadBalancingRevocations.values()).isEmpty();
} else {
canRevoke = delay == 0;
}
- assignConnectors(completeWorkerAssignment, newSubmissions.connectors());
- assignTasks(completeWorkerAssignment, newSubmissions.tasks());
- log.debug("Current complete assignments: {}", currentWorkerAssignment);
- log.debug("New complete assignments: {}", completeWorkerAssignment);
+ final ConnectorsAndTasks toAssign = ConnectorsAndTasks.combine(created, lostAssignmentsToReassign.build());
+ assignConnectors(nextWorkerAssignment, toAssign.connectors());
+ assignTasks(nextWorkerAssignment, toAssign.tasks());
- Map<String, Collection<String>> currentConnectorAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- Map<String, Collection<ConnectorTaskId>> currentTaskAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- Map<String, Collection<String>> incrementalConnectorAssignments =
- diff(connectorAssignments, currentConnectorAssignments);
- Map<String, Collection<ConnectorTaskId>> incrementalTaskAssignments =
- diff(taskAssignments, currentTaskAssignments);
+ // The complete set of connectors and tasks that will be running on each worker after this rebalance
+ final Map<String, ConnectorsAndTasks> nextAssignments = assignments(nextWorkerAssignment);
- log.debug("Incremental connector assignments: {}", incrementalConnectorAssignments);
- log.debug("Incremental task assignments: {}", incrementalTaskAssignments);
+ log.debug("Current complete assignments: {}", memberAssignments);
+ log.debug("New complete assignments: {}", nextAssignments);
Review Comment:
Just minor suggestion and could be ignored. What about changing `New` to `Next`? Because using variable `nextAssignments` for parameter, so logging `Next` looks more clear.
```suggestion
log.debug("New complete assignments: {}", nextAssignments);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r846804952
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
+ log.trace("Lost assignments: {}", lostAssignments);
- // Per worker task assignments without removing deleted connectors yet
- Map<String, Collection<ConnectorTaskId>> taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- log.debug("Complete (ignoring deletions) task assignments: {}", taskAssignments);
+ // The connectors and tasks that have been created since the last rebalance
+ final ConnectorsAndTasks created = ConnectorsAndTasks.diff(configured, previousAssignment, activeAssignments);
+ log.trace("New assignments: {}", created);
- // A collection of the current assignment excluding the connectors-and-tasks to be deleted
- List<WorkerLoad> currentWorkerAssignment = workerAssignment(memberConfigs, deleted);
+ final Map<String, ConnectorsAndTasks.Builder> toRevoke = new HashMap<>();
- Map<String, ConnectorsAndTasks> toRevoke = computeDeleted(deleted, connectorAssignments, taskAssignments);
- log.debug("Connector and task to delete assignments: {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> deletedAndRevoked = intersection(deleted, memberAssignments);
+ log.trace("Deleted connectors and tasks to revoke from each worker: {}", deletedAndRevoked);
+ addAll(toRevoke, deletedAndRevoked);
// Revoking redundant connectors/tasks if the workers have duplicate assignments
- toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
- log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> duplicatedAndRevoked = intersection(duplicated, memberAssignments);
+ log.trace("Duplicated connectors and tasks to revoke from each worker: {}", duplicatedAndRevoked);
+ addAll(toRevoke, duplicatedAndRevoked);
- // Recompute the complete assignment excluding the deleted connectors-and-tasks
- completeWorkerAssignment = workerAssignment(memberConfigs, deleted);
- connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
+ // Compute the assignment that will be applied across the cluster after this round of rebalance
+ // Later on, new submissions and lost-and-reassigned connectors and tasks will be added to these assignments,
+ // and load-balancing revocations will be removed from them.
+ final List<WorkerLoad> nextWorkerAssignment = workerLoads(memberAssignments, ConnectorsAndTasks.combine(deleted, duplicated));
- handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
+ final ConnectorsAndTasks.Builder lostAssignmentsToReassign = ConnectorsAndTasks.builder();
+ handleLostAssignments(lostAssignments, lostAssignmentsToReassign, nextWorkerAssignment);
// Do not revoke resources for re-assignment while a delayed rebalance is active
- // Also we do not revoke in two consecutive rebalances by the same leader
- canRevoke = delay == 0 && canRevoke;
+ // Also we do not revoke in two consecutive rebalances by the same leader, which
+ // should be fine since workers immediately rejoin the group after a rebalance
+ // if connectors and/or tasks were revoked from them
+ canRevoke = canRevoke && delay == 0;
// Compute the connectors-and-tasks to be revoked for load balancing without taking into
// account the deleted ones.
- log.debug("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
+ log.trace("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
if (canRevoke) {
- Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
-
- toExplicitlyRevoke.forEach(
- (worker, assignment) -> {
- ConnectorsAndTasks existing = toRevoke.computeIfAbsent(
- worker,
- v -> new ConnectorsAndTasks.Builder().build());
- existing.connectors().addAll(assignment.connectors());
- existing.tasks().addAll(assignment.tasks());
- }
- );
- canRevoke = toExplicitlyRevoke.size() == 0;
+ Map<String, ConnectorsAndTasks> loadBalancingRevocations =
+ performLoadBalancingRevocations(configured, nextWorkerAssignment);
+
+ log.trace("Load-balancing revocations for each worker: {}", loadBalancingRevocations);
+ addAll(toRevoke, loadBalancingRevocations);
+ canRevoke = ConnectorsAndTasks.combine(loadBalancingRevocations.values()).isEmpty();
} else {
canRevoke = delay == 0;
}
- assignConnectors(completeWorkerAssignment, newSubmissions.connectors());
- assignTasks(completeWorkerAssignment, newSubmissions.tasks());
- log.debug("Current complete assignments: {}", currentWorkerAssignment);
- log.debug("New complete assignments: {}", completeWorkerAssignment);
+ final ConnectorsAndTasks toAssign = ConnectorsAndTasks.combine(created, lostAssignmentsToReassign.build());
+ assignConnectors(nextWorkerAssignment, toAssign.connectors());
+ assignTasks(nextWorkerAssignment, toAssign.tasks());
- Map<String, Collection<String>> currentConnectorAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- Map<String, Collection<ConnectorTaskId>> currentTaskAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- Map<String, Collection<String>> incrementalConnectorAssignments =
- diff(connectorAssignments, currentConnectorAssignments);
- Map<String, Collection<ConnectorTaskId>> incrementalTaskAssignments =
- diff(taskAssignments, currentTaskAssignments);
+ // The complete set of connectors and tasks that will be running on each worker after this rebalance
+ final Map<String, ConnectorsAndTasks> nextAssignments = assignments(nextWorkerAssignment);
- log.debug("Incremental connector assignments: {}", incrementalConnectorAssignments);
- log.debug("Incremental task assignments: {}", incrementalTaskAssignments);
+ log.debug("Current complete assignments: {}", memberAssignments);
+ log.debug("New complete assignments: {}", nextAssignments);
Review Comment:
Just minor suggestion and could be ignored. What about changing `New` to `Next`? Because using variable `nextAssignments` for parameter, so logging `Next` looks more clear.
```suggestion
log.debug("Next complete assignments: {}", nextAssignments);
```
@C0urante
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on PR #12019:
URL: https://github.com/apache/kafka/pull/12019#issuecomment-1107446382
@C0urante
Hello! I am just wondering that how this PR is going? Is threre anything that i can help with?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] C0urante commented on pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
C0urante commented on PR #12019:
URL: https://github.com/apache/kafka/pull/12019#issuecomment-1094487905
Apologies @showuon, this does not actually (fully) address KAFKA-12495. Several of the test cases here relied on rebalances being triggered in circumstances that they would not normally be triggered under, which caused the issue with not performing consecutive revocations to be masked.
I've added a new failing test case that's very similar to the one in #10367 but which fails with all functional and testing framework changes I've made so far in this pull request.
At this point I don't see too many alternatives to permitting consecutive revocations, but here are a few that come to mind when the cluster is imbalanced but a revocation took place during the last round:
- Have the leader send out an assignment with no revocations but also a delay of 1ms to trigger an immediate follow-up rebalance for revocations
- Have every worker automatically rejoin the cluster whenever they receive an assignment that contains revoked connectors/tasks (like now) _or_ newly-assigned connectors/tasks, until a rebalance takes place that doesn't change any worker's assigned connectors/tasks
- Have the leader immediately trigger a new rebalance after completing this one by rejoining the group
These (and the strategy of permitting consecutive revocations) all fall under the umbrella of [https://cwiki.apache.org/confluence/display/KAFKA/KIP-415%3A+Incremental+Cooperative+Rebalancing+in+Kafka+Connect#KIP415:IncrementalCooperativeRebalancinginKafkaConnect-ChangestoConnect'sRebalancingProcess](KIP-415), which outlines this strategy:
> - When a Worker is elected as Leader, it computes a new assignment, describing both assigned and revoked connectors and tasks (previously the Leader computed an assignment from scratch without defining revoked resources).
> - When a Worker receives its assignment, if this assignment includes any revoked connectors or tasks, it stops (releases) these resources and then immediately rejoins the group with an assignment that excludes revoked resources (previously, upon receipt of assignment, the Worker started the connectors and tasks and operated in the new generation of the group protocol until the next rebalance some time in the future).
> - Normally in the next assignment round, the Leader will assign resources according to its policy and there will be no revoked resources in any of the Workers. **If that's not the case, the previous steps will be repeated until the group converges into an assignment without revocations.**
(Emphasis mine)
Overall I think permitting consecutive revocations is the safest and most intuitive option here, and with the new testing logic in this PR (especially the new `assertNoFurtherAssignments` method), we get pretty extensive coverage to help ensure we don't get trapped in an infinite revocation loop.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] C0urante commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
C0urante commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r846908015
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
+ log.trace("Lost assignments: {}", lostAssignments);
- // Per worker task assignments without removing deleted connectors yet
- Map<String, Collection<ConnectorTaskId>> taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- log.debug("Complete (ignoring deletions) task assignments: {}", taskAssignments);
+ // The connectors and tasks that have been created since the last rebalance
+ final ConnectorsAndTasks created = ConnectorsAndTasks.diff(configured, previousAssignment, activeAssignments);
+ log.trace("New assignments: {}", created);
- // A collection of the current assignment excluding the connectors-and-tasks to be deleted
- List<WorkerLoad> currentWorkerAssignment = workerAssignment(memberConfigs, deleted);
+ final Map<String, ConnectorsAndTasks.Builder> toRevoke = new HashMap<>();
- Map<String, ConnectorsAndTasks> toRevoke = computeDeleted(deleted, connectorAssignments, taskAssignments);
- log.debug("Connector and task to delete assignments: {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> deletedAndRevoked = intersection(deleted, memberAssignments);
+ log.trace("Deleted connectors and tasks to revoke from each worker: {}", deletedAndRevoked);
+ addAll(toRevoke, deletedAndRevoked);
// Revoking redundant connectors/tasks if the workers have duplicate assignments
- toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
- log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> duplicatedAndRevoked = intersection(duplicated, memberAssignments);
+ log.trace("Duplicated connectors and tasks to revoke from each worker: {}", duplicatedAndRevoked);
+ addAll(toRevoke, duplicatedAndRevoked);
- // Recompute the complete assignment excluding the deleted connectors-and-tasks
- completeWorkerAssignment = workerAssignment(memberConfigs, deleted);
- connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
+ // Compute the assignment that will be applied across the cluster after this round of rebalance
+ // Later on, new submissions and lost-and-reassigned connectors and tasks will be added to these assignments,
+ // and load-balancing revocations will be removed from them.
+ final List<WorkerLoad> nextWorkerAssignment = workerLoads(memberAssignments, ConnectorsAndTasks.combine(deleted, duplicated));
- handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
+ final ConnectorsAndTasks.Builder lostAssignmentsToReassign = ConnectorsAndTasks.builder();
+ handleLostAssignments(lostAssignments, lostAssignmentsToReassign, nextWorkerAssignment);
// Do not revoke resources for re-assignment while a delayed rebalance is active
- // Also we do not revoke in two consecutive rebalances by the same leader
- canRevoke = delay == 0 && canRevoke;
+ // Also we do not revoke in two consecutive rebalances by the same leader, which
+ // should be fine since workers immediately rejoin the group after a rebalance
+ // if connectors and/or tasks were revoked from them
+ canRevoke = canRevoke && delay == 0;
// Compute the connectors-and-tasks to be revoked for load balancing without taking into
// account the deleted ones.
- log.debug("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
+ log.trace("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
if (canRevoke) {
- Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
-
- toExplicitlyRevoke.forEach(
- (worker, assignment) -> {
- ConnectorsAndTasks existing = toRevoke.computeIfAbsent(
- worker,
- v -> new ConnectorsAndTasks.Builder().build());
- existing.connectors().addAll(assignment.connectors());
- existing.tasks().addAll(assignment.tasks());
- }
- );
- canRevoke = toExplicitlyRevoke.size() == 0;
+ Map<String, ConnectorsAndTasks> loadBalancingRevocations =
+ performLoadBalancingRevocations(configured, nextWorkerAssignment);
+
+ log.trace("Load-balancing revocations for each worker: {}", loadBalancingRevocations);
+ addAll(toRevoke, loadBalancingRevocations);
+ canRevoke = ConnectorsAndTasks.combine(loadBalancingRevocations.values()).isEmpty();
} else {
canRevoke = delay == 0;
}
- assignConnectors(completeWorkerAssignment, newSubmissions.connectors());
- assignTasks(completeWorkerAssignment, newSubmissions.tasks());
- log.debug("Current complete assignments: {}", currentWorkerAssignment);
- log.debug("New complete assignments: {}", completeWorkerAssignment);
+ final ConnectorsAndTasks toAssign = ConnectorsAndTasks.combine(created, lostAssignmentsToReassign.build());
+ assignConnectors(nextWorkerAssignment, toAssign.connectors());
+ assignTasks(nextWorkerAssignment, toAssign.tasks());
- Map<String, Collection<String>> currentConnectorAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- Map<String, Collection<ConnectorTaskId>> currentTaskAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- Map<String, Collection<String>> incrementalConnectorAssignments =
- diff(connectorAssignments, currentConnectorAssignments);
- Map<String, Collection<ConnectorTaskId>> incrementalTaskAssignments =
- diff(taskAssignments, currentTaskAssignments);
+ // The complete set of connectors and tasks that will be running on each worker after this rebalance
+ final Map<String, ConnectorsAndTasks> nextAssignments = assignments(nextWorkerAssignment);
- log.debug("Incremental connector assignments: {}", incrementalConnectorAssignments);
- log.debug("Incremental task assignments: {}", incrementalTaskAssignments);
+ log.debug("Current complete assignments: {}", memberAssignments);
+ log.debug("New complete assignments: {}", nextAssignments);
Review Comment:
That's fair! I was copying the wording in the [existing log message](https://github.com/apache/kafka/blob/4ad439c56db551697ea366dc4986eee5fc288706/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java#L290). Probably best to keep the updated log message consistent with the new variable name like you suggest--another way to go about that is to rename the variable from `nextAssignments` to `newAssignments`. Any preference between the two?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] C0urante commented on pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
C0urante commented on PR #12019:
URL: https://github.com/apache/kafka/pull/12019#issuecomment-1194881570
Converting this to a draft since I haven't had time to prioritize it (sorry @YeonCheolGit!) and the changes here are not safe to merge as-are.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r847446537
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
+ log.trace("Lost assignments: {}", lostAssignments);
- // Per worker task assignments without removing deleted connectors yet
- Map<String, Collection<ConnectorTaskId>> taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- log.debug("Complete (ignoring deletions) task assignments: {}", taskAssignments);
+ // The connectors and tasks that have been created since the last rebalance
+ final ConnectorsAndTasks created = ConnectorsAndTasks.diff(configured, previousAssignment, activeAssignments);
+ log.trace("New assignments: {}", created);
- // A collection of the current assignment excluding the connectors-and-tasks to be deleted
- List<WorkerLoad> currentWorkerAssignment = workerAssignment(memberConfigs, deleted);
+ final Map<String, ConnectorsAndTasks.Builder> toRevoke = new HashMap<>();
- Map<String, ConnectorsAndTasks> toRevoke = computeDeleted(deleted, connectorAssignments, taskAssignments);
- log.debug("Connector and task to delete assignments: {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> deletedAndRevoked = intersection(deleted, memberAssignments);
+ log.trace("Deleted connectors and tasks to revoke from each worker: {}", deletedAndRevoked);
+ addAll(toRevoke, deletedAndRevoked);
// Revoking redundant connectors/tasks if the workers have duplicate assignments
- toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
- log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> duplicatedAndRevoked = intersection(duplicated, memberAssignments);
+ log.trace("Duplicated connectors and tasks to revoke from each worker: {}", duplicatedAndRevoked);
+ addAll(toRevoke, duplicatedAndRevoked);
- // Recompute the complete assignment excluding the deleted connectors-and-tasks
- completeWorkerAssignment = workerAssignment(memberConfigs, deleted);
- connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
+ // Compute the assignment that will be applied across the cluster after this round of rebalance
+ // Later on, new submissions and lost-and-reassigned connectors and tasks will be added to these assignments,
+ // and load-balancing revocations will be removed from them.
+ final List<WorkerLoad> nextWorkerAssignment = workerLoads(memberAssignments, ConnectorsAndTasks.combine(deleted, duplicated));
- handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
+ final ConnectorsAndTasks.Builder lostAssignmentsToReassign = ConnectorsAndTasks.builder();
+ handleLostAssignments(lostAssignments, lostAssignmentsToReassign, nextWorkerAssignment);
// Do not revoke resources for re-assignment while a delayed rebalance is active
- // Also we do not revoke in two consecutive rebalances by the same leader
- canRevoke = delay == 0 && canRevoke;
+ // Also we do not revoke in two consecutive rebalances by the same leader, which
+ // should be fine since workers immediately rejoin the group after a rebalance
+ // if connectors and/or tasks were revoked from them
+ canRevoke = canRevoke && delay == 0;
// Compute the connectors-and-tasks to be revoked for load balancing without taking into
// account the deleted ones.
- log.debug("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
+ log.trace("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
if (canRevoke) {
- Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
-
- toExplicitlyRevoke.forEach(
- (worker, assignment) -> {
- ConnectorsAndTasks existing = toRevoke.computeIfAbsent(
- worker,
- v -> new ConnectorsAndTasks.Builder().build());
- existing.connectors().addAll(assignment.connectors());
- existing.tasks().addAll(assignment.tasks());
- }
- );
- canRevoke = toExplicitlyRevoke.size() == 0;
+ Map<String, ConnectorsAndTasks> loadBalancingRevocations =
+ performLoadBalancingRevocations(configured, nextWorkerAssignment);
+
+ log.trace("Load-balancing revocations for each worker: {}", loadBalancingRevocations);
+ addAll(toRevoke, loadBalancingRevocations);
+ canRevoke = ConnectorsAndTasks.combine(loadBalancingRevocations.values()).isEmpty();
} else {
canRevoke = delay == 0;
}
- assignConnectors(completeWorkerAssignment, newSubmissions.connectors());
- assignTasks(completeWorkerAssignment, newSubmissions.tasks());
- log.debug("Current complete assignments: {}", currentWorkerAssignment);
- log.debug("New complete assignments: {}", completeWorkerAssignment);
+ final ConnectorsAndTasks toAssign = ConnectorsAndTasks.combine(created, lostAssignmentsToReassign.build());
+ assignConnectors(nextWorkerAssignment, toAssign.connectors());
+ assignTasks(nextWorkerAssignment, toAssign.tasks());
- Map<String, Collection<String>> currentConnectorAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- Map<String, Collection<ConnectorTaskId>> currentTaskAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- Map<String, Collection<String>> incrementalConnectorAssignments =
- diff(connectorAssignments, currentConnectorAssignments);
- Map<String, Collection<ConnectorTaskId>> incrementalTaskAssignments =
- diff(taskAssignments, currentTaskAssignments);
+ // The complete set of connectors and tasks that will be running on each worker after this rebalance
+ final Map<String, ConnectorsAndTasks> nextAssignments = assignments(nextWorkerAssignment);
- log.debug("Incremental connector assignments: {}", incrementalConnectorAssignments);
- log.debug("Incremental task assignments: {}", incrementalTaskAssignments);
+ log.debug("Current complete assignments: {}", memberAssignments);
+ log.debug("New complete assignments: {}", nextAssignments);
Review Comment:
@C0urante
Thank you for the reply:)
I may not know how your team works but maybe keeping `next` is looking better for me. Because if we change `new` to `next`, we need to change all variable names and consider huge side effects.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r847446537
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
+ log.trace("Lost assignments: {}", lostAssignments);
- // Per worker task assignments without removing deleted connectors yet
- Map<String, Collection<ConnectorTaskId>> taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- log.debug("Complete (ignoring deletions) task assignments: {}", taskAssignments);
+ // The connectors and tasks that have been created since the last rebalance
+ final ConnectorsAndTasks created = ConnectorsAndTasks.diff(configured, previousAssignment, activeAssignments);
+ log.trace("New assignments: {}", created);
- // A collection of the current assignment excluding the connectors-and-tasks to be deleted
- List<WorkerLoad> currentWorkerAssignment = workerAssignment(memberConfigs, deleted);
+ final Map<String, ConnectorsAndTasks.Builder> toRevoke = new HashMap<>();
- Map<String, ConnectorsAndTasks> toRevoke = computeDeleted(deleted, connectorAssignments, taskAssignments);
- log.debug("Connector and task to delete assignments: {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> deletedAndRevoked = intersection(deleted, memberAssignments);
+ log.trace("Deleted connectors and tasks to revoke from each worker: {}", deletedAndRevoked);
+ addAll(toRevoke, deletedAndRevoked);
// Revoking redundant connectors/tasks if the workers have duplicate assignments
- toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
- log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> duplicatedAndRevoked = intersection(duplicated, memberAssignments);
+ log.trace("Duplicated connectors and tasks to revoke from each worker: {}", duplicatedAndRevoked);
+ addAll(toRevoke, duplicatedAndRevoked);
- // Recompute the complete assignment excluding the deleted connectors-and-tasks
- completeWorkerAssignment = workerAssignment(memberConfigs, deleted);
- connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
+ // Compute the assignment that will be applied across the cluster after this round of rebalance
+ // Later on, new submissions and lost-and-reassigned connectors and tasks will be added to these assignments,
+ // and load-balancing revocations will be removed from them.
+ final List<WorkerLoad> nextWorkerAssignment = workerLoads(memberAssignments, ConnectorsAndTasks.combine(deleted, duplicated));
- handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
+ final ConnectorsAndTasks.Builder lostAssignmentsToReassign = ConnectorsAndTasks.builder();
+ handleLostAssignments(lostAssignments, lostAssignmentsToReassign, nextWorkerAssignment);
// Do not revoke resources for re-assignment while a delayed rebalance is active
- // Also we do not revoke in two consecutive rebalances by the same leader
- canRevoke = delay == 0 && canRevoke;
+ // Also we do not revoke in two consecutive rebalances by the same leader, which
+ // should be fine since workers immediately rejoin the group after a rebalance
+ // if connectors and/or tasks were revoked from them
+ canRevoke = canRevoke && delay == 0;
// Compute the connectors-and-tasks to be revoked for load balancing without taking into
// account the deleted ones.
- log.debug("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
+ log.trace("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
if (canRevoke) {
- Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
-
- toExplicitlyRevoke.forEach(
- (worker, assignment) -> {
- ConnectorsAndTasks existing = toRevoke.computeIfAbsent(
- worker,
- v -> new ConnectorsAndTasks.Builder().build());
- existing.connectors().addAll(assignment.connectors());
- existing.tasks().addAll(assignment.tasks());
- }
- );
- canRevoke = toExplicitlyRevoke.size() == 0;
+ Map<String, ConnectorsAndTasks> loadBalancingRevocations =
+ performLoadBalancingRevocations(configured, nextWorkerAssignment);
+
+ log.trace("Load-balancing revocations for each worker: {}", loadBalancingRevocations);
+ addAll(toRevoke, loadBalancingRevocations);
+ canRevoke = ConnectorsAndTasks.combine(loadBalancingRevocations.values()).isEmpty();
} else {
canRevoke = delay == 0;
}
- assignConnectors(completeWorkerAssignment, newSubmissions.connectors());
- assignTasks(completeWorkerAssignment, newSubmissions.tasks());
- log.debug("Current complete assignments: {}", currentWorkerAssignment);
- log.debug("New complete assignments: {}", completeWorkerAssignment);
+ final ConnectorsAndTasks toAssign = ConnectorsAndTasks.combine(created, lostAssignmentsToReassign.build());
+ assignConnectors(nextWorkerAssignment, toAssign.connectors());
+ assignTasks(nextWorkerAssignment, toAssign.tasks());
- Map<String, Collection<String>> currentConnectorAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- Map<String, Collection<ConnectorTaskId>> currentTaskAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- Map<String, Collection<String>> incrementalConnectorAssignments =
- diff(connectorAssignments, currentConnectorAssignments);
- Map<String, Collection<ConnectorTaskId>> incrementalTaskAssignments =
- diff(taskAssignments, currentTaskAssignments);
+ // The complete set of connectors and tasks that will be running on each worker after this rebalance
+ final Map<String, ConnectorsAndTasks> nextAssignments = assignments(nextWorkerAssignment);
- log.debug("Incremental connector assignments: {}", incrementalConnectorAssignments);
- log.debug("Incremental task assignments: {}", incrementalTaskAssignments);
+ log.debug("Current complete assignments: {}", memberAssignments);
+ log.debug("New complete assignments: {}", nextAssignments);
Review Comment:
@C0urante
Thank you for the reply:)
I may not know how your team works but maybe keeping `nextAssignments ` is looking better for me. Because if we change `next` to `new`, we need to change all variable names and consider huge side effects.
If someone wants to change `next` to `new` it should be working with saperate PR.
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
+ log.trace("Lost assignments: {}", lostAssignments);
- // Per worker task assignments without removing deleted connectors yet
- Map<String, Collection<ConnectorTaskId>> taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- log.debug("Complete (ignoring deletions) task assignments: {}", taskAssignments);
+ // The connectors and tasks that have been created since the last rebalance
+ final ConnectorsAndTasks created = ConnectorsAndTasks.diff(configured, previousAssignment, activeAssignments);
+ log.trace("New assignments: {}", created);
- // A collection of the current assignment excluding the connectors-and-tasks to be deleted
- List<WorkerLoad> currentWorkerAssignment = workerAssignment(memberConfigs, deleted);
+ final Map<String, ConnectorsAndTasks.Builder> toRevoke = new HashMap<>();
- Map<String, ConnectorsAndTasks> toRevoke = computeDeleted(deleted, connectorAssignments, taskAssignments);
- log.debug("Connector and task to delete assignments: {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> deletedAndRevoked = intersection(deleted, memberAssignments);
+ log.trace("Deleted connectors and tasks to revoke from each worker: {}", deletedAndRevoked);
+ addAll(toRevoke, deletedAndRevoked);
// Revoking redundant connectors/tasks if the workers have duplicate assignments
- toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
- log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> duplicatedAndRevoked = intersection(duplicated, memberAssignments);
+ log.trace("Duplicated connectors and tasks to revoke from each worker: {}", duplicatedAndRevoked);
+ addAll(toRevoke, duplicatedAndRevoked);
- // Recompute the complete assignment excluding the deleted connectors-and-tasks
- completeWorkerAssignment = workerAssignment(memberConfigs, deleted);
- connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
+ // Compute the assignment that will be applied across the cluster after this round of rebalance
+ // Later on, new submissions and lost-and-reassigned connectors and tasks will be added to these assignments,
+ // and load-balancing revocations will be removed from them.
+ final List<WorkerLoad> nextWorkerAssignment = workerLoads(memberAssignments, ConnectorsAndTasks.combine(deleted, duplicated));
- handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
+ final ConnectorsAndTasks.Builder lostAssignmentsToReassign = ConnectorsAndTasks.builder();
+ handleLostAssignments(lostAssignments, lostAssignmentsToReassign, nextWorkerAssignment);
// Do not revoke resources for re-assignment while a delayed rebalance is active
- // Also we do not revoke in two consecutive rebalances by the same leader
- canRevoke = delay == 0 && canRevoke;
+ // Also we do not revoke in two consecutive rebalances by the same leader, which
+ // should be fine since workers immediately rejoin the group after a rebalance
+ // if connectors and/or tasks were revoked from them
+ canRevoke = canRevoke && delay == 0;
// Compute the connectors-and-tasks to be revoked for load balancing without taking into
// account the deleted ones.
- log.debug("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
+ log.trace("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
if (canRevoke) {
- Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
-
- toExplicitlyRevoke.forEach(
- (worker, assignment) -> {
- ConnectorsAndTasks existing = toRevoke.computeIfAbsent(
- worker,
- v -> new ConnectorsAndTasks.Builder().build());
- existing.connectors().addAll(assignment.connectors());
- existing.tasks().addAll(assignment.tasks());
- }
- );
- canRevoke = toExplicitlyRevoke.size() == 0;
+ Map<String, ConnectorsAndTasks> loadBalancingRevocations =
+ performLoadBalancingRevocations(configured, nextWorkerAssignment);
+
+ log.trace("Load-balancing revocations for each worker: {}", loadBalancingRevocations);
+ addAll(toRevoke, loadBalancingRevocations);
+ canRevoke = ConnectorsAndTasks.combine(loadBalancingRevocations.values()).isEmpty();
} else {
canRevoke = delay == 0;
}
- assignConnectors(completeWorkerAssignment, newSubmissions.connectors());
- assignTasks(completeWorkerAssignment, newSubmissions.tasks());
- log.debug("Current complete assignments: {}", currentWorkerAssignment);
- log.debug("New complete assignments: {}", completeWorkerAssignment);
+ final ConnectorsAndTasks toAssign = ConnectorsAndTasks.combine(created, lostAssignmentsToReassign.build());
+ assignConnectors(nextWorkerAssignment, toAssign.connectors());
+ assignTasks(nextWorkerAssignment, toAssign.tasks());
- Map<String, Collection<String>> currentConnectorAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- Map<String, Collection<ConnectorTaskId>> currentTaskAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- Map<String, Collection<String>> incrementalConnectorAssignments =
- diff(connectorAssignments, currentConnectorAssignments);
- Map<String, Collection<ConnectorTaskId>> incrementalTaskAssignments =
- diff(taskAssignments, currentTaskAssignments);
+ // The complete set of connectors and tasks that will be running on each worker after this rebalance
+ final Map<String, ConnectorsAndTasks> nextAssignments = assignments(nextWorkerAssignment);
- log.debug("Incremental connector assignments: {}", incrementalConnectorAssignments);
- log.debug("Incremental task assignments: {}", incrementalTaskAssignments);
+ log.debug("Current complete assignments: {}", memberAssignments);
+ log.debug("New complete assignments: {}", nextAssignments);
Review Comment:
@C0urante
Thank you for the reply:)
I may not know how your team works but maybe keeping `nextAssignments` is looking better for me. Because if we change `next` to `new`, we need to change all variable names and consider huge side effects.
If someone wants to change `next` to `new` it should be working with saperate PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r862388033
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -110,14 +114,18 @@ public Map<String, ByteBuffer> performAssignment(String leaderId, String protoco
: CONNECT_PROTOCOL_V1;
Long leaderOffset = ensureLeaderConfig(maxOffset, coordinator);
+ Map<String, ExtendedAssignment> assignments;
if (leaderOffset == null) {
- Map<String, ExtendedAssignment> assignments = fillAssignments(
+ assignments = fillAssignments(
memberConfigs.keySet(), Assignment.CONFIG_MISMATCH,
- leaderId, memberConfigs.get(leaderId).url(), maxOffset, Collections.emptyMap(),
- Collections.emptyMap(), Collections.emptyMap(), 0, protocolVersion);
- return serializeAssignments(assignments);
+ leaderId, memberConfigs.get(leaderId).url(), maxOffset,
+ ClusterAssignment.EMPTY, 0, protocolVersion);
+ } else {
+ assignments = performTaskAssignment(leaderId, leaderOffset, memberConfigs, coordinator, protocolVersion);
}
- return performTaskAssignment(leaderId, leaderOffset, memberConfigs, coordinator, protocolVersion);
+ Map<String, ByteBuffer> result = serializeAssignments(assignments);
+ log.debug("Finished assignment");
Review Comment:
This works with `assignment's'` so maybe this?
```suggestion
log.debug("Finished assignments");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r847446537
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
+ log.trace("Lost assignments: {}", lostAssignments);
- // Per worker task assignments without removing deleted connectors yet
- Map<String, Collection<ConnectorTaskId>> taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- log.debug("Complete (ignoring deletions) task assignments: {}", taskAssignments);
+ // The connectors and tasks that have been created since the last rebalance
+ final ConnectorsAndTasks created = ConnectorsAndTasks.diff(configured, previousAssignment, activeAssignments);
+ log.trace("New assignments: {}", created);
- // A collection of the current assignment excluding the connectors-and-tasks to be deleted
- List<WorkerLoad> currentWorkerAssignment = workerAssignment(memberConfigs, deleted);
+ final Map<String, ConnectorsAndTasks.Builder> toRevoke = new HashMap<>();
- Map<String, ConnectorsAndTasks> toRevoke = computeDeleted(deleted, connectorAssignments, taskAssignments);
- log.debug("Connector and task to delete assignments: {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> deletedAndRevoked = intersection(deleted, memberAssignments);
+ log.trace("Deleted connectors and tasks to revoke from each worker: {}", deletedAndRevoked);
+ addAll(toRevoke, deletedAndRevoked);
// Revoking redundant connectors/tasks if the workers have duplicate assignments
- toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
- log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> duplicatedAndRevoked = intersection(duplicated, memberAssignments);
+ log.trace("Duplicated connectors and tasks to revoke from each worker: {}", duplicatedAndRevoked);
+ addAll(toRevoke, duplicatedAndRevoked);
- // Recompute the complete assignment excluding the deleted connectors-and-tasks
- completeWorkerAssignment = workerAssignment(memberConfigs, deleted);
- connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
+ // Compute the assignment that will be applied across the cluster after this round of rebalance
+ // Later on, new submissions and lost-and-reassigned connectors and tasks will be added to these assignments,
+ // and load-balancing revocations will be removed from them.
+ final List<WorkerLoad> nextWorkerAssignment = workerLoads(memberAssignments, ConnectorsAndTasks.combine(deleted, duplicated));
- handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
+ final ConnectorsAndTasks.Builder lostAssignmentsToReassign = ConnectorsAndTasks.builder();
+ handleLostAssignments(lostAssignments, lostAssignmentsToReassign, nextWorkerAssignment);
// Do not revoke resources for re-assignment while a delayed rebalance is active
- // Also we do not revoke in two consecutive rebalances by the same leader
- canRevoke = delay == 0 && canRevoke;
+ // Also we do not revoke in two consecutive rebalances by the same leader, which
+ // should be fine since workers immediately rejoin the group after a rebalance
+ // if connectors and/or tasks were revoked from them
+ canRevoke = canRevoke && delay == 0;
// Compute the connectors-and-tasks to be revoked for load balancing without taking into
// account the deleted ones.
- log.debug("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
+ log.trace("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
if (canRevoke) {
- Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
-
- toExplicitlyRevoke.forEach(
- (worker, assignment) -> {
- ConnectorsAndTasks existing = toRevoke.computeIfAbsent(
- worker,
- v -> new ConnectorsAndTasks.Builder().build());
- existing.connectors().addAll(assignment.connectors());
- existing.tasks().addAll(assignment.tasks());
- }
- );
- canRevoke = toExplicitlyRevoke.size() == 0;
+ Map<String, ConnectorsAndTasks> loadBalancingRevocations =
+ performLoadBalancingRevocations(configured, nextWorkerAssignment);
+
+ log.trace("Load-balancing revocations for each worker: {}", loadBalancingRevocations);
+ addAll(toRevoke, loadBalancingRevocations);
+ canRevoke = ConnectorsAndTasks.combine(loadBalancingRevocations.values()).isEmpty();
} else {
canRevoke = delay == 0;
}
- assignConnectors(completeWorkerAssignment, newSubmissions.connectors());
- assignTasks(completeWorkerAssignment, newSubmissions.tasks());
- log.debug("Current complete assignments: {}", currentWorkerAssignment);
- log.debug("New complete assignments: {}", completeWorkerAssignment);
+ final ConnectorsAndTasks toAssign = ConnectorsAndTasks.combine(created, lostAssignmentsToReassign.build());
+ assignConnectors(nextWorkerAssignment, toAssign.connectors());
+ assignTasks(nextWorkerAssignment, toAssign.tasks());
- Map<String, Collection<String>> currentConnectorAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- Map<String, Collection<ConnectorTaskId>> currentTaskAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- Map<String, Collection<String>> incrementalConnectorAssignments =
- diff(connectorAssignments, currentConnectorAssignments);
- Map<String, Collection<ConnectorTaskId>> incrementalTaskAssignments =
- diff(taskAssignments, currentTaskAssignments);
+ // The complete set of connectors and tasks that will be running on each worker after this rebalance
+ final Map<String, ConnectorsAndTasks> nextAssignments = assignments(nextWorkerAssignment);
- log.debug("Incremental connector assignments: {}", incrementalConnectorAssignments);
- log.debug("Incremental task assignments: {}", incrementalTaskAssignments);
+ log.debug("Current complete assignments: {}", memberAssignments);
+ log.debug("New complete assignments: {}", nextAssignments);
Review Comment:
@C0urante
Thank you for the reply:)
I may not know how your team works but maybe keeping `nextAssignments` is looking better for me. Because if we change `nextAssignments ` to `newAssignments `, we need to change all variable names and consider huge side effects.
If someone wants to change `nextAssignments` to `newAssignments` it should be working with saperate PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r862396035
##########
connect/runtime/src/main/java/org/apache/kafka/connect/util/ConnectUtils.java:
##########
@@ -160,4 +166,40 @@ public static boolean isSourceConnector(Connector connector) {
return SourceConnector.class.isAssignableFrom(connector.getClass());
}
+ public static <K, I, O> Map<K, O> transformValues(Map<K, I> map, Function<I, O> transformation) {
+ return map.entrySet().stream().collect(Collectors.toMap(
+ Map.Entry::getKey,
+ transformation.compose(Map.Entry::getValue)
+ ));
+ }
+
+ public static <I> List<I> combineCollections(Collection<? extends Collection<I>> collections) {
+ return combineCollections(collections, Function.identity());
+ }
+
+ public static <I, T> List<T> combineCollections(Collection<? extends I> collection, Function<I, Collection<T>> extractCollection) {
+ return combineCollections(collection, extractCollection, Collectors.toList());
+ }
+
+ public static <I, T, C> C combineCollections(
Review Comment:
Could you explain why `combineCollections` return `combineCollections` then return `combineCollections`?
For me, It looks final returning result is always `<I, T, C> C combineCollections`. Why not using only `<I, T, C> C combineCollections`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r862491251
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -723,44 +610,175 @@ protected void assignConnectors(List<WorkerLoad> workerAssignment, Collection<St
* @param workerAssignment the current worker assignment; assigned tasks are added to this list
* @param tasks the tasks to be assigned
*/
- protected void assignTasks(List<WorkerLoad> workerAssignment, Collection<ConnectorTaskId> tasks) {
- workerAssignment.sort(WorkerLoad.taskComparator());
- WorkerLoad first = workerAssignment.get(0);
+ // Visible for testing
+ void assignTasks(List<WorkerLoad> workerAssignment, Collection<ConnectorTaskId> tasks) {
+ assign(workerAssignment, tasks, WorkerLoad::tasks, WorkerLoad::assign);
+ }
- Iterator<ConnectorTaskId> load = tasks.iterator();
+ private <E> void assign(
+ List<WorkerLoad> workers,
+ Collection<E> toAssign,
+ Function<WorkerLoad, Collection<E>> currentAllocation,
+ BiConsumer<WorkerLoad, E> assignToWorker
+ ) {
+ Function<WorkerLoad, Integer> allocationSize = currentAllocation.andThen(Collection::size);
+ workers.sort(Comparator.comparing(allocationSize));
+ WorkerLoad first = workers.get(0);
+
+ Iterator<E> load = toAssign.stream().sorted().iterator();
while (load.hasNext()) {
- int firstLoad = first.tasksSize();
- int upTo = IntStream.range(0, workerAssignment.size())
- .filter(i -> workerAssignment.get(i).tasksSize() > firstLoad)
+ int firstLoad = allocationSize.apply(first);
+ int upTo = IntStream.range(0, workers.size())
Review Comment:
This is minor suggestion and could be ignored.
If calculate workers.size in while loop it has to be calculated all the time until it is true.
What about calculating size one time then use it many times.
```
int workersSize = workers.size();
IntStream.range(0, workersSize)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r862394876
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -151,19 +159,46 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
* @param coordinator the worker coordinator instance that provide the configuration snapshot
* and get assigned the leader state during this assignment
* @param protocolVersion the Connect subprotocol version
- * @return the serialized assignment of tasks to the whole group, including assigned or
- * revoked tasks
+ * @return the assignment of tasks to the whole group, including assigned or revoked tasks
*/
- protected Map<String, ByteBuffer> performTaskAssignment(String leaderId, long maxOffset,
+ private Map<String, ExtendedAssignment> performTaskAssignment(String leaderId, long maxOffset,
Review Comment:
Just wondering that why changing `protected` to `private`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on PR #12019:
URL: https://github.com/apache/kafka/pull/12019#issuecomment-1107446381
@C0urante
Hello! I am just wondering that how this PR is going? Is threre anything that i can help with?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r846804952
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
+ log.trace("Lost assignments: {}", lostAssignments);
- // Per worker task assignments without removing deleted connectors yet
- Map<String, Collection<ConnectorTaskId>> taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- log.debug("Complete (ignoring deletions) task assignments: {}", taskAssignments);
+ // The connectors and tasks that have been created since the last rebalance
+ final ConnectorsAndTasks created = ConnectorsAndTasks.diff(configured, previousAssignment, activeAssignments);
+ log.trace("New assignments: {}", created);
- // A collection of the current assignment excluding the connectors-and-tasks to be deleted
- List<WorkerLoad> currentWorkerAssignment = workerAssignment(memberConfigs, deleted);
+ final Map<String, ConnectorsAndTasks.Builder> toRevoke = new HashMap<>();
- Map<String, ConnectorsAndTasks> toRevoke = computeDeleted(deleted, connectorAssignments, taskAssignments);
- log.debug("Connector and task to delete assignments: {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> deletedAndRevoked = intersection(deleted, memberAssignments);
+ log.trace("Deleted connectors and tasks to revoke from each worker: {}", deletedAndRevoked);
+ addAll(toRevoke, deletedAndRevoked);
// Revoking redundant connectors/tasks if the workers have duplicate assignments
- toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
- log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> duplicatedAndRevoked = intersection(duplicated, memberAssignments);
+ log.trace("Duplicated connectors and tasks to revoke from each worker: {}", duplicatedAndRevoked);
+ addAll(toRevoke, duplicatedAndRevoked);
- // Recompute the complete assignment excluding the deleted connectors-and-tasks
- completeWorkerAssignment = workerAssignment(memberConfigs, deleted);
- connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
+ // Compute the assignment that will be applied across the cluster after this round of rebalance
+ // Later on, new submissions and lost-and-reassigned connectors and tasks will be added to these assignments,
+ // and load-balancing revocations will be removed from them.
+ final List<WorkerLoad> nextWorkerAssignment = workerLoads(memberAssignments, ConnectorsAndTasks.combine(deleted, duplicated));
- handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
+ final ConnectorsAndTasks.Builder lostAssignmentsToReassign = ConnectorsAndTasks.builder();
+ handleLostAssignments(lostAssignments, lostAssignmentsToReassign, nextWorkerAssignment);
// Do not revoke resources for re-assignment while a delayed rebalance is active
- // Also we do not revoke in two consecutive rebalances by the same leader
- canRevoke = delay == 0 && canRevoke;
+ // Also we do not revoke in two consecutive rebalances by the same leader, which
+ // should be fine since workers immediately rejoin the group after a rebalance
+ // if connectors and/or tasks were revoked from them
+ canRevoke = canRevoke && delay == 0;
// Compute the connectors-and-tasks to be revoked for load balancing without taking into
// account the deleted ones.
- log.debug("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
+ log.trace("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
if (canRevoke) {
- Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
-
- toExplicitlyRevoke.forEach(
- (worker, assignment) -> {
- ConnectorsAndTasks existing = toRevoke.computeIfAbsent(
- worker,
- v -> new ConnectorsAndTasks.Builder().build());
- existing.connectors().addAll(assignment.connectors());
- existing.tasks().addAll(assignment.tasks());
- }
- );
- canRevoke = toExplicitlyRevoke.size() == 0;
+ Map<String, ConnectorsAndTasks> loadBalancingRevocations =
+ performLoadBalancingRevocations(configured, nextWorkerAssignment);
+
+ log.trace("Load-balancing revocations for each worker: {}", loadBalancingRevocations);
+ addAll(toRevoke, loadBalancingRevocations);
+ canRevoke = ConnectorsAndTasks.combine(loadBalancingRevocations.values()).isEmpty();
} else {
canRevoke = delay == 0;
}
- assignConnectors(completeWorkerAssignment, newSubmissions.connectors());
- assignTasks(completeWorkerAssignment, newSubmissions.tasks());
- log.debug("Current complete assignments: {}", currentWorkerAssignment);
- log.debug("New complete assignments: {}", completeWorkerAssignment);
+ final ConnectorsAndTasks toAssign = ConnectorsAndTasks.combine(created, lostAssignmentsToReassign.build());
+ assignConnectors(nextWorkerAssignment, toAssign.connectors());
+ assignTasks(nextWorkerAssignment, toAssign.tasks());
- Map<String, Collection<String>> currentConnectorAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- Map<String, Collection<ConnectorTaskId>> currentTaskAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- Map<String, Collection<String>> incrementalConnectorAssignments =
- diff(connectorAssignments, currentConnectorAssignments);
- Map<String, Collection<ConnectorTaskId>> incrementalTaskAssignments =
- diff(taskAssignments, currentTaskAssignments);
+ // The complete set of connectors and tasks that will be running on each worker after this rebalance
+ final Map<String, ConnectorsAndTasks> nextAssignments = assignments(nextWorkerAssignment);
- log.debug("Incremental connector assignments: {}", incrementalConnectorAssignments);
- log.debug("Incremental task assignments: {}", incrementalTaskAssignments);
+ log.debug("Current complete assignments: {}", memberAssignments);
+ log.debug("New complete assignments: {}", nextAssignments);
Review Comment:
Just minor suggestion and could be ignored. What about changing `New` to `Next`? Because using variable `nextAssignments` for parameter, so logging `Next` looks more clear for me.
```suggestion
log.debug("Next complete assignments: {}", nextAssignments);
```
@C0urante
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r862492477
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -526,165 +421,174 @@ private List<WorkerLoad> pickCandidateWorkerForReassignment(List<WorkerLoad> com
}
/**
- * Task revocation is based on an rough estimation of the lower average number of tasks before
- * and after new workers join the group. If no new workers join, no revocation takes place.
- * Based on this estimation, tasks are revoked until the new floor average is reached for
- * each existing worker. The revoked tasks, once assigned to the new workers will maintain
- * a balanced load among the group.
- *
- * @param activeAssignments
- * @param completeWorkerAssignment
- * @return
+ * Revoke connectors and tasks from each worker in the cluster until no worker is running more than it would be if:
+ * <ul>
+ * <li>The allocation of connectors and tasks across the cluster were as balanced as possible (i.e., the difference in allocation size between any two workers is at most one)</li>
+ * <li>Any workers that left the group within the scheduled rebalance delay permanently left the group</li>
+ * <li>All currently-configured connectors and tasks were allocated (including instances that may be revoked in this round because they are duplicated across workers)</li>
+ * </ul>
Review Comment:
Maybe this is silly question and i don't know this things.
Is there any reason to put HTML tag for comments?
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -526,165 +421,174 @@ private List<WorkerLoad> pickCandidateWorkerForReassignment(List<WorkerLoad> com
}
/**
- * Task revocation is based on an rough estimation of the lower average number of tasks before
- * and after new workers join the group. If no new workers join, no revocation takes place.
- * Based on this estimation, tasks are revoked until the new floor average is reached for
- * each existing worker. The revoked tasks, once assigned to the new workers will maintain
- * a balanced load among the group.
- *
- * @param activeAssignments
- * @param completeWorkerAssignment
- * @return
+ * Revoke connectors and tasks from each worker in the cluster until no worker is running more than it would be if:
+ * <ul>
+ * <li>The allocation of connectors and tasks across the cluster were as balanced as possible (i.e., the difference in allocation size between any two workers is at most one)</li>
+ * <li>Any workers that left the group within the scheduled rebalance delay permanently left the group</li>
+ * <li>All currently-configured connectors and tasks were allocated (including instances that may be revoked in this round because they are duplicated across workers)</li>
+ * </ul>
Review Comment:
Maybe this is silly question and i don't know this things much.
Is there any reason to put HTML tag for comments?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r862388033
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -110,14 +114,18 @@ public Map<String, ByteBuffer> performAssignment(String leaderId, String protoco
: CONNECT_PROTOCOL_V1;
Long leaderOffset = ensureLeaderConfig(maxOffset, coordinator);
+ Map<String, ExtendedAssignment> assignments;
if (leaderOffset == null) {
- Map<String, ExtendedAssignment> assignments = fillAssignments(
+ assignments = fillAssignments(
memberConfigs.keySet(), Assignment.CONFIG_MISMATCH,
- leaderId, memberConfigs.get(leaderId).url(), maxOffset, Collections.emptyMap(),
- Collections.emptyMap(), Collections.emptyMap(), 0, protocolVersion);
- return serializeAssignments(assignments);
+ leaderId, memberConfigs.get(leaderId).url(), maxOffset,
+ ClusterAssignment.EMPTY, 0, protocolVersion);
+ } else {
+ assignments = performTaskAssignment(leaderId, leaderOffset, memberConfigs, coordinator, protocolVersion);
}
- return performTaskAssignment(leaderId, leaderOffset, memberConfigs, coordinator, protocolVersion);
+ Map<String, ByteBuffer> result = serializeAssignments(assignments);
+ log.debug("Finished assignment");
Review Comment:
@C0urante
This works with `Map<String, ExtendedAssignment> assignment's'`.
So maybe this?
```suggestion
log.debug("Finished assignments");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r862394876
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -151,19 +159,46 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
* @param coordinator the worker coordinator instance that provide the configuration snapshot
* and get assigned the leader state during this assignment
* @param protocolVersion the Connect subprotocol version
- * @return the serialized assignment of tasks to the whole group, including assigned or
- * revoked tasks
+ * @return the assignment of tasks to the whole group, including assigned or revoked tasks
*/
- protected Map<String, ByteBuffer> performTaskAssignment(String leaderId, long maxOffset,
+ private Map<String, ExtendedAssignment> performTaskAssignment(String leaderId, long maxOffset,
Review Comment:
Just wondering that why changing `protected` to `private`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] C0urante commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
C0urante commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r849010637
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
+ log.trace("Lost assignments: {}", lostAssignments);
- // Per worker task assignments without removing deleted connectors yet
- Map<String, Collection<ConnectorTaskId>> taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- log.debug("Complete (ignoring deletions) task assignments: {}", taskAssignments);
+ // The connectors and tasks that have been created since the last rebalance
+ final ConnectorsAndTasks created = ConnectorsAndTasks.diff(configured, previousAssignment, activeAssignments);
+ log.trace("New assignments: {}", created);
- // A collection of the current assignment excluding the connectors-and-tasks to be deleted
- List<WorkerLoad> currentWorkerAssignment = workerAssignment(memberConfigs, deleted);
+ final Map<String, ConnectorsAndTasks.Builder> toRevoke = new HashMap<>();
- Map<String, ConnectorsAndTasks> toRevoke = computeDeleted(deleted, connectorAssignments, taskAssignments);
- log.debug("Connector and task to delete assignments: {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> deletedAndRevoked = intersection(deleted, memberAssignments);
+ log.trace("Deleted connectors and tasks to revoke from each worker: {}", deletedAndRevoked);
+ addAll(toRevoke, deletedAndRevoked);
// Revoking redundant connectors/tasks if the workers have duplicate assignments
- toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
- log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> duplicatedAndRevoked = intersection(duplicated, memberAssignments);
+ log.trace("Duplicated connectors and tasks to revoke from each worker: {}", duplicatedAndRevoked);
+ addAll(toRevoke, duplicatedAndRevoked);
- // Recompute the complete assignment excluding the deleted connectors-and-tasks
- completeWorkerAssignment = workerAssignment(memberConfigs, deleted);
- connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
+ // Compute the assignment that will be applied across the cluster after this round of rebalance
+ // Later on, new submissions and lost-and-reassigned connectors and tasks will be added to these assignments,
+ // and load-balancing revocations will be removed from them.
+ final List<WorkerLoad> nextWorkerAssignment = workerLoads(memberAssignments, ConnectorsAndTasks.combine(deleted, duplicated));
- handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
+ final ConnectorsAndTasks.Builder lostAssignmentsToReassign = ConnectorsAndTasks.builder();
+ handleLostAssignments(lostAssignments, lostAssignmentsToReassign, nextWorkerAssignment);
// Do not revoke resources for re-assignment while a delayed rebalance is active
- // Also we do not revoke in two consecutive rebalances by the same leader
- canRevoke = delay == 0 && canRevoke;
+ // Also we do not revoke in two consecutive rebalances by the same leader, which
+ // should be fine since workers immediately rejoin the group after a rebalance
+ // if connectors and/or tasks were revoked from them
+ canRevoke = canRevoke && delay == 0;
// Compute the connectors-and-tasks to be revoked for load balancing without taking into
// account the deleted ones.
- log.debug("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
+ log.trace("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
if (canRevoke) {
- Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
-
- toExplicitlyRevoke.forEach(
- (worker, assignment) -> {
- ConnectorsAndTasks existing = toRevoke.computeIfAbsent(
- worker,
- v -> new ConnectorsAndTasks.Builder().build());
- existing.connectors().addAll(assignment.connectors());
- existing.tasks().addAll(assignment.tasks());
- }
- );
- canRevoke = toExplicitlyRevoke.size() == 0;
+ Map<String, ConnectorsAndTasks> loadBalancingRevocations =
+ performLoadBalancingRevocations(configured, nextWorkerAssignment);
+
+ log.trace("Load-balancing revocations for each worker: {}", loadBalancingRevocations);
+ addAll(toRevoke, loadBalancingRevocations);
+ canRevoke = ConnectorsAndTasks.combine(loadBalancingRevocations.values()).isEmpty();
} else {
canRevoke = delay == 0;
}
- assignConnectors(completeWorkerAssignment, newSubmissions.connectors());
- assignTasks(completeWorkerAssignment, newSubmissions.tasks());
- log.debug("Current complete assignments: {}", currentWorkerAssignment);
- log.debug("New complete assignments: {}", completeWorkerAssignment);
+ final ConnectorsAndTasks toAssign = ConnectorsAndTasks.combine(created, lostAssignmentsToReassign.build());
+ assignConnectors(nextWorkerAssignment, toAssign.connectors());
+ assignTasks(nextWorkerAssignment, toAssign.tasks());
- Map<String, Collection<String>> currentConnectorAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- Map<String, Collection<ConnectorTaskId>> currentTaskAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- Map<String, Collection<String>> incrementalConnectorAssignments =
- diff(connectorAssignments, currentConnectorAssignments);
- Map<String, Collection<ConnectorTaskId>> incrementalTaskAssignments =
- diff(taskAssignments, currentTaskAssignments);
+ // The complete set of connectors and tasks that will be running on each worker after this rebalance
+ final Map<String, ConnectorsAndTasks> nextAssignments = assignments(nextWorkerAssignment);
- log.debug("Incremental connector assignments: {}", incrementalConnectorAssignments);
- log.debug("Incremental task assignments: {}", incrementalTaskAssignments);
+ log.debug("Current complete assignments: {}", memberAssignments);
+ log.debug("New complete assignments: {}", nextAssignments);
Review Comment:
Fair enough! Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r847446537
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
+ log.trace("Lost assignments: {}", lostAssignments);
- // Per worker task assignments without removing deleted connectors yet
- Map<String, Collection<ConnectorTaskId>> taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- log.debug("Complete (ignoring deletions) task assignments: {}", taskAssignments);
+ // The connectors and tasks that have been created since the last rebalance
+ final ConnectorsAndTasks created = ConnectorsAndTasks.diff(configured, previousAssignment, activeAssignments);
+ log.trace("New assignments: {}", created);
- // A collection of the current assignment excluding the connectors-and-tasks to be deleted
- List<WorkerLoad> currentWorkerAssignment = workerAssignment(memberConfigs, deleted);
+ final Map<String, ConnectorsAndTasks.Builder> toRevoke = new HashMap<>();
- Map<String, ConnectorsAndTasks> toRevoke = computeDeleted(deleted, connectorAssignments, taskAssignments);
- log.debug("Connector and task to delete assignments: {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> deletedAndRevoked = intersection(deleted, memberAssignments);
+ log.trace("Deleted connectors and tasks to revoke from each worker: {}", deletedAndRevoked);
+ addAll(toRevoke, deletedAndRevoked);
// Revoking redundant connectors/tasks if the workers have duplicate assignments
- toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
- log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> duplicatedAndRevoked = intersection(duplicated, memberAssignments);
+ log.trace("Duplicated connectors and tasks to revoke from each worker: {}", duplicatedAndRevoked);
+ addAll(toRevoke, duplicatedAndRevoked);
- // Recompute the complete assignment excluding the deleted connectors-and-tasks
- completeWorkerAssignment = workerAssignment(memberConfigs, deleted);
- connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
+ // Compute the assignment that will be applied across the cluster after this round of rebalance
+ // Later on, new submissions and lost-and-reassigned connectors and tasks will be added to these assignments,
+ // and load-balancing revocations will be removed from them.
+ final List<WorkerLoad> nextWorkerAssignment = workerLoads(memberAssignments, ConnectorsAndTasks.combine(deleted, duplicated));
- handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
+ final ConnectorsAndTasks.Builder lostAssignmentsToReassign = ConnectorsAndTasks.builder();
+ handleLostAssignments(lostAssignments, lostAssignmentsToReassign, nextWorkerAssignment);
// Do not revoke resources for re-assignment while a delayed rebalance is active
- // Also we do not revoke in two consecutive rebalances by the same leader
- canRevoke = delay == 0 && canRevoke;
+ // Also we do not revoke in two consecutive rebalances by the same leader, which
+ // should be fine since workers immediately rejoin the group after a rebalance
+ // if connectors and/or tasks were revoked from them
+ canRevoke = canRevoke && delay == 0;
// Compute the connectors-and-tasks to be revoked for load balancing without taking into
// account the deleted ones.
- log.debug("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
+ log.trace("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
if (canRevoke) {
- Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
-
- toExplicitlyRevoke.forEach(
- (worker, assignment) -> {
- ConnectorsAndTasks existing = toRevoke.computeIfAbsent(
- worker,
- v -> new ConnectorsAndTasks.Builder().build());
- existing.connectors().addAll(assignment.connectors());
- existing.tasks().addAll(assignment.tasks());
- }
- );
- canRevoke = toExplicitlyRevoke.size() == 0;
+ Map<String, ConnectorsAndTasks> loadBalancingRevocations =
+ performLoadBalancingRevocations(configured, nextWorkerAssignment);
+
+ log.trace("Load-balancing revocations for each worker: {}", loadBalancingRevocations);
+ addAll(toRevoke, loadBalancingRevocations);
+ canRevoke = ConnectorsAndTasks.combine(loadBalancingRevocations.values()).isEmpty();
} else {
canRevoke = delay == 0;
}
- assignConnectors(completeWorkerAssignment, newSubmissions.connectors());
- assignTasks(completeWorkerAssignment, newSubmissions.tasks());
- log.debug("Current complete assignments: {}", currentWorkerAssignment);
- log.debug("New complete assignments: {}", completeWorkerAssignment);
+ final ConnectorsAndTasks toAssign = ConnectorsAndTasks.combine(created, lostAssignmentsToReassign.build());
+ assignConnectors(nextWorkerAssignment, toAssign.connectors());
+ assignTasks(nextWorkerAssignment, toAssign.tasks());
- Map<String, Collection<String>> currentConnectorAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- Map<String, Collection<ConnectorTaskId>> currentTaskAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- Map<String, Collection<String>> incrementalConnectorAssignments =
- diff(connectorAssignments, currentConnectorAssignments);
- Map<String, Collection<ConnectorTaskId>> incrementalTaskAssignments =
- diff(taskAssignments, currentTaskAssignments);
+ // The complete set of connectors and tasks that will be running on each worker after this rebalance
+ final Map<String, ConnectorsAndTasks> nextAssignments = assignments(nextWorkerAssignment);
- log.debug("Incremental connector assignments: {}", incrementalConnectorAssignments);
- log.debug("Incremental task assignments: {}", incrementalTaskAssignments);
+ log.debug("Current complete assignments: {}", memberAssignments);
+ log.debug("New complete assignments: {}", nextAssignments);
Review Comment:
@C0urante
Thank you for the reply:)
I may not know how your team works but maybe keeping `next` is looking better for me. Because if we change `next` to `new`, we need to change all variable names and consider huge side effects.
If someone wants to change `next` to `new` it should be working with saperate PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] YeonCheolGit commented on a diff in pull request #12019: KAFKA-13764: Improve balancing algorithm for Connect incremental rebalancing
Posted by GitBox <gi...@apache.org>.
YeonCheolGit commented on code in PR #12019:
URL: https://github.com/apache/kafka/pull/12019#discussion_r847446537
##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java:
##########
@@ -200,283 +229,149 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
previousAssignment = activeAssignments;
canRevoke = true;
}
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
+ previousRevocation = ConnectorsAndTasks.EMPTY;
}
- // Derived set: The set of deleted connectors-and-tasks is a derived set from the set
- // difference of previous - configured
- ConnectorsAndTasks deleted = diff(previousAssignment, configured);
- log.debug("Deleted assignments: {}", deleted);
-
- // Derived set: The set of remaining active connectors-and-tasks is a derived set from the
- // set difference of active - deleted
- ConnectorsAndTasks remainingActive = diff(activeAssignments, deleted);
- log.debug("Remaining (excluding deleted) active assignments: {}", remainingActive);
-
- // Derived set: The set of lost or unaccounted connectors-and-tasks is a derived set from
- // the set difference of previous - active - deleted
- ConnectorsAndTasks lostAssignments = diff(previousAssignment, activeAssignments, deleted);
- log.debug("Lost assignments: {}", lostAssignments);
-
- // Derived set: The set of new connectors-and-tasks is a derived set from the set
- // difference of configured - previous - active
- ConnectorsAndTasks newSubmissions = diff(configured, previousAssignment, activeAssignments);
- log.debug("New assignments: {}", newSubmissions);
+ // The connectors and tasks that have been deleted since the last rebalance
+ final ConnectorsAndTasks deleted = ConnectorsAndTasks.diff(previousAssignment, configured);
+ log.trace("Deleted assignments: {}", deleted);
- // A collection of the complete assignment
- List<WorkerLoad> completeWorkerAssignment = workerAssignment(memberConfigs, ConnectorsAndTasks.EMPTY);
- log.debug("Complete (ignoring deletions) worker assignments: {}", completeWorkerAssignment);
+ // The connectors and tasks that are currently running on more than one worker each
+ final ConnectorsAndTasks duplicated = duplicated(memberAssignments);
+ log.trace("Duplicated assignments: {}", duplicated);
- // Per worker connector assignments without removing deleted connectors yet
- Map<String, Collection<String>> connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- log.debug("Complete (ignoring deletions) connector assignments: {}", connectorAssignments);
+ // The connectors and tasks that should already be running on the cluster, but which are not included
+ // in the assignment reported by any workers in the cluster
+ final ConnectorsAndTasks lostAssignments = ConnectorsAndTasks.diff(previousAssignment, activeAssignments, deleted);
+ log.trace("Lost assignments: {}", lostAssignments);
- // Per worker task assignments without removing deleted connectors yet
- Map<String, Collection<ConnectorTaskId>> taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- log.debug("Complete (ignoring deletions) task assignments: {}", taskAssignments);
+ // The connectors and tasks that have been created since the last rebalance
+ final ConnectorsAndTasks created = ConnectorsAndTasks.diff(configured, previousAssignment, activeAssignments);
+ log.trace("New assignments: {}", created);
- // A collection of the current assignment excluding the connectors-and-tasks to be deleted
- List<WorkerLoad> currentWorkerAssignment = workerAssignment(memberConfigs, deleted);
+ final Map<String, ConnectorsAndTasks.Builder> toRevoke = new HashMap<>();
- Map<String, ConnectorsAndTasks> toRevoke = computeDeleted(deleted, connectorAssignments, taskAssignments);
- log.debug("Connector and task to delete assignments: {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> deletedAndRevoked = intersection(deleted, memberAssignments);
+ log.trace("Deleted connectors and tasks to revoke from each worker: {}", deletedAndRevoked);
+ addAll(toRevoke, deletedAndRevoked);
// Revoking redundant connectors/tasks if the workers have duplicate assignments
- toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
- log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ final Map<String, ConnectorsAndTasks> duplicatedAndRevoked = intersection(duplicated, memberAssignments);
+ log.trace("Duplicated connectors and tasks to revoke from each worker: {}", duplicatedAndRevoked);
+ addAll(toRevoke, duplicatedAndRevoked);
- // Recompute the complete assignment excluding the deleted connectors-and-tasks
- completeWorkerAssignment = workerAssignment(memberConfigs, deleted);
- connectorAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- taskAssignments =
- completeWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
+ // Compute the assignment that will be applied across the cluster after this round of rebalance
+ // Later on, new submissions and lost-and-reassigned connectors and tasks will be added to these assignments,
+ // and load-balancing revocations will be removed from them.
+ final List<WorkerLoad> nextWorkerAssignment = workerLoads(memberAssignments, ConnectorsAndTasks.combine(deleted, duplicated));
- handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
+ final ConnectorsAndTasks.Builder lostAssignmentsToReassign = ConnectorsAndTasks.builder();
+ handleLostAssignments(lostAssignments, lostAssignmentsToReassign, nextWorkerAssignment);
// Do not revoke resources for re-assignment while a delayed rebalance is active
- // Also we do not revoke in two consecutive rebalances by the same leader
- canRevoke = delay == 0 && canRevoke;
+ // Also we do not revoke in two consecutive rebalances by the same leader, which
+ // should be fine since workers immediately rejoin the group after a rebalance
+ // if connectors and/or tasks were revoked from them
+ canRevoke = canRevoke && delay == 0;
// Compute the connectors-and-tasks to be revoked for load balancing without taking into
// account the deleted ones.
- log.debug("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
+ log.trace("Can leader revoke tasks in this assignment? {} (delay: {})", canRevoke, delay);
if (canRevoke) {
- Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
-
- toExplicitlyRevoke.forEach(
- (worker, assignment) -> {
- ConnectorsAndTasks existing = toRevoke.computeIfAbsent(
- worker,
- v -> new ConnectorsAndTasks.Builder().build());
- existing.connectors().addAll(assignment.connectors());
- existing.tasks().addAll(assignment.tasks());
- }
- );
- canRevoke = toExplicitlyRevoke.size() == 0;
+ Map<String, ConnectorsAndTasks> loadBalancingRevocations =
+ performLoadBalancingRevocations(configured, nextWorkerAssignment);
+
+ log.trace("Load-balancing revocations for each worker: {}", loadBalancingRevocations);
+ addAll(toRevoke, loadBalancingRevocations);
+ canRevoke = ConnectorsAndTasks.combine(loadBalancingRevocations.values()).isEmpty();
} else {
canRevoke = delay == 0;
}
- assignConnectors(completeWorkerAssignment, newSubmissions.connectors());
- assignTasks(completeWorkerAssignment, newSubmissions.tasks());
- log.debug("Current complete assignments: {}", currentWorkerAssignment);
- log.debug("New complete assignments: {}", completeWorkerAssignment);
+ final ConnectorsAndTasks toAssign = ConnectorsAndTasks.combine(created, lostAssignmentsToReassign.build());
+ assignConnectors(nextWorkerAssignment, toAssign.connectors());
+ assignTasks(nextWorkerAssignment, toAssign.tasks());
- Map<String, Collection<String>> currentConnectorAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::connectors));
- Map<String, Collection<ConnectorTaskId>> currentTaskAssignments =
- currentWorkerAssignment.stream().collect(Collectors.toMap(WorkerLoad::worker, WorkerLoad::tasks));
- Map<String, Collection<String>> incrementalConnectorAssignments =
- diff(connectorAssignments, currentConnectorAssignments);
- Map<String, Collection<ConnectorTaskId>> incrementalTaskAssignments =
- diff(taskAssignments, currentTaskAssignments);
+ // The complete set of connectors and tasks that will be running on each worker after this rebalance
+ final Map<String, ConnectorsAndTasks> nextAssignments = assignments(nextWorkerAssignment);
- log.debug("Incremental connector assignments: {}", incrementalConnectorAssignments);
- log.debug("Incremental task assignments: {}", incrementalTaskAssignments);
+ log.debug("Current complete assignments: {}", memberAssignments);
+ log.debug("New complete assignments: {}", nextAssignments);
Review Comment:
@C0urante
Thank you for the reply:)
I may not know how your team works but maybe keeping `next` is looking better for me. Because if we change `next` to `new`, we need to change all variable names and consider huge side effects.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org