-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Initial support for cooperative-sticky rebalancing #407
Merged
+170
−40
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c68f56f
feat: Initial support for cooperative-sticky rebalancing
untitaker 79a95f9
revert broken changes to pytest.ini
untitaker c5d7b52
apply review feedback
untitaker cd0cc07
Merge remote-tracking branch 'origin/main' into incremental-rebalancing
untitaker 6d43ebb
wip on supporting kip-848
untitaker c76ceae
skip empty assignments all the time
untitaker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -14,7 +14,10 @@ | |
|
||
from arroyo.backends.kafka import KafkaConsumer, KafkaPayload, KafkaProducer | ||
from arroyo.backends.kafka.commit import CommitCodec | ||
from arroyo.backends.kafka.configuration import build_kafka_configuration | ||
from arroyo.backends.kafka.configuration import ( | ||
KafkaBrokerConfig, | ||
build_kafka_configuration, | ||
) | ||
from arroyo.backends.kafka.consumer import as_kafka_configuration_bool | ||
from arroyo.commit import IMMEDIATE, Commit | ||
from arroyo.errors import ConsumerError, EndOfPartition | ||
|
@@ -56,6 +59,7 @@ def get_topic( | |
configuration: Mapping[str, Any], partitions_count: int | ||
) -> Iterator[Topic]: | ||
name = f"test-{uuid.uuid1().hex}" | ||
configuration = dict(configuration) | ||
client = AdminClient(configuration) | ||
[[key, future]] = client.create_topics( | ||
[NewTopic(name, num_partitions=partitions_count, replication_factor=1)] | ||
|
@@ -71,10 +75,15 @@ def get_topic( | |
|
||
|
||
class TestKafkaStreams(StreamsTestMixin[KafkaPayload]): | ||
kip_848 = False | ||
|
||
configuration = build_kafka_configuration( | ||
{"bootstrap.servers": os.environ.get("DEFAULT_BROKERS", "localhost:9092")} | ||
) | ||
@property | ||
def configuration(self) -> KafkaBrokerConfig: | ||
config = { | ||
"bootstrap.servers": os.environ.get("DEFAULT_BROKERS", "localhost:9092"), | ||
} | ||
|
||
return build_kafka_configuration(config) | ||
|
||
@contextlib.contextmanager | ||
def get_topic(self, partitions: int = 1) -> Iterator[Topic]: | ||
|
@@ -90,7 +99,7 @@ def get_consumer( | |
enable_end_of_partition: bool = True, | ||
auto_offset_reset: str = "earliest", | ||
strict_offset_reset: Optional[bool] = None, | ||
max_poll_interval_ms: Optional[int] = None | ||
max_poll_interval_ms: Optional[int] = None, | ||
) -> KafkaConsumer: | ||
configuration = { | ||
**self.configuration, | ||
|
@@ -110,6 +119,16 @@ def get_consumer( | |
if max_poll_interval_ms < 45000: | ||
configuration["session.timeout.ms"] = max_poll_interval_ms | ||
|
||
if self.cooperative_sticky: | ||
configuration["partition.assignment.strategy"] = "cooperative-sticky" | ||
|
||
if self.kip_848: | ||
configuration["group.protocol"] = "consumer" | ||
configuration.pop("session.timeout.ms") | ||
configuration.pop("max.poll.interval.ms", None) | ||
assert "group.protocol.type" not in configuration | ||
assert "heartbeat.interval.ms" not in configuration | ||
|
||
return KafkaConsumer(configuration) | ||
|
||
def get_producer(self) -> KafkaProducer: | ||
|
@@ -210,7 +229,9 @@ def test_consumer_polls_when_paused(self) -> None: | |
poll_interval = 6000 | ||
|
||
with self.get_topic() as topic: | ||
with closing(self.get_producer()) as producer, closing(self.get_consumer(max_poll_interval_ms=poll_interval)) as consumer: | ||
with closing(self.get_producer()) as producer, closing( | ||
self.get_consumer(max_poll_interval_ms=poll_interval) | ||
) as consumer: | ||
producer.produce(topic, next(self.get_payloads())).result(5.0) | ||
|
||
processor = StreamProcessor(consumer, topic, factory, IMMEDIATE) | ||
|
@@ -245,6 +266,16 @@ def test_consumer_polls_when_paused(self) -> None: | |
assert consumer.paused() == [] | ||
|
||
|
||
class TestKafkaStreamsIncrementalRebalancing(TestKafkaStreams): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, this actually re-declares all the tests in |
||
# re-test the kafka consumer with cooperative-sticky rebalancing | ||
cooperative_sticky = True | ||
|
||
|
||
@pytest.mark.skip("kip-848 not functional yet") | ||
class TestKafkaStreamsKip848(TestKafkaStreams): | ||
kip_848 = True | ||
|
||
|
||
def test_commit_codec() -> None: | ||
commit = Commit( | ||
"group", Partition(Topic("topic"), 0), 0, time.time(), time.time() - 5 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need a different logic for partition assignment between cooperative and standard in case of empty assignment?
I assume you can get an empty assignment in the cooperative rebalancing when, after a rebalancing, your assignments do not change. Is that the scenario where you do not want to touch the existing assignments ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after sleeping on it i agree. i only added this because it made cooperative rebalancing more comprehensible, and wasn't sure of the implications on regular rebalancing. i think we can skip empty assignments regardless of the assignment strategy.