Commit 588af60
authored
Fix:
* Fix: make `KafkaConsumer.commitSync` non-blocking
Motivation:
Currently our invocation to `rd_kafka_commit` inside of
`KafkaCosumer.commitSync` is blocking a cooperative thread.
This PR aims to make `KafkaCosumer.commitSync` non-blocking by using the
callback-based commit API.
Modifications:
* move `commitSync` logic to `KafkaClient`
* replace the blocking invocation to
[rd_kafka_commit](https://docs.confluent.io/platform/current/clients/librdkafka/html/rdkafka_8h.html#ab96539928328f14c3c9177ea0c896c87)
with a callback-based invocation to
[rd_kafka_commit_queue](https://docs.confluent.io/platform/current/clients/librdkafka/html/rdkafka_8h.html#af76a6a73baa9c2621536e3f6882a3c1a)
which is then wrapped inside a `withAsyncThrowingContinuation` statement
* `KafkaClient.consumerClose`: make non-blocking
Motivation:
[rd_kakfa_consumer_close](https://docs.confluent.io/platform/current/clients/librdkafka/html/rdkafka_8h.html#a37b54d329e12d745889defe96e7d043d)
was blocking. This PR proposes using the
[rd_kakfa_consumer_close_queue](https://docs.confluent.io/platform/current/clients/librdkafka/html/rdkafka_8h.html#a9dd5c18bdfed81c8847b259f0a8d498d)
API which is non-blocking and served through the normal poll loop.
We now
Modifications:
* `KafkaClient.consumerClose`: use `rd_kakfa_consumer_close_queue` in
favour of `rd_kakfa_consumer_close`
* create a new variable `KafkaClient.isConsumerClosed` that indicates
if the poll loop needs to continue polling or if it can stop running
* updated state management in `KafkaConsumer` to accomodate for polling
when the `KafkaConsumer` is in the process of closing
Result:
Calling `KafkaClient.consumerClose` is not blocking anymore.
* Review Franz
Modifications:
* introduce new `KafkaConsumer.StateMachine.State` `.finishing` to avoid
retaining `client` in state `.finished`
* rename `KafkaConsumer.shutdownGracefully` to
`KafkaConsumer.triggerGracefulShutdown`
* add note that `KafkaConsumer.commitSync` does not support `Task`
cancellationKafkaClient.closeConsumer should not block (#73)1 parent 77d0b0e commit 588af60
File tree
3 files changed
+137
-58
lines changed- Sources/SwiftKafka
- RDKafka
3 files changed
+137
-58
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
122 | 204 | | |
123 | | - | |
124 | | - | |
125 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
126 | 210 | | |
127 | 211 | | |
128 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
129 | 217 | | |
130 | 218 | | |
131 | 219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
204 | | - | |
205 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
206 | 207 | | |
207 | | - | |
208 | | - | |
209 | 208 | | |
210 | 209 | | |
211 | 210 | | |
212 | 211 | | |
213 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
214 | 218 | | |
215 | 219 | | |
216 | 220 | | |
| |||
222 | 226 | | |
223 | 227 | | |
224 | 228 | | |
| 229 | + | |
225 | 230 | | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | 231 | | |
238 | 232 | | |
239 | 233 | | |
| |||
243 | 237 | | |
244 | 238 | | |
245 | 239 | | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
| 240 | + | |
269 | 241 | | |
270 | 242 | | |
271 | 243 | | |
272 | 244 | | |
273 | 245 | | |
274 | 246 | | |
275 | 247 | | |
276 | | - | |
| 248 | + | |
277 | 249 | | |
278 | 250 | | |
279 | | - | |
280 | | - | |
| 251 | + | |
| 252 | + | |
281 | 253 | | |
282 | 254 | | |
283 | 255 | | |
| |||
287 | 259 | | |
288 | 260 | | |
289 | 261 | | |
290 | | - | |
| 262 | + | |
291 | 263 | | |
292 | 264 | | |
293 | 265 | | |
| |||
336 | 308 | | |
337 | 309 | | |
338 | 310 | | |
339 | | - | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
340 | 317 | | |
341 | 318 | | |
342 | 319 | | |
| |||
368 | 345 | | |
369 | 346 | | |
370 | 347 | | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
371 | 353 | | |
372 | 354 | | |
373 | 355 | | |
| |||
376 | 358 | | |
377 | 359 | | |
378 | 360 | | |
379 | | - | |
| 361 | + | |
380 | 362 | | |
381 | 363 | | |
382 | 364 | | |
383 | 365 | | |
384 | 366 | | |
385 | 367 | | |
386 | 368 | | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
387 | 376 | | |
388 | 377 | | |
389 | 378 | | |
| |||
409 | 398 | | |
410 | 399 | | |
411 | 400 | | |
412 | | - | |
| 401 | + | |
413 | 402 | | |
414 | 403 | | |
415 | 404 | | |
| |||
438 | 427 | | |
439 | 428 | | |
440 | 429 | | |
441 | | - | |
| 430 | + | |
442 | 431 | | |
443 | 432 | | |
444 | 433 | | |
| |||
449 | 438 | | |
450 | 439 | | |
451 | 440 | | |
452 | | - | |
| 441 | + | |
453 | 442 | | |
454 | 443 | | |
455 | 444 | | |
| |||
466 | 455 | | |
467 | 456 | | |
468 | 457 | | |
469 | | - | |
470 | | - | |
| 458 | + | |
| 459 | + | |
471 | 460 | | |
472 | 461 | | |
473 | 462 | | |
474 | | - | |
| 463 | + | |
475 | 464 | | |
476 | 465 | | |
477 | 466 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
| |||
0 commit comments