Skip to content
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

kafka_topics fails to increase partition count if topic list include both - topics to change and desired ones #107

Closed
mrandreyeff opened this issue Jul 19, 2021 · 0 comments · Fixed by #108
Labels
bug Something isn't working
Milestone

Comments

@mrandreyeff
Copy link

mrandreyeff commented Jul 19, 2021

Expected Behavior

Partition count changed, no error is thrown

Actual Behavior

Partition count changed, error is thrown:

Unable to initialize Kafka manager: KafkaManagerError: Error while updating topic 'topic_b' partitions. Error key is INVALID_PARTITIONS, Number of partitions is invalid.. Request was CreatePartitionsRequest_v0(topic_partitions=[(topic='topic_b', new_partitions=(count=<built-in method count of tuple object at 0x7fcc18234200>, assignment=[])), (topic='topic_a', new_partitions=(count=<built-in method count of tuple object at 0x7fcc180bdd40>, assignment=[[202, 203, 204]]))], timeout=15000, validate_only=False).

Tasks to Reproduce the Problem

  - name: "manage topics - init"
    kafka_topics:
      api_version: "2.6.0"
      topics:
        - name: topic_a
           partitions: 1
           replica_factor: 3
        - name: topic_b
           partitions: 1
           replica_factor: 3
      zookeeper: "localhost:2181"
      bootstrap_servers: "localhost:9092"

  - name: "manage topics - error"
    kafka_topics:
      api_version: "2.6.0"
      topics:
        - name: topic_a
           partitions: 2
           replica_factor: 3
        - name: topic_b
           partitions: 1
           replica_factor: 3
      zookeeper: "localhost:2181"
      bootstrap_servers: "localhost:9092"

Code with problem

            for _new_partition in range(partitions - old_partition):
                assignment = []
                for _replica in range(total_replica):
                    assignment.append(next(brokers_iterator))
                assignments.append(assignment)
            topics_assignments.append(
                (topic_name, (partitions, assignments))
            )

For the good topics (which do not require any change), the code adds record as well with empty assignments, e.g. from an example above:

(topic='topic_b', new_partitions=(count=<built-in method count of tuple object at 0x7fcc18234200>, assignment=[]

The proposed solution is to add an if partitions > old_partition: for that block.

@ryarnyah ryarnyah added the bug Something isn't working label Jul 19, 2021
@ryarnyah ryarnyah added this to the 0.13.2 milestone Jul 19, 2021
mrandreyeff pushed a commit to mrandreyeff/ansible-kafka-admin that referenced this issue Jul 20, 2021
ryarnyah added a commit that referenced this issue Jul 20, 2021
…on_increase

#107: fix kafka_topics partition increase
ryarnyah pushed a commit that referenced this issue Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants