kafka
FastForwardPolicy ¶
FastForwardPolicy(grace_budgets=FAST_FORWARD_GRACE_BUDGETS, grace_floor=FAST_FORWARD_GRACE_FLOOR, clock=time.monotonic)
Decide when a live stream should give up on its backlog and skip ahead to current data.
Every stream has a latency budget: how old its data may grow and
still be useful (its channels' max_latency, plus a stride).
Older data is dropped as late anyway, so a consumer stuck further
behind real time than its budget is doing pure waste -- decoding
blocks nothing will use, with no way to catch up. Better to skip
to fresh data and take one bounded gap.
Feed each delivered block's age to :meth:observe. Once a
stream has stayed over budget for its whole grace period
(grace_budgets times its budget, at least grace_floor
seconds), it answers :attr:LagAction.FORWARD; the caller
performs the seek and reports it via :meth:forwarded. The
first observation with every stream back within budget answers
:attr:LagAction.RECOVERED, once, for logging. Lag is tracked
per stream, so a healthy stream cannot hide a stuck one.
Used by :class:KafkaReader for direct-Kafka clients, and by the
arrakis-server for the readers it pools for its own clients.
Source code in arrakis/kafka.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
forwarded ¶
forwarded()
Record that the consumer skipped ahead: every stream starts fresh, and the next fully within-budget observation reports recovery.
Source code in arrakis/kafka.py
118 119 120 121 122 123 | |
grace ¶
grace(budget_ns)
The grace period for the given latency budget, in seconds.
Source code in arrakis/kafka.py
98 99 100 | |
observe ¶
observe(stream_id, lag_ns, budget_ns)
Record one delivered block's age against its stream's budget.
Source code in arrakis/kafka.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
KafkaReader ¶
KafkaReader(url, metadata, start=None, *, fast_forward=False)
Bases: StreamReader
A connection object to read data from Kafka.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL of Kafka broker to connect to. |
required |
metadata
|
dict[str, Channel]]
|
Dictionary of channel metadata for request. |
required |
start
|
int | None
|
GPS start time of stream in nanoseconds, defaults to "now". |
None
|
fast_forward
|
bool
|
When True, a live stream that has fallen further behind real
time than its latency budget allows -- for long enough that it
clearly cannot catch up -- skips ahead to current data via
:meth: |
False
|
Source code in arrakis/kafka.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 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 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
enter ¶
enter()
Assign the consumer to the requested topics.
Partitions are assigned directly rather than subscribed via a consumer group: every reader is a single-member group with no committed offsets, so group membership buys nothing and costs the coordinator dependency (slow or failing joins starve the reader entirely) plus rebalance churn when any requested topic does not exist. Missing topics are excluded — their channels are served as gaps by the muxer — and re-checked periodically so data starts flowing if a topic appears.
Source code in arrakis/kafka.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
exhausted ¶
exhausted()
Whether everything currently in Kafka has been consumed.
True when every assigned partition's position has reached its high watermark. Topics missing from the broker are not assigned and therefore count as exhausted — they have nothing to consume. Watermarks are fetched from the broker at most every WATERMARK_REFRESH seconds; a False result may be spurious (stale watermark, broker hiccup), so callers should simply re-check later, while True is reliable for the data Kafka held at the last refresh.
Bounded readers use this as their terminal state: once the log is exhausted, data absent from the requested range is absent for good, and waiting for it will not end.
Source code in arrakis/kafka.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
fast_forward ¶
fast_forward(time_ns=None)
Skip the assigned partitions ahead, dropping the backlog.
Seeks the assigned partitions to the first message at or after
time_ns (GPS nanoseconds), or to the end of the partition
when time_ns is None or no message that recent exists yet.
A partition that has already consumed past its target stays
where it is. Messages between the current position and the
target are never delivered. Intended for a consumer that has
fallen behind real time further than it can catch up: reading
the backlog only produces data too old to serve.
Returns:
| Type | Description |
|---|---|
int
|
The number of partitions moved (0 when nothing is assigned). |
Source code in arrakis/kafka.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | |
generate_groupid ¶
generate_groupid()
Generate a random Kafka group ID.
Source code in arrakis/kafka.py
732 733 734 | |
random_alphanum ¶
random_alphanum(n)
Generate a random alpha-numeric sequence of N characters.
Source code in arrakis/kafka.py
737 738 739 740 | |