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 2021/03/20 03:58:15 UTC
[GitHub] [kafka] showuon opened a new pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
showuon opened a new pull request #10367:
URL: https://github.com/apache/kafka/pull/10367
jira: https://issues.apache.org/jira/browse/KAFKA-12495
Allow consecutive revoke in incremental cooperative assignor in connector, to fix the issue when new members joined right after revocation round, which causes uneven distribution. What I did are:
1. remove `canRevoke` and `previousRevocation` variable, since we allow consecutive revoking (as lone as `delay == 0`) now
2. compute `currentWorkerAssignmentWithoutDuplication`, to remove duplicated connectors/tasks from `currentWorkerAssignment`, so that we can use it to compute if we need revoke more connectors/tasks in this round
3. When entering `performTaskRevocation`, we passed in the configured assignment, so that we can compute the expected result size (totalSize/workerSize)
### 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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598381699
##########
File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java
##########
@@ -532,23 +531,23 @@ private void resetDelay() {
* 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
+ * @param allConnectorsAndTasks all the connectors and tasks we need to distribute
+ * @param completeWorkerAssignmentWithoutDuplication current workers assignment without duplication
+ * @return the connectors/tasks that needed to be revoked on each worker, if no revoke is required, will return empty map
*/
- 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()
+ private Map<String, ConnectorsAndTasks> performTaskRevocation(ConnectorsAndTasks allConnectorsAndTasks,
+ Collection<WorkerLoad> completeWorkerAssignmentWithoutDuplication) {
+ int totalConnectorsNum = allConnectorsAndTasks.connectors().size();
+ int totalTasksNum = allConnectorsAndTasks.tasks().size();
+ Collection<WorkerLoad> existingWorkers = completeWorkerAssignmentWithoutDuplication.stream()
Review comment:
Use `allConnectorsAndTasks` (`configured`) to compute the total connectors/tasks number, and use the `completeWorkerAssignmentWithoutDuplication` to compute the existing workers.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598077882
##########
File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java
##########
@@ -60,8 +60,6 @@
private final Time time;
private final int maxDelay;
private ConnectorsAndTasks previousAssignment;
- private ConnectorsAndTasks previousRevocation;
- private boolean canRevoke;
Review comment:
change (1): remove unused `canRevoke`
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598078087
##########
File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java
##########
@@ -192,28 +188,11 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
ConnectorsAndTasks activeAssignments = assignment(memberConfigs);
log.debug("Active assignments: {}", activeAssignments);
- // This means that a previous revocation did not take effect. In this case, reset
- // appropriately and be ready to re-apply revocation of tasks
Review comment:
After this fix, we can work well under this case: _a previous revocation did not take effect_, by computing the ceiling of totalTasksWeHave / totalWorkers in `performTasksRevocation` method, and check if current assignment in each worker higher than this amount.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598081851
##########
File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java
##########
@@ -1133,20 +1219,9 @@ public void testTaskAssignmentWhenTasksDuplicatedInWorkerAssignment() {
assertDelay(0, returnedAssignments);
expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
assertNoReassignments(memberConfigs, expectedMemberConfigs);
- assertAssignment(1, 4, 0, 2, "worker1", "worker2");
Review comment:
This revocation is unnecessary because we revoked the connecor1 and all of the tasks in connector1 in previous round, so when entering this round, the assignment is:
W1: connectors: [connector2], tasks: [T2-0, T2-1, T2-2, T2-3]
W2: connectors: [], tasks: []
We can just assign the connector1 and 4 of his tasks into W2, and complete the rebalance.
However, before my change, in `performTasksRevocation` method, we use `activeAssignment` as the total tasks, so, we'll get the `avg umber of tasks each worker can have` = 4 (total active tasks) / 2 (total worker) = 2, then revoke 2 tasks, and then assign to 2 workers in next round.
After my change, the `avg number of tasks each worker can have` will be: 8 (total tasks) / 2 (total workers) = 4, so no tasks will be revoked.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598081851
##########
File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java
##########
@@ -1133,20 +1219,9 @@ public void testTaskAssignmentWhenTasksDuplicatedInWorkerAssignment() {
assertDelay(0, returnedAssignments);
expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
assertNoReassignments(memberConfigs, expectedMemberConfigs);
- assertAssignment(1, 4, 0, 2, "worker1", "worker2");
Review comment:
This revocation is unnecessary because we revoked the connecor1 and all of the tasks in connector1 in previous round, so when entering this round, the assignment is:
W1: connectors: [C0], tasks: [T0-0, T0-1, T0-2, T0-3]
W2: connectors: [], tasks: []
We can just assign the connector1 and 4 of his tasks into W2, and complete the rebalance.
However, before my change, in `performTasksRevocation` method, we use `activeAssignment` as the total tasks, so, we'll get the `avg umber of tasks each worker can have` = 4 (total active tasks) / 2 (total worker) = 2, then revoke 2 tasks, and then assign to 2 workers in next round.
After my change, the `avg number of tasks each worker can have` will be: 8 (total tasks) / 2 (total workers) = 4, so no tasks will be revoked.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598081851
##########
File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java
##########
@@ -1133,20 +1219,9 @@ public void testTaskAssignmentWhenTasksDuplicatedInWorkerAssignment() {
assertDelay(0, returnedAssignments);
expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
assertNoReassignments(memberConfigs, expectedMemberConfigs);
- assertAssignment(1, 4, 0, 2, "worker1", "worker2");
Review comment:
This revocation is unnecessary because we revoked the connecor1 and all of the tasks in connector1 in previous round, so when entering this round, the assignment is:
W1: connectors: [connector2], tasks: [T2-0, T2-1, T2-2, T2-3]
W2: connectors: [], tasks: []
We can just assign the connector1 and 4 of his tasks into W2, and complete the rebalance.
However, before my change, in `performTasksRevocation` method, we use `activeAssignment` as the total tasks, so, we'll get the numTasksToRevoked = 4 (active tasks) / 2 (total worker) = 2, then revoke 2 tasks, and then assign to 2 workers in next round.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#issuecomment-878731886
@kkonstantine , I suddenly found this is a V3.0 blocker bug. Could you help take a look. Thanks.
--
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] showuon edited a comment on pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon edited a comment on pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#issuecomment-861125710
@kkonstantine , could you check this PR? Or I should find another guy to review this PR since it's been 3 months? Thanks.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598079706
##########
File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java
##########
@@ -489,12 +473,10 @@ protected void handleLostAssignments(ConnectorsAndTasks lostAssignments,
log.debug("Delayed rebalance in progress. Task reassignment is postponed. New computed rebalance delay: {}", delay);
} else {
// This means scheduledRebalance == 0
- // We could also also extract the current minimum delay from the group, to make
- // independent of consecutive leader failures, but this optimization is skipped
- // at the moment
+ // We could also extract the current minimum delay from the group, to make
+ // independent of consecutive leader failures, but this optimization is skipped at the moment
delay = maxDelay;
- log.debug("Resetting rebalance delay to the max: {}. scheduledRebalance: {} now: {} diff scheduledRebalance - now: {}",
- delay, scheduledRebalance, now, scheduledRebalance - now);
Review comment:
As the comment said, this else block means `scheduledRebalance == 0`, so we don't need to log the `scheduledRebalance` and `now` value
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598488476
##########
File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java
##########
@@ -650,7 +1035,18 @@ public void testTaskAssignmentWhenConnectorsAreDeleted() {
when(coordinator.configSnapshot()).thenReturn(configState);
doReturn(Collections.EMPTY_MAP).when(assignor).serializeAssignments(assignmentsCapture.capture());
- // First assignment with 1 worker and 2 connectors configured but not yet assigned
+ // First assignment with 2 worker and 3 connectors configured but not yet assigned
Review comment:
fix the wrong comment
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598082304
##########
File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java
##########
@@ -1195,20 +1270,9 @@ public void testDuplicatedAssignmentHandleWhenTheDuplicatedAssignmentsDeleted()
assertDelay(0, returnedAssignments);
expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
assertNoReassignments(memberConfigs, expectedMemberConfigs);
- assertAssignment(0, 0, 2, 8, "worker1", "worker2");
-
- // Third assignment after revocations
- applyAssignments(returnedAssignments);
- memberConfigs = memberConfigs(leader, offset, assignments);
- assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
- ++rebalanceNum;
- returnedAssignments = assignmentsCapture.getValue();
- assertDelay(0, returnedAssignments);
- expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
- assertNoReassignments(memberConfigs, expectedMemberConfigs);
- assertAssignment(0, 0, 0, 2, "worker1", "worker2");
+ assertAssignment(0, 0, 2, 10, "worker1", "worker2");
Review comment:
Same as above comments. Before my change, we revoke 8 tasks in 1st round, and then 2 tasks in next round. After my change, we revoke total 10 tasks in 1 round.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598078375
##########
File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java
##########
@@ -192,28 +188,11 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
ConnectorsAndTasks activeAssignments = assignment(memberConfigs);
log.debug("Active assignments: {}", activeAssignments);
- // This means that a previous revocation did not take effect. In this case, reset
- // appropriately and be ready to re-apply revocation of tasks
- if (!previousRevocation.isEmpty()) {
- if (previousRevocation.connectors().stream().anyMatch(c -> activeAssignments.connectors().contains(c))
- || previousRevocation.tasks().stream().anyMatch(t -> activeAssignments.tasks().contains(t))) {
- previousAssignment = activeAssignments;
- canRevoke = true;
- }
- previousRevocation.connectors().clear();
- previousRevocation.tasks().clear();
- }
-
// 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);
Review comment:
This is not used anywhere else, so delete it.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] C0urante commented on pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
C0urante commented on pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#issuecomment-1083666779
@showuon FWIW, I've got a refactoring PR up for the testing logic that we might take a look at in the meantime: https://github.com/apache/kafka/pull/11974
Hopefully this should make writing and reviewing tests for changes like in this PR easier in the future.
--
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] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598078087
##########
File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java
##########
@@ -192,28 +188,11 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
ConnectorsAndTasks activeAssignments = assignment(memberConfigs);
log.debug("Active assignments: {}", activeAssignments);
- // This means that a previous revocation did not take effect. In this case, reset
- // appropriately and be ready to re-apply revocation of tasks
Review comment:
After this fix, we can work well under this case: _a previous revocation did not take effect_, by computing the ceiling of totalTasksWeHave / totalWorkers in `performTasksRevocation` method, and check if current assignment in each worker higher than this amount.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#issuecomment-861125710
@kkonstantine , could you check this PR? Or I should find another guy to review this PR? Thanks.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598078087
##########
File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java
##########
@@ -192,28 +188,11 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
ConnectorsAndTasks activeAssignments = assignment(memberConfigs);
log.debug("Active assignments: {}", activeAssignments);
- // This means that a previous revocation did not take effect. In this case, reset
- // appropriately and be ready to re-apply revocation of tasks
Review comment:
After this fix, we can work well under this case: _a previous revocation did not take effect_, by computing the totalTasksWeHave / totalWorkers in `performTasksRevocation` method, and check if current assignment in each worker higher than this amount.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598488014
##########
File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java
##########
@@ -137,6 +145,16 @@ public void testTaskAssignmentWhenWorkerJoins() {
assertAssignment(2, 8, 0, 0, "worker1");
// Second assignment with a second worker joining and all connectors running on previous worker
+ //
+ // assignment after this phase:
+ // W1: assignedConnectors:[], assignedTasks:[],
+ // revokedConnectors:[C1], revokedTasks:[T1-0, T1-1, T1-2, T1-3]
Review comment:
change (4): improve test readability by adding the final assignment for each phase of rebalance. It'll let other devs/users better understanding how the tests go and how the algorithm works.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] C0urante commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
C0urante commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r833730504
##########
File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java
##########
@@ -180,6 +208,155 @@ public void testTaskAssignmentWhenWorkerJoins() {
verify(coordinator, times(rebalanceNum)).lastCompletedGenerationId();
}
+ @Test
+ public void testTaskAssignmentWhenWorkerJoinAfterRevocation() {
+ when(coordinator.configSnapshot()).thenReturn(configState);
+ doReturn(Collections.EMPTY_MAP).when(assignor).serializeAssignments(assignmentsCapture.capture());
+
+ // First assignment with 1 worker and 2 connectors configured but not yet assigned
+ //
+ // note: the assigned/revoked Connectors/tasks might be different, but the amount should be the same
+ // assignment after this phase:
+ // W1: assignedConnectors:[C0, C1], assignedTasks:[T0-0, T0-1, T0-2, T0-3, T1-0, T1-1, T1-2, T1-3],
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0, C1], tasks:[T0-0, T0-1, T0-2, T0-3, T1-0, T1-1, T1-2, T1-3]
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(2, 8, 0, 0, "worker1");
+
+ // Second assignment with a second worker joining and all connectors running on previous worker
+ //
+ // assignment after this phase:
+ // W1: assignedConnectors:[], assignedTasks:[],
+ // revokedConnectors:[C1], revokedTasks:[T1-0, T1-1, T1-2, T1-3]
+ // W2: assignedConnectors:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1, T0-2, T0-3]
+ // W2: connectors:[], tasks:[]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker2", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(0, 0, 1, 4, "worker1", "worker2");
+
+ // Third assignment after revocations, and a third worker joining
+ //
+ // assignment after this phase:
+ // W1: assignedTasks:[], assignedTasks:[],
+ // revokedConnectors:[], revokedTasks:[T0-3]
+ // W2: assignedTasks:[C1], assignedTasks:[T1-0, T1-1]
+ // revokedConnectors:[] revokedTasks:[]
+ // W3: assignedTasks:[], assignedTasks:[T1-2, T1-3]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1, T0-2]
+ // W2: connectors:[C1], tasks:[T1-0, T1-1]
+ // W3: connectors:[], tasks:[T1-2, T1-3]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker3", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(1, 4, 0, 1, "worker1", "worker2", "worker3");
Review comment:
Covered by [KAFKA-13763](https://issues.apache.org/jira/browse/KAFKA-13763).
--
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] showuon commented on pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#issuecomment-803850434
@kkonstantine @rhauch @ramesh-muthusamy , could you help review this PR to fix the uneven distribution in incremental cooperative assignor in connector? Thanks.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598078620
##########
File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java
##########
@@ -248,6 +227,10 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
toRevoke.putAll(computeDuplicatedAssignments(memberConfigs, connectorAssignments, taskAssignments));
log.debug("Connector and task to revoke assignments (include duplicated assignments): {}", toRevoke);
+ List<WorkerLoad> currentWorkerAssignmentWithoutDuplication =
+ removeDuplicated(workerAssignment(memberConfigs, deleted), toRevoke);
+ log.debug("Complete (excluding deletions and remove duplicated assignments) worker assignments: {}", currentWorkerAssignmentWithoutDuplication);
Review comment:
change (2): compute the current worker assignment excluding deletions and duplicated assignments. If after excluding deletion and duplicated assignments, there are still workers have assignment higher than totalTasksWeHave / totalWorkers, we still need to revoke more tasks.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598078087
##########
File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java
##########
@@ -192,28 +188,11 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
ConnectorsAndTasks activeAssignments = assignment(memberConfigs);
log.debug("Active assignments: {}", activeAssignments);
- // This means that a previous revocation did not take effect. In this case, reset
- // appropriately and be ready to re-apply revocation of tasks
Review comment:
After this fix, we can work well under this case: _a previous revocation did not take effect_, by computing the totalTasksWeHave / totalWorkers in `performTasksRevocation` method
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#issuecomment-1069090526
@C0urante , thanks for your comments. TBH, I need some time to revisit the code (since it's long time ago...), and answering your comments later. Thank you.
--
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] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598079320
##########
File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java
##########
@@ -258,17 +241,12 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
// 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;
-
- // 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);
- if (canRevoke) {
+ log.debug("Can leader revoke tasks in this assignment? (delay: {})", delay);
+ if (delay == 0) {
+ // Compute the connectors-and-tasks to be revoked for load balancing without taking into
+ // account the deleted ones.
Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
+ performTaskRevocation(configured, currentWorkerAssignmentWithoutDuplication);
Review comment:
change (3): pass `configured` (total tasks we have), and `currentWorkerAssignmentWithoutDuplication` into `performTaskRevocation` method.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598081851
##########
File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java
##########
@@ -1133,20 +1219,9 @@ public void testTaskAssignmentWhenTasksDuplicatedInWorkerAssignment() {
assertDelay(0, returnedAssignments);
expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
assertNoReassignments(memberConfigs, expectedMemberConfigs);
- assertAssignment(1, 4, 0, 2, "worker1", "worker2");
Review comment:
This revocation is unnecessary because we revoked the connecor1 and all of the tasks in connector1 in previous round, so when entering this round, the assignment is:
W1: connectors: [C0], tasks: [T0-0, T0-1, T0-2, T0-3]
W2: connectors: [], tasks: []
We can just assign the connector1 and 4 of his tasks into W2, and complete the rebalance.
However, before my change, in `performTasksRevocation` method, we use `activeAssignment` as the total tasks, so, we'll get the `avg number of tasks each worker can have` = 4 (total active tasks) / 2 (total worker) = 2, then revoke 2 tasks, and then assign to 2 workers in next round.
After my change, the `avg number of tasks each worker can have` will be: 8 (total tasks) / 2 (total workers) = 4, so no tasks will be revoked.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] C0urante commented on pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
C0urante commented on pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#issuecomment-1076777750
Thanks @showuon. In that case, I can file separate issues for a lot of the comments I've made here, and we can try to keep this PR as focused as possible for the sake of moving forward.
--
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] showuon commented on pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#issuecomment-1077035346
@C0urante , sure, please file another PR for other comments. And thanks for the comments. However, I'm still concerned that @kkonstantine doesn't like the current solution, and would like to have another proposal as mentioned [here](https://issues.apache.org/jira/browse/KAFKA-12495?focusedCommentId=17380872&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17380872). So, I think we still need to get his approval before we can continue. WDYT?
cc @kkonstantine , we need your suggestions here, please!
--
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] showuon commented on pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#issuecomment-1032172509
@kkonstantine , call for review and comments. Thanks.
--
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 change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
C0urante commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r803045306
##########
File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java
##########
@@ -532,23 +531,23 @@ private void resetDelay() {
* 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
+ * @param allConnectorsAndTasks all the connectors and tasks we need to distribute
+ * @param completeWorkerAssignmentWithoutDuplication current workers assignment without duplication
Review comment:
I think the existing variable name is fine; we can definitely update the Javadoc to clarify that this assignment should exclude duplicated and to-be-deleted C/T, but something this long is a little hard to read.
##########
File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java
##########
@@ -180,6 +208,155 @@ public void testTaskAssignmentWhenWorkerJoins() {
verify(coordinator, times(rebalanceNum)).lastCompletedGenerationId();
}
+ @Test
+ public void testTaskAssignmentWhenWorkerJoinAfterRevocation() {
+ when(coordinator.configSnapshot()).thenReturn(configState);
+ doReturn(Collections.EMPTY_MAP).when(assignor).serializeAssignments(assignmentsCapture.capture());
+
+ // First assignment with 1 worker and 2 connectors configured but not yet assigned
+ //
+ // note: the assigned/revoked Connectors/tasks might be different, but the amount should be the same
+ // assignment after this phase:
+ // W1: assignedConnectors:[C0, C1], assignedTasks:[T0-0, T0-1, T0-2, T0-3, T1-0, T1-1, T1-2, T1-3],
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0, C1], tasks:[T0-0, T0-1, T0-2, T0-3, T1-0, T1-1, T1-2, T1-3]
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(2, 8, 0, 0, "worker1");
+
+ // Second assignment with a second worker joining and all connectors running on previous worker
+ //
+ // assignment after this phase:
+ // W1: assignedConnectors:[], assignedTasks:[],
+ // revokedConnectors:[C1], revokedTasks:[T1-0, T1-1, T1-2, T1-3]
+ // W2: assignedConnectors:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1, T0-2, T0-3]
+ // W2: connectors:[], tasks:[]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker2", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(0, 0, 1, 4, "worker1", "worker2");
+
+ // Third assignment after revocations, and a third worker joining
+ //
+ // assignment after this phase:
+ // W1: assignedTasks:[], assignedTasks:[],
+ // revokedConnectors:[], revokedTasks:[T0-3]
+ // W2: assignedTasks:[C1], assignedTasks:[T1-0, T1-1]
+ // revokedConnectors:[] revokedTasks:[]
+ // W3: assignedTasks:[], assignedTasks:[T1-2, T1-3]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1, T0-2]
+ // W2: connectors:[C1], tasks:[T1-0, T1-1]
+ // W3: connectors:[], tasks:[T1-2, T1-3]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker3", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(1, 4, 0, 1, "worker1", "worker2", "worker3");
+
+ // Forth assignment after revocations, and a forth worker joining
+ //
+ // assignment after this phase:
+ // W1: assignedTasks:[], assignedTasks:[],
+ // revokedConnectors:[], revokedTasks:[T0-2]
+ // W2: assignedTasks:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ // W3: assignedTasks:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ // W4: assignedTasks:[], assignedTasks:[T0-3]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1]
+ // W2: connectors:[C1], tasks:[T1-0, T1-1]
+ // W3: connectors:[], tasks:[T1-2, T1-3]
+ // W4: connectors:[], tasks:[T0-3]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker4", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(0, 1, 0, 1, "worker1", "worker2", "worker3", "worker4");
+
+ // Fifth assignment after revocations
+ //
+ // assignment after this phase:
+ // W1: assignedTasks:[], assignedTasks:[],
+ // revokedConnectors:[], revokedTasks:[]
+ // W2: assignedTasks:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ // W3: assignedTasks:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ // W4: assignedTasks:[], assignedTasks:[T0-2]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1]
+ // W2: connectors:[C1], tasks:[T1-0, T1-1]
+ // W3: connectors:[], tasks:[T1-2, T1-3]
+ // W4: connectors:[], tasks:[T0-3, T0-2]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(0, 1, 0, 0, "worker1", "worker2", "worker3", "worker4");
Review comment:
By this point, we should be completely balanced, but there's no explicit testing logic to verify that. What do you think about adding a utility method like `assertBalancedAssignments` and then invoking it here (and possibly other places in this test suite)?
```java
private void assertBalancedAssignments(Map<String, ExtendedWorkerState> existingAssignments) {
List<Integer> connectorCounts = existingAssignments.values().stream()
.map(e -> e.assignment().connectors().size())
.sorted()
.collect(Collectors.toList());
List<Integer> taskCounts = existingAssignments.values().stream()
.map(e -> e.assignment().tasks().size())
.sorted()
.collect(Collectors.toList());
int minConnectors = connectorCounts.get(0);
int maxConnectors = connectorCounts.get(connectorCounts.size() - 1);
int minTasks = taskCounts.get(0);
int maxTasks = taskCounts.get(taskCounts.size() - 1);
assertTrue(
"Assignments are imbalanced. The spread of connectors across each worker is: " + connectorCounts,
maxConnectors - minConnectors <= 1
);
assertTrue(
"Assignments are imbalanced. The spread of tasks across each worker is: " + taskCounts,
maxTasks - minTasks <= 1
);
}
```
It might also make these tests easier to write and modify (if we need to tweak rebalancing logic again in the future) if we used this type of method instead of the existing `assertAssignment` one, since in many cases all that really matters is that we achieve a balanced allocation after a specific series of rebalances, instead of exactly how many C/T were assigned/revoked in the interim.
##########
File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java
##########
@@ -180,6 +208,155 @@ public void testTaskAssignmentWhenWorkerJoins() {
verify(coordinator, times(rebalanceNum)).lastCompletedGenerationId();
}
+ @Test
+ public void testTaskAssignmentWhenWorkerJoinAfterRevocation() {
+ when(coordinator.configSnapshot()).thenReturn(configState);
+ doReturn(Collections.EMPTY_MAP).when(assignor).serializeAssignments(assignmentsCapture.capture());
+
+ // First assignment with 1 worker and 2 connectors configured but not yet assigned
+ //
+ // note: the assigned/revoked Connectors/tasks might be different, but the amount should be the same
+ // assignment after this phase:
+ // W1: assignedConnectors:[C0, C1], assignedTasks:[T0-0, T0-1, T0-2, T0-3, T1-0, T1-1, T1-2, T1-3],
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0, C1], tasks:[T0-0, T0-1, T0-2, T0-3, T1-0, T1-1, T1-2, T1-3]
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(2, 8, 0, 0, "worker1");
+
+ // Second assignment with a second worker joining and all connectors running on previous worker
+ //
+ // assignment after this phase:
+ // W1: assignedConnectors:[], assignedTasks:[],
+ // revokedConnectors:[C1], revokedTasks:[T1-0, T1-1, T1-2, T1-3]
+ // W2: assignedConnectors:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1, T0-2, T0-3]
+ // W2: connectors:[], tasks:[]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker2", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(0, 0, 1, 4, "worker1", "worker2");
+
+ // Third assignment after revocations, and a third worker joining
+ //
+ // assignment after this phase:
+ // W1: assignedTasks:[], assignedTasks:[],
+ // revokedConnectors:[], revokedTasks:[T0-3]
+ // W2: assignedTasks:[C1], assignedTasks:[T1-0, T1-1]
+ // revokedConnectors:[] revokedTasks:[]
+ // W3: assignedTasks:[], assignedTasks:[T1-2, T1-3]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1, T0-2]
+ // W2: connectors:[C1], tasks:[T1-0, T1-1]
+ // W3: connectors:[], tasks:[T1-2, T1-3]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker3", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(1, 4, 0, 1, "worker1", "worker2", "worker3");
+
+ // Forth assignment after revocations, and a forth worker joining
+ //
+ // assignment after this phase:
+ // W1: assignedTasks:[], assignedTasks:[],
+ // revokedConnectors:[], revokedTasks:[T0-2]
+ // W2: assignedTasks:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ // W3: assignedTasks:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ // W4: assignedTasks:[], assignedTasks:[T0-3]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1]
+ // W2: connectors:[C1], tasks:[T1-0, T1-1]
+ // W3: connectors:[], tasks:[T1-2, T1-3]
+ // W4: connectors:[], tasks:[T0-3]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker4", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(0, 1, 0, 1, "worker1", "worker2", "worker3", "worker4");
+
+ // Fifth assignment after revocations
+ //
+ // assignment after this phase:
+ // W1: assignedTasks:[], assignedTasks:[],
+ // revokedConnectors:[], revokedTasks:[]
+ // W2: assignedTasks:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ // W3: assignedTasks:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ // W4: assignedTasks:[], assignedTasks:[T0-2]
+ // revokedConnectors:[] revokedTasks:[]
Review comment:
```suggestion
// W1: assignedConnectors:[], assignedTasks:[],
// revokedConnectors:[], revokedTasks:[]
// W2: assignedConnectors:[], assignedTasks:[]
// revokedConnectors:[] revokedTasks:[]
// W3: assignedConnectors:[], assignedTasks:[]
// revokedConnectors:[] revokedTasks:[]
// W4: assignedConnectors:[], assignedTasks:[T0-2]
// revokedConnectors:[] revokedTasks:[]
```
##########
File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java
##########
@@ -180,6 +208,155 @@ public void testTaskAssignmentWhenWorkerJoins() {
verify(coordinator, times(rebalanceNum)).lastCompletedGenerationId();
}
+ @Test
+ public void testTaskAssignmentWhenWorkerJoinAfterRevocation() {
+ when(coordinator.configSnapshot()).thenReturn(configState);
+ doReturn(Collections.EMPTY_MAP).when(assignor).serializeAssignments(assignmentsCapture.capture());
+
+ // First assignment with 1 worker and 2 connectors configured but not yet assigned
+ //
+ // note: the assigned/revoked Connectors/tasks might be different, but the amount should be the same
+ // assignment after this phase:
+ // W1: assignedConnectors:[C0, C1], assignedTasks:[T0-0, T0-1, T0-2, T0-3, T1-0, T1-1, T1-2, T1-3],
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0, C1], tasks:[T0-0, T0-1, T0-2, T0-3, T1-0, T1-1, T1-2, T1-3]
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(2, 8, 0, 0, "worker1");
+
+ // Second assignment with a second worker joining and all connectors running on previous worker
+ //
+ // assignment after this phase:
+ // W1: assignedConnectors:[], assignedTasks:[],
+ // revokedConnectors:[C1], revokedTasks:[T1-0, T1-1, T1-2, T1-3]
+ // W2: assignedConnectors:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1, T0-2, T0-3]
+ // W2: connectors:[], tasks:[]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker2", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(0, 0, 1, 4, "worker1", "worker2");
+
+ // Third assignment after revocations, and a third worker joining
+ //
+ // assignment after this phase:
+ // W1: assignedTasks:[], assignedTasks:[],
+ // revokedConnectors:[], revokedTasks:[T0-3]
+ // W2: assignedTasks:[C1], assignedTasks:[T1-0, T1-1]
+ // revokedConnectors:[] revokedTasks:[]
+ // W3: assignedTasks:[], assignedTasks:[T1-2, T1-3]
+ // revokedConnectors:[] revokedTasks:[]
Review comment:
```suggestion
// W1: assignedConnectors:[], assignedTasks:[],
// revokedConnectors:[], revokedTasks:[T0-3]
// W2: assignedConnectors:[C1], assignedTasks:[T1-0, T1-1]
// revokedConnectors:[] revokedTasks:[]
// W3: assignedConnectors:[], assignedTasks:[T1-2, T1-3]
// revokedConnectors:[] revokedTasks:[]
```
##########
File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java
##########
@@ -258,17 +241,12 @@ private Long ensureLeaderConfig(long maxOffset, WorkerCoordinator coordinator) {
handleLostAssignments(lostAssignments, newSubmissions, completeWorkerAssignment, memberConfigs);
// 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;
-
- // 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);
- if (canRevoke) {
+ log.debug("Can leader revoke tasks in this assignment? (delay: {})", delay);
+ if (delay == 0) {
+ // Compute the connectors-and-tasks to be revoked for load balancing without taking into
+ // account the deleted ones.
Map<String, ConnectorsAndTasks> toExplicitlyRevoke =
- performTaskRevocation(activeAssignments, currentWorkerAssignment);
-
- log.debug("Connector and task to revoke assignments: {}", toRevoke);
+ performTaskRevocation(configured, currentWorkerAssignmentWithoutDuplication);
Review comment:
Can you clarify why this change is necessary? I ran the new `testTaskAssignmentWhenWorkerJoinAfterRevocation` test case with and without it, and although it fails without this change, it looks like that's more due to frail testing logic with the `assertAssignment` method than an actual bug in the rebalancing logic here. If I remove the `assertAssignment` calls but manually check on the distribution of C/T across the cluster after the fifth rebalance, everything is balanced.
I've also produced a test case that fails with this change but succeeds without it:
```java
@Test
public void testNewWorkerAndNewTasksInSameRound() {
doReturn(Collections.EMPTY_MAP).when(assignor).serializeAssignments(assignmentsCapture.capture());
// Start with 40 tasks
configState = clusterConfigState(offset, 1, 40);
when(coordinator.configSnapshot()).thenReturn(configState);
// Start with three workers
memberConfigs = memberConfigs(leader, offset, 0, 2);
expectGeneration();
assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
++rebalanceNum;
returnedAssignments = assignmentsCapture.getValue();
assertDelay(0, returnedAssignments);
expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
assertNoReassignments(memberConfigs, expectedMemberConfigs);
applyAssignments(returnedAssignments);
memberConfigs = memberConfigs(leader, offset, assignments);
// Add 2 tasks
configState = clusterConfigState(offset, 1, 42);
when(coordinator.configSnapshot()).thenReturn(configState);
// Add a worker
memberConfigs.put("worker3", new ExtendedWorkerState(leaderUrl, offset, null));
expectGeneration();
assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
++rebalanceNum;
returnedAssignments = assignmentsCapture.getValue();
assertDelay(0, returnedAssignments);
expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
assertNoReassignments(memberConfigs, expectedMemberConfigs);
applyAssignments(returnedAssignments);
memberConfigs = memberConfigs(leader, offset, assignments);
// Rebalance once more as a follow-up to task revocation
expectGeneration();
assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
++rebalanceNum;
returnedAssignments = assignmentsCapture.getValue();
assertDelay(0, returnedAssignments);
expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
assertNoReassignments(memberConfigs, expectedMemberConfigs);
applyAssignments(returnedAssignments);
memberConfigs = memberConfigs(leader, offset, assignments);
assertBalancedAssignments(memberConfigs);
verify(coordinator, times(rebalanceNum)).configSnapshot();
verify(coordinator, times(rebalanceNum)).leaderState(any());
verify(coordinator, times(2 * rebalanceNum)).generationId();
verify(coordinator, times(rebalanceNum)).memberId();
verify(coordinator, times(rebalanceNum)).lastCompletedGenerationId();
}
private void assertBalancedAssignments(Map<String, ExtendedWorkerState> existingAssignments) {
List<Integer> connectorCounts = existingAssignments.values().stream()
.map(e -> e.assignment().connectors().size())
.sorted()
.collect(Collectors.toList());
List<Integer> taskCounts = existingAssignments.values().stream()
.map(e -> e.assignment().tasks().size())
.sorted()
.collect(Collectors.toList());
int minConnectors = connectorCounts.get(0);
int maxConnectors = connectorCounts.get(connectorCounts.size() - 1);
int minTasks = taskCounts.get(0);
int maxTasks = taskCounts.get(taskCounts.size() - 1);
assertTrue(
"Assignments are imbalanced. The spread of connectors across each worker is: " + connectorCounts,
maxConnectors - minConnectors <= 1
);
assertTrue(
"Assignments are imbalanced. The spread of tasks across each worker is: " + taskCounts,
maxTasks - minTasks <= 1
);
}
```
##########
File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java
##########
@@ -180,6 +208,155 @@ public void testTaskAssignmentWhenWorkerJoins() {
verify(coordinator, times(rebalanceNum)).lastCompletedGenerationId();
}
+ @Test
+ public void testTaskAssignmentWhenWorkerJoinAfterRevocation() {
+ when(coordinator.configSnapshot()).thenReturn(configState);
+ doReturn(Collections.EMPTY_MAP).when(assignor).serializeAssignments(assignmentsCapture.capture());
+
+ // First assignment with 1 worker and 2 connectors configured but not yet assigned
+ //
+ // note: the assigned/revoked Connectors/tasks might be different, but the amount should be the same
+ // assignment after this phase:
+ // W1: assignedConnectors:[C0, C1], assignedTasks:[T0-0, T0-1, T0-2, T0-3, T1-0, T1-1, T1-2, T1-3],
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0, C1], tasks:[T0-0, T0-1, T0-2, T0-3, T1-0, T1-1, T1-2, T1-3]
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(2, 8, 0, 0, "worker1");
+
+ // Second assignment with a second worker joining and all connectors running on previous worker
+ //
+ // assignment after this phase:
+ // W1: assignedConnectors:[], assignedTasks:[],
+ // revokedConnectors:[C1], revokedTasks:[T1-0, T1-1, T1-2, T1-3]
+ // W2: assignedConnectors:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1, T0-2, T0-3]
+ // W2: connectors:[], tasks:[]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker2", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(0, 0, 1, 4, "worker1", "worker2");
+
+ // Third assignment after revocations, and a third worker joining
+ //
+ // assignment after this phase:
+ // W1: assignedTasks:[], assignedTasks:[],
+ // revokedConnectors:[], revokedTasks:[T0-3]
+ // W2: assignedTasks:[C1], assignedTasks:[T1-0, T1-1]
+ // revokedConnectors:[] revokedTasks:[]
+ // W3: assignedTasks:[], assignedTasks:[T1-2, T1-3]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1, T0-2]
+ // W2: connectors:[C1], tasks:[T1-0, T1-1]
+ // W3: connectors:[], tasks:[T1-2, T1-3]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker3", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(1, 4, 0, 1, "worker1", "worker2", "worker3");
Review comment:
This assertion style is useful for straightforward test cases but I wonder if we might want something more granular that allows us to assert how many C/T were assigned/revoked from individual workers (instead of across the entire cluster) for cases like this? Or, if that's difficult because of non-deterministic behavior caused by things like Java collections with undefined iteration order, could we at least have something that asserts how many workers should have a given total count of C/T in the cluster (e.g., "assert that 3 workers have 2 connectors assigned to them and 4 tasks, and that 1 worker has 1 connector assigned to it and 3 tasks") or how many workers were assigned/revoked a given number of C/T during the rebalance (e.g., "assert that 2 workers were assigned 2 tasks and revoked 3 tasks, and that 1 worker was assigned 0 tasks and revoked 4 tasks")?
The comments are useful for illustrating what the expectations are on that front, but they aren't testable and so there's no guarantee that they're actually correct. And in fact, after running this through a debugger, I was seeing the correct number of C/T being allocated/revoked during each round, but the actual C/T names (i.e., `T0-0` vs `T1-1`) were different from what's described in the comments.
##########
File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java
##########
@@ -180,6 +208,155 @@ public void testTaskAssignmentWhenWorkerJoins() {
verify(coordinator, times(rebalanceNum)).lastCompletedGenerationId();
}
+ @Test
+ public void testTaskAssignmentWhenWorkerJoinAfterRevocation() {
+ when(coordinator.configSnapshot()).thenReturn(configState);
+ doReturn(Collections.EMPTY_MAP).when(assignor).serializeAssignments(assignmentsCapture.capture());
+
+ // First assignment with 1 worker and 2 connectors configured but not yet assigned
+ //
+ // note: the assigned/revoked Connectors/tasks might be different, but the amount should be the same
+ // assignment after this phase:
+ // W1: assignedConnectors:[C0, C1], assignedTasks:[T0-0, T0-1, T0-2, T0-3, T1-0, T1-1, T1-2, T1-3],
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0, C1], tasks:[T0-0, T0-1, T0-2, T0-3, T1-0, T1-1, T1-2, T1-3]
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(2, 8, 0, 0, "worker1");
+
+ // Second assignment with a second worker joining and all connectors running on previous worker
+ //
+ // assignment after this phase:
+ // W1: assignedConnectors:[], assignedTasks:[],
+ // revokedConnectors:[C1], revokedTasks:[T1-0, T1-1, T1-2, T1-3]
+ // W2: assignedConnectors:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1, T0-2, T0-3]
+ // W2: connectors:[], tasks:[]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker2", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(0, 0, 1, 4, "worker1", "worker2");
+
+ // Third assignment after revocations, and a third worker joining
+ //
+ // assignment after this phase:
+ // W1: assignedTasks:[], assignedTasks:[],
+ // revokedConnectors:[], revokedTasks:[T0-3]
+ // W2: assignedTasks:[C1], assignedTasks:[T1-0, T1-1]
+ // revokedConnectors:[] revokedTasks:[]
+ // W3: assignedTasks:[], assignedTasks:[T1-2, T1-3]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1, T0-2]
+ // W2: connectors:[C1], tasks:[T1-0, T1-1]
+ // W3: connectors:[], tasks:[T1-2, T1-3]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker3", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(1, 4, 0, 1, "worker1", "worker2", "worker3");
+
+ // Forth assignment after revocations, and a forth worker joining
+ //
+ // assignment after this phase:
+ // W1: assignedTasks:[], assignedTasks:[],
+ // revokedConnectors:[], revokedTasks:[T0-2]
+ // W2: assignedTasks:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ // W3: assignedTasks:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ // W4: assignedTasks:[], assignedTasks:[T0-3]
+ // revokedConnectors:[] revokedTasks:[]
Review comment:
```suggestion
// W1: assignedConnectors:[], assignedTasks:[],
// revokedConnectors:[], revokedTasks:[T0-2]
// W2: assignedConnectors:[], assignedTasks:[]
// revokedConnectors:[] revokedTasks:[]
// W3: assignedConnectors:[], assignedTasks:[]
// revokedConnectors:[] revokedTasks:[]
// W4: assignedConnectors:[], assignedTasks:[T0-3]
// revokedConnectors:[] revokedTasks:[]
```
--
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 change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
C0urante commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r833730613
##########
File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java
##########
@@ -180,6 +208,155 @@ public void testTaskAssignmentWhenWorkerJoins() {
verify(coordinator, times(rebalanceNum)).lastCompletedGenerationId();
}
+ @Test
+ public void testTaskAssignmentWhenWorkerJoinAfterRevocation() {
+ when(coordinator.configSnapshot()).thenReturn(configState);
+ doReturn(Collections.EMPTY_MAP).when(assignor).serializeAssignments(assignmentsCapture.capture());
+
+ // First assignment with 1 worker and 2 connectors configured but not yet assigned
+ //
+ // note: the assigned/revoked Connectors/tasks might be different, but the amount should be the same
+ // assignment after this phase:
+ // W1: assignedConnectors:[C0, C1], assignedTasks:[T0-0, T0-1, T0-2, T0-3, T1-0, T1-1, T1-2, T1-3],
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0, C1], tasks:[T0-0, T0-1, T0-2, T0-3, T1-0, T1-1, T1-2, T1-3]
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(2, 8, 0, 0, "worker1");
+
+ // Second assignment with a second worker joining and all connectors running on previous worker
+ //
+ // assignment after this phase:
+ // W1: assignedConnectors:[], assignedTasks:[],
+ // revokedConnectors:[C1], revokedTasks:[T1-0, T1-1, T1-2, T1-3]
+ // W2: assignedConnectors:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1, T0-2, T0-3]
+ // W2: connectors:[], tasks:[]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker2", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(0, 0, 1, 4, "worker1", "worker2");
+
+ // Third assignment after revocations, and a third worker joining
+ //
+ // assignment after this phase:
+ // W1: assignedTasks:[], assignedTasks:[],
+ // revokedConnectors:[], revokedTasks:[T0-3]
+ // W2: assignedTasks:[C1], assignedTasks:[T1-0, T1-1]
+ // revokedConnectors:[] revokedTasks:[]
+ // W3: assignedTasks:[], assignedTasks:[T1-2, T1-3]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1, T0-2]
+ // W2: connectors:[C1], tasks:[T1-0, T1-1]
+ // W3: connectors:[], tasks:[T1-2, T1-3]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker3", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(1, 4, 0, 1, "worker1", "worker2", "worker3");
+
+ // Forth assignment after revocations, and a forth worker joining
+ //
+ // assignment after this phase:
+ // W1: assignedTasks:[], assignedTasks:[],
+ // revokedConnectors:[], revokedTasks:[T0-2]
+ // W2: assignedTasks:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ // W3: assignedTasks:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ // W4: assignedTasks:[], assignedTasks:[T0-3]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1]
+ // W2: connectors:[C1], tasks:[T1-0, T1-1]
+ // W3: connectors:[], tasks:[T1-2, T1-3]
+ // W4: connectors:[], tasks:[T0-3]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ memberConfigs.put("worker4", new ExtendedWorkerState(leaderUrl, offset, null));
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(0, 1, 0, 1, "worker1", "worker2", "worker3", "worker4");
+
+ // Fifth assignment after revocations
+ //
+ // assignment after this phase:
+ // W1: assignedTasks:[], assignedTasks:[],
+ // revokedConnectors:[], revokedTasks:[]
+ // W2: assignedTasks:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ // W3: assignedTasks:[], assignedTasks:[]
+ // revokedConnectors:[] revokedTasks:[]
+ // W4: assignedTasks:[], assignedTasks:[T0-2]
+ // revokedConnectors:[] revokedTasks:[]
+ //
+ // Final distribution after this phase:
+ // W1: connectors:[C0], tasks:[T0-0, T0-1]
+ // W2: connectors:[C1], tasks:[T1-0, T1-1]
+ // W3: connectors:[], tasks:[T1-2, T1-3]
+ // W4: connectors:[], tasks:[T0-3, T0-2]
+ applyAssignments(returnedAssignments);
+ memberConfigs = memberConfigs(leader, offset, assignments);
+ expectGeneration();
+ assignor.performTaskAssignment(leader, offset, memberConfigs, coordinator, protocolVersion);
+ ++rebalanceNum;
+ returnedAssignments = assignmentsCapture.getValue();
+ assertDelay(0, returnedAssignments);
+ expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
+ assertNoReassignments(memberConfigs, expectedMemberConfigs);
+ assertAssignment(0, 1, 0, 0, "worker1", "worker2", "worker3", "worker4");
Review comment:
Covered by [KAFKA-13763](https://issues.apache.org/jira/browse/KAFKA-13763).
--
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] showuon commented on pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#issuecomment-1080254334
@kkonstantine , sorry to keep pinging you, but we need your advice before we can continue. Thanks.
--
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] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598381699
##########
File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java
##########
@@ -532,23 +531,23 @@ private void resetDelay() {
* 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
+ * @param allConnectorsAndTasks all the connectors and tasks we need to distribute
+ * @param completeWorkerAssignmentWithoutDuplication current workers assignment without duplication
+ * @return the connectors/tasks that needed to be revoked on each worker, if no revoke is required, will return empty map
*/
- 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()
+ private Map<String, ConnectorsAndTasks> performTaskRevocation(ConnectorsAndTasks allConnectorsAndTasks,
+ Collection<WorkerLoad> completeWorkerAssignmentWithoutDuplication) {
+ int totalConnectorsNum = allConnectorsAndTasks.connectors().size();
+ int totalTasksNum = allConnectorsAndTasks.tasks().size();
+ Collection<WorkerLoad> existingWorkers = completeWorkerAssignmentWithoutDuplication.stream()
Review comment:
Use `allConnectorsAndTasks` (`configured`) to compute the total connectors/tasks number, and use the `completeWorkerAssignmentWithoutDuplication` to compute the existing workers. So it'll always compute the correct expected connector/task number for each worker
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598077882
##########
File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignor.java
##########
@@ -60,8 +60,6 @@
private final Time time;
private final int maxDelay;
private ConnectorsAndTasks previousAssignment;
- private ConnectorsAndTasks previousRevocation;
- private boolean canRevoke;
Review comment:
change (1): remove unused `previousRevocation` and `canRevoke`
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on a change in pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#discussion_r598081851
##########
File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java
##########
@@ -1133,20 +1219,9 @@ public void testTaskAssignmentWhenTasksDuplicatedInWorkerAssignment() {
assertDelay(0, returnedAssignments);
expectedMemberConfigs = memberConfigs(leader, offset, returnedAssignments);
assertNoReassignments(memberConfigs, expectedMemberConfigs);
- assertAssignment(1, 4, 0, 2, "worker1", "worker2");
Review comment:
This revocation is unnecessary because we revoked the connecor1 and all of the tasks in connector1 in previous round, so when entering this round, the assignment is:
W1: connectors: [connector2], tasks: [T2-0, T2-1, T2-2, T2-3]
W2: connectors: [], tasks: []
We can just assign the connector1 and 4 of his tasks into W2, and complete the rebalance.
However, before my change, in `performTasksRevocation` method, we use `activeAssignment` as the total tasks, so, we'll get the avg umber of tasks each worker can have = 4 (total active tasks) / 2 (total worker) = 2, then revoke 2 tasks, and then assign to 2 workers in next round.
After my change, the avg umber of tasks each worker can have will be: 8 (total tasks) / 2 (total workers) = 4, so no tasks will be revoked.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] showuon commented on pull request #10367: KAFKA-12495: allow consecutive revoke in incremental cooperative assignor in connector
Posted by GitBox <gi...@apache.org>.
showuon commented on pull request #10367:
URL: https://github.com/apache/kafka/pull/10367#issuecomment-844641158
@kkonstantine , could you please check this PR when available? Thank you.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org