Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

KIP-195 — CreatePartitions

Status: implemented — back to the KIP index.

What the KIP changes in Apache Kafka

Kafka 1.0 added AdminClient.createPartitions() and the CreatePartitions API (key 37): increase an existing topic's partition count (the request carries the new total, not a delta), optionally with manual replica assignments for the new partitions, plus a validateOnly mode. Shrinking is rejected.

How kaas implements it

The handler (crates/kaas-broker/src/handlers/create_partitions.rs, key 37, v0–v3, flexible from v2) doesn't touch storage at all. After authorizing Alter on the topic, it translates the request into a merge PATCH on KafkaTopic.spec.partitions via the installed TopicCRWriter (crates/kaas-broker/src/topic_cr_writer.rs). The operator reconciles the CR as usual — creating the new partition directories on the shared volume — and the broker observes them through its topic watcher. This is the gh #52 pattern: admin writes go through the CR so there is one materialization path, and the broker's RBAC carries update,patch on kafkatopics to allow it.

The writer runs a client-side shrink guard (read current spec.partitions, refuse a decrease with INVALID_PARTITIONS (37)) before patching; a missing CR maps to UNKNOWN_TOPIC_OR_PARTITION (3), RBAC denial to CLUSTER_AUTHORIZATION_FAILED (31). In dev mode (no kube client) every write answers 31 with an explanatory message.

Honest corners, all visible in the source:

  • assignments is decoded and ignored. kaas has no replicas (non-goals); partition placement belongs to the controller's balancer, not the caller.
  • timeout_ms is ignored. The handler returns success once the CR patch is accepted — before the operator has created the directories. Apache waits up to the timeout for the partitions to exist; with kaas a Metadata refresh moments later shows the new count.
  • validate_only validates less than upstream. It short-circuits after the authorization and writer checks but before the CR read, so it reports success even for a nonexistent topic or a would-be shrink.

How it's verified

  • crates/kaas-codec/src/api/create_partitions.rs round-trip tests: v0_roundtrip, v1_carries_error_message, v2_is_flexible, v3_roundtrip, validate_only_round_trips.
  • crates/kaas-broker/src/topic_cr_writer.rs: noop_writer_returns_forbidden pins the dev-mode error mapping.
  • scripts/kafka-topics.sh scenario 4 drives kafka-topics.sh --alter --partitions N against a live cluster and asserts the described partition count actually changes.

See also the CreatePartitions entry in the per-API reference.