Skip to content

7.x - Implement AdminClient with topic management operations#592

Open
aknEvrnky wants to merge 5 commits intoarnaud-lb:7.xfrom
aknEvrnky:7.x-admin-client
Open

7.x - Implement AdminClient with topic management operations#592
aknEvrnky wants to merge 5 commits intoarnaud-lb:7.xfrom
aknEvrnky:7.x-admin-client

Conversation

@aknEvrnky
Copy link
Copy Markdown

Summary

Adds a new RdKafka\Admin\AdminClient class that exposes librdkafka's admin API to PHP, covering the 5 most-requested topic management operations:

  • CreateTopics — create topics with partition count, replication factor, and optional config/replica assignment
  • DeleteTopics — delete topics by name
  • CreatePartitions — increase partition count for existing topics
  • DescribeTopics — get topic metadata including partition info, leader/ISR/replica nodes
  • DeleteRecords — delete records before a given offset per partition

New classes

Class Purpose
RdKafka\Admin\AdminClient Main entry point, wraps a producer-type rd_kafka_t handle
RdKafka\Admin\AdminOptions Per-operation options (timeouts, validate-only, broker ID)
RdKafka\Admin\NewTopic Input for createTopics()
RdKafka\Admin\DeleteTopic Input for deleteTopics()
RdKafka\Admin\NewPartitions Input for createPartitions()
RdKafka\Admin\TopicResult Result for create/delete operations
RdKafka\Admin\TopicDescription Result for describeTopics()
RdKafka\Admin\TopicPartitionInfo Partition detail within a TopicDescription
RdKafka\Admin\Node Broker node info (id, host, port, rack)

Design decisions

  • Synchronous PHP API wrapping librdkafka's async queue-based pattern internally — the extension creates a temporary queue, calls the operation, polls for the result, and returns it directly.
  • AdminOptions via factory method ($admin->newAdminOptions(RD_KAFKA_ADMIN_OP_*)) because the underlying C API requires the rd_kafka_t handle.
  • describeTopics() takes string[] instead of exposing a TopicCollection wrapper class — keeps the API simple while the collection is built internally.
  • deleteRecords() takes TopicPartition[] — reuses the existing RdKafka\TopicPartition class and internal helpers.
  • Follows all naming/design conventions from CONTRIBUTING.md.

Tests

  • 1 unit test (admin_client_001.phpt) — object creation and configuration without a broker
  • 4 integration tests against a running broker:
    • admin_client_create_delete_topics.phpt
    • admin_client_describe_topics.phpt
    • admin_client_create_partitions.phpt
    • admin_client_delete_records.phpt

Related issues

Addresses the topic management portion of:

Consumer group operations (#454) and remaining admin APIs can follow as separate PRs.

Necmi Akin Evrenkaya added 5 commits February 25, 2026 20:47
…itions

Add the foundation for librdkafka Admin API support (issue arnaud-lb#215).

New classes in RdKafka\Admin namespace:
- AdminClient: wraps rd_kafka_t handle, provides admin operations
- AdminOptions: configurable options (timeout, validate_only, broker)
- NewTopic: input for createTopics with config and replica assignment
- DeleteTopic: input for deleteTopics
- NewPartitions: input for createPartitions with replica assignment
- TopicResult: per-topic operation result with error and name

AdminOptions is created via AdminClient::newAdminOptions() factory
because rd_kafka_AdminOptions_new() requires a rd_kafka_t handle.

All operations are synchronous: internally creates a queue, calls the
librdkafka async operation, polls for the result, and returns it.
Complete the Topic Management category of the Admin API.

New methods on AdminClient:
- describeTopics(string[] $topics): returns TopicDescription[]
  with partition info, leader nodes, ISR, replicas, and topic UUID
- deleteRecords(TopicPartition[] $partitions): deletes records
  up to specified offsets, returns resulting offsets

New result classes in RdKafka\Admin namespace:
- Node: broker node with id, host, port, rack
- TopicPartitionInfo: partition details with leader, ISR, replicas
- TopicDescription: full topic info with partitions and error status

New AdminOptions setter:
- setIncludeAuthorizedOperations() for DescribeTopics

Node and TopicPartitionInfo are shared types that will be reused
by DescribeCluster and DescribeConsumerGroups in future phases.
Cover createTopics, deleteTopics, createPartitions, describeTopics, and deleteRecords with end-to-end tests against a running broker.
Add admin_client source files and test files to package.xml so they are included in PECL builds. Add config.w32 entry for Windows builds. Guard DescribeTopics APIs (Node, TopicDescription, TopicPartitionInfo, setIncludeAuthorizedOperations) with HAS_RD_KAFKA_DESCRIBE_TOPICS for librdkafka < 2.3.0 compatibility.
@emir
Copy link
Copy Markdown

emir commented Feb 26, 2026

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants