Commit 71449aa
authored
KAFKA-20106: Ensure reconciled assignment updated within poll (#21495)
Fix to ensure that reconciled assignments are only updated in the
subscription state with a call to consumer.poll.
Before this PR, assignment changes occurred in the background thread
when async operations commit/callback completed : (1)commit → (2)revoke
callback → (3)assignment update → (4)assign callback), potentially
causing IllegalStateException when applications called seek/position on
consumer.assignment().
With this PR, we piggyback the assignment update on the existing
mechanism that triggers the onPartitionsAssigned callback (consolidate
steps 3 and 4 mentioned above, in a single one). Replace
CallbackNeededEvent with a new PartitionsAssignedEvent sent to the app
thread after every reconciliation. This event performs both assignment
update and onPartitionsAssigned callback (if needed).
This ensures assignment changes happen within poll() for all cases
(commit or not, callbacks or not).
The fix applies to the KafkaConsumer only. The ShareConsumer behaviour
remains unchanged with this PR (performs assignment update in the
background)
Reviewers: Lucas Brutschy <lbrutschy@confluent.io>, David Jacot
<djacot@confluent.io>1 parent 5af84cf commit 71449aa
File tree
12 files changed
+388
-85
lines changed- clients/src
- main/java/org/apache/kafka/clients/consumer/internals
- events
- test/java/org/apache/kafka/clients/consumer/internals
12 files changed
+388
-85
lines changedLines changed: 9 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
505 | 505 | | |
506 | 506 | | |
507 | 507 | | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | 508 | | |
523 | 509 | | |
524 | 510 | | |
| |||
1192 | 1178 | | |
1193 | 1179 | | |
1194 | 1180 | | |
1195 | | - | |
1196 | | - | |
1197 | | - | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
1198 | 1185 | | |
1199 | | - | |
1200 | | - | |
1201 | 1186 | | |
1202 | 1187 | | |
1203 | 1188 | | |
| |||
1230 | 1215 | | |
1231 | 1216 | | |
1232 | 1217 | | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
1233 | 1221 | | |
1234 | | - | |
1235 | | - | |
1236 | | - | |
| 1222 | + | |
| 1223 | + | |
1237 | 1224 | | |
1238 | 1225 | | |
1239 | 1226 | | |
| |||
Lines changed: 55 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | | - | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
143 | 145 | | |
144 | 146 | | |
145 | 147 | | |
| 148 | + | |
146 | 149 | | |
147 | 150 | | |
148 | 151 | | |
| |||
194 | 197 | | |
195 | 198 | | |
196 | 199 | | |
197 | | - | |
198 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
199 | 206 | | |
200 | 207 | | |
201 | 208 | | |
| |||
220 | 227 | | |
221 | 228 | | |
222 | 229 | | |
223 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
224 | 270 | | |
225 | 271 | | |
226 | | - | |
227 | | - | |
228 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
229 | 275 | | |
230 | 276 | | |
231 | 277 | | |
| |||
2252 | 2298 | | |
2253 | 2299 | | |
2254 | 2300 | | |
2255 | | - | |
| 2301 | + | |
2256 | 2302 | | |
2257 | | - | |
| 2303 | + | |
2258 | 2304 | | |
2259 | 2305 | | |
2260 | 2306 | | |
| |||
Lines changed: 47 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
51 | | - | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
137 | | - | |
| 138 | + | |
138 | 139 | | |
139 | 140 | | |
140 | 141 | | |
| |||
360 | 361 | | |
361 | 362 | | |
362 | 363 | | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | 364 | | |
375 | 365 | | |
376 | 366 | | |
| |||
386 | 376 | | |
387 | 377 | | |
388 | 378 | | |
389 | | - | |
390 | | - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
391 | 385 | | |
392 | 386 | | |
393 | 387 | | |
| |||
440 | 434 | | |
441 | 435 | | |
442 | 436 | | |
443 | | - | |
444 | | - | |
445 | | - | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
446 | 440 | | |
447 | 441 | | |
448 | 442 | | |
449 | 443 | | |
450 | 444 | | |
451 | 445 | | |
452 | | - | |
| 446 | + | |
453 | 447 | | |
454 | 448 | | |
455 | 449 | | |
| |||
458 | 452 | | |
459 | 453 | | |
460 | 454 | | |
461 | | - | |
| 455 | + | |
462 | 456 | | |
463 | 457 | | |
464 | 458 | | |
465 | 459 | | |
466 | 460 | | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
467 | 478 | | |
468 | 479 | | |
469 | 480 | | |
| |||
497 | 508 | | |
498 | 509 | | |
499 | 510 | | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
500 | 526 | | |
501 | 527 | | |
502 | 528 | | |
| |||
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
175 | 177 | | |
176 | 178 | | |
177 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
178 | 193 | | |
179 | 194 | | |
180 | 195 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
0 commit comments