-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Rebalancing fixes for kip-848 (#419)
Changes to support kip-848 - previously we were calling the wrong api if `group.protocol=consumer` was used. it should be consumer.assign() not consumer.incremental_assign() - retry if we get the new stale member epoch error on commit - adds tests - the TestKafkaStreamsKip848 are now unskipped except for test_pause_resume_rebalancing which still needs to be fixed - the kafka version running in CI is updated to support this
- Loading branch information
Showing
9 changed files
with
163 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
confluent-kafka>=2.3.0 | ||
confluent-kafka>=2.7.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
#!/bin/sh | ||
|
||
docker run \ | ||
--name sentry_zookeeper \ | ||
--name arroyo_kafka \ | ||
-d --network host \ | ||
-e ZOOKEEPER_CLIENT_PORT=2181 \ | ||
confluentinc/cp-zookeeper:6.2.0 | ||
|
||
docker run \ | ||
--name sentry_kafka \ | ||
-d --network host \ | ||
-e KAFKA_ZOOKEEPER_CONNECT=127.0.0.1:2181 \ | ||
-e KAFKA_LISTENERS=INTERNAL://0.0.0.0:9093,EXTERNAL://0.0.0.0:9092 \ | ||
-e KAFKA_ADVERTISED_LISTENERS=INTERNAL://127.0.0.1:9093,EXTERNAL://127.0.0.1:9092 \ | ||
-e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT \ | ||
-e KAFKA_INTER_BROKER_LISTENER_NAME=INTERNAL \ | ||
-e KAFKA_PROCESS_ROLES=broker,controller \ | ||
-e KAFKA_CONTROLLER_QUORUM_VOTERS=1@127.0.0.1:9093 \ | ||
-e KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER \ | ||
-e KAFKA_NODE_ID=1 \ | ||
-e CLUSTER_ID=MkU3OEVBNTcwNTJENDM2Qk \ | ||
-e KAFKA_LISTENERS=PLAINTEXT://127.0.0.1:9092,CONTROLLER://127.0.0.1:9093 \ | ||
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092 \ | ||
-e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT \ | ||
-e KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT \ | ||
-e KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 \ | ||
confluentinc/cp-kafka:6.2.0 | ||
-e KAFKA_GROUP_COORDINATOR_REBALANCE_PROTOCOLS=classic,consumer \ | ||
-e KAFKA_TRANSACTION_PARTITION_VERIFICATION_ENABLE=false \ | ||
confluentinc/cp-kafka:7.8.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
from typing import Any | ||
|
||
import time | ||
import contextlib | ||
from contextlib import closing | ||
import os | ||
import threading | ||
import logging | ||
from typing import Iterator, Mapping | ||
|
||
from confluent_kafka.admin import AdminClient, NewTopic | ||
from arroyo.types import Commit, Message, Partition, Topic | ||
from arroyo.backends.kafka.configuration import build_kafka_consumer_configuration | ||
from arroyo.backends.kafka.consumer import KafkaConsumer, KafkaPayload | ||
from arroyo.processing.strategies import RunTask, CommitOffsets, ProcessingStrategy | ||
from arroyo.processing.strategies.abstract import ProcessingStrategyFactory | ||
from arroyo.processing.processor import StreamProcessor | ||
from arroyo.backends.kafka import KafkaProducer | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
TOPIC = "test-kip848" | ||
|
||
|
||
@contextlib.contextmanager | ||
def get_topic( | ||
configuration: Mapping[str, Any], partitions_count: int | ||
) -> Iterator[Topic]: | ||
name = TOPIC | ||
configuration = dict(configuration) | ||
client = AdminClient(configuration) | ||
[[key, future]] = client.create_topics( | ||
[NewTopic(name, num_partitions=partitions_count, replication_factor=1)] | ||
).items() | ||
assert key == name | ||
assert future.result() is None | ||
try: | ||
yield Topic(name) | ||
finally: | ||
[[key, future]] = client.delete_topics([name]).items() | ||
assert key == name | ||
assert future.result() is None | ||
|
||
|
||
def test_kip848_e2e() -> None: | ||
counter = 0 | ||
|
||
def print_msg(message: Message[Any]) -> Message[Any]: | ||
nonlocal counter | ||
((partition, offset),) = message.committable.items() | ||
print(f"message: {partition.index}-{offset}") | ||
counter += 1 | ||
return message | ||
|
||
class Strat(RunTask[Any, Any]): | ||
def join(self, *args: Any, **kwargs: Any) -> None: | ||
print("joining strategy, sleeping 5 seconds") | ||
time.sleep(5) | ||
print("joining strategy, sleeping 5 seconds -- DONE") | ||
return super().join(*args, **kwargs) | ||
|
||
class Factory(ProcessingStrategyFactory[KafkaPayload]): | ||
def create_with_partitions( | ||
self, commit: Commit, partitions: Mapping[Partition, int] | ||
) -> ProcessingStrategy[KafkaPayload]: | ||
print("assign: ", [p.index for p in partitions]) | ||
return Strat(print_msg, CommitOffsets(commit)) | ||
|
||
default_config = { | ||
"bootstrap.servers": os.environ.get("DEFAULT_BROKERS", "localhost:9092") | ||
} | ||
|
||
with get_topic(default_config, 2) as topic: | ||
producer = KafkaProducer(default_config) | ||
|
||
with closing(producer): | ||
for i in range(30): | ||
message = KafkaPayload(None, i.to_bytes(1, "big"), []) | ||
producer.produce(topic, message).result() | ||
|
||
consumer_config = build_kafka_consumer_configuration( | ||
default_config, | ||
group_id="kip848", | ||
) | ||
|
||
consumer_config["group.protocol"] = "consumer" | ||
consumer_config.pop("session.timeout.ms", None) | ||
consumer_config.pop("max.poll.interval.ms", None) | ||
consumer_config.pop("partition.assignment.strategy", None) | ||
consumer_config.pop("group.protocol.type", None) | ||
consumer_config.pop("heartbeat.interval.ms", None) | ||
|
||
consumer = KafkaConsumer(consumer_config) | ||
|
||
processor = StreamProcessor( | ||
consumer=consumer, topic=Topic(TOPIC), processor_factory=Factory() | ||
) | ||
|
||
def shutdown() -> None: | ||
for i in range(100): | ||
time.sleep(0.1) | ||
if counter == 30: | ||
break | ||
print("shutting down") | ||
processor.signal_shutdown() | ||
|
||
t = threading.Thread(target=shutdown) | ||
t.start() | ||
|
||
processor.run() | ||
|
||
assert counter == 30 | ||
|
||
t.join() |