karafka-rdkafka 0.28.0-aarch64-linux-gnu → 0.28.1-aarch64-linux-gnu
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +37 -30
- data/README.md +3 -3
- data/ext/librdkafka.so +0 -0
- data/lib/rdkafka/admin/create_acl_report.rb +2 -1
- data/lib/rdkafka/admin/delete_records_handle.rb +31 -0
- data/lib/rdkafka/admin/delete_records_report.rb +25 -0
- data/lib/rdkafka/admin/describe_acl_report.rb +2 -1
- data/lib/rdkafka/admin/list_consumer_groups_handle.rb +31 -0
- data/lib/rdkafka/admin/list_consumer_groups_report.rb +83 -0
- data/lib/rdkafka/admin.rb +177 -8
- data/lib/rdkafka/bindings.rb +51 -13
- data/lib/rdkafka/callbacks/delete_records_handler.rb +38 -0
- data/lib/rdkafka/callbacks/list_consumer_groups_handler.rb +39 -0
- data/lib/rdkafka/callbacks.rb +4 -2
- data/lib/rdkafka/config.rb +19 -17
- data/lib/rdkafka/consumer/topic_partition_list.rb +14 -9
- data/lib/rdkafka/consumer.rb +37 -36
- data/lib/rdkafka/defaults.rb +11 -2
- data/lib/rdkafka/error.rb +2 -1
- data/lib/rdkafka/helpers/oauth.rb +10 -5
- data/lib/rdkafka/native_kafka.rb +20 -7
- data/lib/rdkafka/producer/delivery_handle.rb +1 -2
- data/lib/rdkafka/producer/testing.rb +2 -1
- data/lib/rdkafka/producer.rb +28 -20
- data/lib/rdkafka/version.rb +1 -1
- data/lib/rdkafka.rb +6 -0
- metadata +8 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cb6dd6580bf5c14ddceaa2ccd38deaad34cf4e6e81e994c82df73e62fb831f77
|
|
4
|
+
data.tar.gz: c26f74ea68b3c14ace182f7f8b2da1184cceb59d6063b044a7efb3a84a022eef
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6b954711968c6acaa5beffa2995a33262bef8e2297b18eb3d9e828dd0be43818bfa5be73a7a20bfe13a8d19ee08ec4436e38e7b63a69948f3b85b7d06843d5db
|
|
7
|
+
data.tar.gz: f2003f4f608143b78dd9caab59a30d2fd96b5ed1a280ea9d1388cb4d5ff386d26655f2b0b3e15ec16b450b7df23118cfae1f1f99f229139e19243cd6bb7f3d5c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,43 +1,50 @@
|
|
|
1
1
|
# Rdkafka Changelog
|
|
2
2
|
|
|
3
|
-
## v0.28.
|
|
3
|
+
## v0.28.1 (2026-09-04)
|
|
4
|
+
- [Enhancement] Add `Admin#delete_records`, wrapping librdkafka's `DeleteRecords` admin API. Deletes all messages in a partition up to (but not including) a given offset - accepts an integer offset or `:end` to clear all current data. Ported from rdkafka-ruby (#956).
|
|
5
|
+
- [Enhancement] Add `Admin#list_consumer_groups`, wrapping librdkafka's `ListConsumerGroups` admin API. Returns a cluster-wide listing of consumer groups (`group_id`, `is_simple_consumer_group`, state) plus any per-broker errors. Ported from rdkafka-ruby (#955).
|
|
6
|
+
- [Fix] Make `NativeKafka#close` fork-aware so a forked child no longer segfaults on exit. Handles record their creator pid and skip the native teardown in any other process.
|
|
7
|
+
- [Fix] Stabilize the flaky partitions count cache statistics spec.
|
|
8
|
+
- [Fix] Stabilize the `to_native_tpl` leak integration spec against RSS measurement noise.
|
|
9
|
+
|
|
10
|
+
## v0.28.0 (2026-07-12)
|
|
4
11
|
- [Enhancement] Bump librdkafka to `2.14.2`. Maintenance release: fixes duplicate groups in `ListConsumerGroups` when multiple brokers return the same group, a data race in timers, and bumps bundled OpenSSL/libcurl/zstd/zlib/cJSON dependencies (several CVEs).
|
|
5
12
|
- [Enhancement] Add `Consumer#metadata` and `Producer#metadata`, mirroring `Admin#metadata`, so cluster/topic metadata can be fetched from an existing consumer or producer handle without opening a dedicated admin connection.
|
|
6
13
|
- [Enhancement] Name the failing partition and topic in the `RdkafkaError` raised for per-partition `list_offsets` errors (previously a bare error code), preserving the per-partition context the pre-batching `Consumer#lag` watermark errors carried.
|
|
7
|
-
- [Enhancement] Add `Consumer#list_offsets`, mirroring `Admin#list_offsets`, so
|
|
8
|
-
- [Enhancement] Extract the admin background-event result handlers into one class per operation under `lib/rdkafka/callbacks
|
|
9
|
-
- [Enhancement] Expose `replicas` and `isrs` (in-sync replica broker ids) on each partition in topic metadata
|
|
10
|
-
- [Enhancement] Reuse per-thread scratch pointers in `Consumer::Headers.from_native
|
|
11
|
-
- [Enhancement] Remove the unused `DeliveryHandle` `:topic_name` struct field and
|
|
12
|
-
- [Fix] Stop `poll_batch`/`poll_batch_nb` from discarding a whole batch when one message fails to build.
|
|
13
|
-
- [Fix] Add the missing `closed_consumer_check` to `Consumer#position
|
|
14
|
-
- [Fix] Stop leaking the native `rd_kafka_topic_conf_t` in `Producer#set_topic_config` when a per-topic config value is rejected.
|
|
15
|
-
- [Fix] Raise instead of silently dropping a rejected `incremental_alter_configs` entry
|
|
16
|
-
- [Fix] Let `PartitionsCountCache` adopt a lower partition count once the cached entry has expired
|
|
17
|
-
- [Fix] Make the `Consumer` GC finalizer close the consumer and destroy its consumer queue, not just the native client
|
|
18
|
-
- [Fix] Stop
|
|
19
|
-
- [Fix] Destroy the native topic-partition list in `TopicPartitionList#to_native_tpl` when population fails partway
|
|
20
|
-
- [Fix] Allocate the admin result-count out-parameter as `:size_t` instead of `:int32
|
|
21
|
-
- [Fix] Destroy admin API background events after processing
|
|
22
|
-
- [Fix] Resolve admin operation handles from the event error when an
|
|
23
|
-
- [Fix] Stop leaking the native `rd_kafka_conf_t` when client creation fails
|
|
24
|
-
- [Fix] Stop `Metadata` from leaking the native metadata struct
|
|
25
|
-
- [Fix] Free the librdkafka-allocated string in `Consumer#cluster_id` and `Consumer#member_id
|
|
26
|
-
- [Fix] Guard the message delivery callback so a raising user `delivery_callback` can no longer
|
|
27
|
-
- [Fix] Stop `Producer#produce` from orphaning the delivery handle in the process-global registry when it fails after registering it.
|
|
28
|
-
- [Fix] Attach `rd_kafka_query_watermark_offsets` with `blocking: true` so it releases the GVL
|
|
29
|
-
- [Fix] Stabilize the flaky `Consumer#lag`
|
|
30
|
-
- [Fix] Fix the NULL background-queue cleanup branches in `Admin#delete_group`, `Admin#delete_acl` and `Admin#describe_acl`, which
|
|
31
|
-
- [Fix] Forward `broker_message` and `instance_name` through `RdkafkaError.build
|
|
32
|
-
- [Fix] Synchronize `AbstractHandle::REGISTRY` mutations
|
|
33
|
-
- [Fix] Stop the `Metadata` retry loop from clobbering the request timeout and blocking for minutes.
|
|
34
|
-
- [Fix] Cache the partition count for a missing topic so `produce` with a `partition_key` to a not-yet-created topic no longer runs a blocking metadata query on every message.
|
|
14
|
+
- [Enhancement] Add `Consumer#list_offsets`, mirroring `Admin#list_offsets`, so offsets can be queried on an existing consumer handle without a dedicated admin connection, and rebuild `Consumer#lag` on top of it as one batched query instead of a roundtrip per partition.
|
|
15
|
+
- [Enhancement] Extract the admin background-event result handlers into one class per operation under `lib/rdkafka/callbacks/`. Internal reorganization with no API or behavior change.
|
|
16
|
+
- [Enhancement] Expose `replicas` and `isrs` (in-sync replica broker ids) on each partition in topic metadata; both were previously dropped from the `Metadata#topics` partition hashes.
|
|
17
|
+
- [Enhancement] Reuse per-thread scratch pointers in `Consumer::Headers.from_native`, removing the per-message native allocations from the consumer hot path.
|
|
18
|
+
- [Enhancement] Remove the unused `DeliveryHandle` `:topic_name` struct field and its per-message allocation. Use `DeliveryHandle#topic` or `DeliveryReport#topic_name`, both unchanged.
|
|
19
|
+
- [Fix] Stop `poll_batch`/`poll_batch_nb` from discarding a whole batch when one message fails to build. The failure is now surfaced inline as an `RdkafkaError` in the returned array, preserving the rest of the batch.
|
|
20
|
+
- [Fix] Add the missing `closed_consumer_check` to `Consumer#position`, so it raises a consistent `ClosedConsumerError` like every sibling offset method.
|
|
21
|
+
- [Fix] Stop leaking the native `rd_kafka_topic_conf_t` in `Producer#set_topic_config` when a per-topic config value is rejected.
|
|
22
|
+
- [Fix] Raise instead of silently dropping a rejected `incremental_alter_configs` entry, which previously left the alter request reporting success.
|
|
23
|
+
- [Fix] Let `PartitionsCountCache` adopt a lower partition count once the cached entry has expired, so a topic recreated with fewer partitions no longer fails `produce` until process restart.
|
|
24
|
+
- [Fix] Make the `Consumer` GC finalizer close the consumer and destroy its consumer queue, not just the native client, preventing a hang or leak when a consumer is collected without an explicit `close`.
|
|
25
|
+
- [Fix] Stop `describe_configs`, `incremental_alter_configs` and `list_offsets` from leaking handles and native resources when their arguments are rejected; all three now validate input before allocating.
|
|
26
|
+
- [Fix] Destroy the native topic-partition list in `TopicPartitionList#to_native_tpl` when population fails partway, which previously leaked the half-built list.
|
|
27
|
+
- [Fix] Allocate the admin result-count out-parameter as `:size_t` instead of `:int32`, fixing a 4-byte overflow on every admin result parse.
|
|
28
|
+
- [Fix] Destroy admin API background events after processing; they were never destroyed, so every admin operation leaked its whole result event. The internal FFI struct fields on admin handles were removed as part of this - use `handle.wait` and the returned report objects, whose interfaces are unchanged.
|
|
29
|
+
- [Fix] Resolve admin operation handles from the event error when an operation fails at the operation level (e.g. brokers unreachable), instead of blocking until `wait` timed out and discarding the real error.
|
|
30
|
+
- [Fix] Stop leaking the native `rd_kafka_conf_t` when client creation fails, a multi-KB leak per failed attempt for supervisors retrying on transient SASL/SSL misconfiguration.
|
|
31
|
+
- [Fix] Stop `Metadata` from leaking the native metadata struct on every retried fetch; each attempt now frees its own native resources.
|
|
32
|
+
- [Fix] Free the librdkafka-allocated string in `Consumer#cluster_id` and `Consumer#member_id`, and fix the `rd_kafka_clusterid` arity. `Consumer#cluster_id` now accepts a `timeout_ms`.
|
|
33
|
+
- [Fix] Guard the message delivery callback so a raising user `delivery_callback` can no longer leave the handle locked or crash the producer; exceptions are now logged and swallowed.
|
|
34
|
+
- [Fix] Stop `Producer#produce` from orphaning the delivery handle in the process-global registry when it fails after registering it.
|
|
35
|
+
- [Fix] Attach `rd_kafka_query_watermark_offsets` with `blocking: true` so it releases the GVL; it previously froze every other Ruby thread for up to `timeout_ms`.
|
|
36
|
+
- [Fix] Stabilize the flaky `Consumer#lag` spec on overloaded CI. Backported from rdkafka-ruby (#912).
|
|
37
|
+
- [Fix] Fix the NULL background-queue cleanup branches in `Admin#delete_group`, `Admin#delete_acl` and `Admin#describe_acl`, which raised a `NameError` and leaked the native request object instead of raising `ConfigError`.
|
|
38
|
+
- [Fix] Forward `broker_message` and `instance_name` through `RdkafkaError.build`; both were previously discarded on the `rd_kafka_error_t` pointer path.
|
|
39
|
+
- [Fix] Synchronize `AbstractHandle::REGISTRY` mutations with a mutex, which could otherwise lose a write on JRuby and leave a handle unregistered or leaked.
|
|
40
|
+
- [Fix] Stop the `Metadata` retry loop from clobbering the request timeout and blocking for minutes. The request timeout is left unchanged across retries, the backoff is capped, and the loop is bounded by a ~5s wall-clock budget after a floor of 3 attempts.
|
|
41
|
+
- [Fix] Cache the partition count for a missing topic, so `produce` with a `partition_key` to a not-yet-created topic no longer runs a blocking metadata query on every message.
|
|
35
42
|
|
|
36
43
|
## 0.27.2 (2026-05-21)
|
|
37
44
|
- [Enhancement] `poll_batch` and `poll_batch_nb` now return error events inline as `RdkafkaError` objects rather than raising on the first error. The return type is `Array<Message, RdkafkaError>` and callers are responsible for handling errors in the result.
|
|
38
45
|
|
|
39
46
|
## 0.27.1 (2026-05-14)
|
|
40
|
-
- [Fix] `poll_nb`, `poll_nb_each`, `poll_batch
|
|
47
|
+
- [Fix] `poll_nb`, `poll_nb_each`, `poll_batch` and `poll_batch_nb` now raise `RdkafkaError` with `details` populated (`{topic:, partition:, offset:}`) when a message contains an error, consistent with `poll`.
|
|
41
48
|
|
|
42
49
|
## 0.27.0 (2026-05-08)
|
|
43
50
|
- [Feature] Add `Consumer#poll_batch(timeout_ms, max_items:)` and `Consumer#poll_batch_nb(timeout_ms, max_items:)` for batch message polling via `rd_kafka_consume_batch_queue` (from upstream).
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Karafka-Rdkafka
|
|
2
2
|
|
|
3
|
-
[](https://github.com/karafka/karafka-rdkafka/actions/workflows/
|
|
3
|
+
[](https://github.com/karafka/karafka-rdkafka/actions/workflows/ci_linux_ubuntu_x86_64_gnu.yml)
|
|
4
4
|
[](https://badge.fury.io/rb/karafka-rdkafka)
|
|
5
5
|
[](https://slack.karafka.io)
|
|
6
6
|
|
|
@@ -61,14 +61,14 @@ Contributions should generally be made to the upstream [rdkafka-ruby repository]
|
|
|
61
61
|
|
|
62
62
|
## Versions
|
|
63
63
|
|
|
64
|
-
| rdkafka
|
|
64
|
+
| karafka-rdkafka | librdkafka | patches |
|
|
65
65
|
|-|-|-|
|
|
66
66
|
| 0.28.x (2026-07-12) | 2.14.2 (2026-06-03) | yes |
|
|
67
67
|
| 0.27.x (2026-05-08) | 2.14.1 (2026-04-15) | yes |
|
|
68
68
|
| 0.26.x (2026-04-11) | 2.14.0 (2026-04-01) | yes |
|
|
69
69
|
| 0.25.x (2026-04-02) | 2.13.2 (2026-03-02) | yes |
|
|
70
70
|
| 0.24.x (2026-02-25) | 2.13.0 (2026-01-05) | yes |
|
|
71
|
-
| 0.23.x (2025-11-01) | 2.12.1 (2025-10-
|
|
71
|
+
| 0.23.x (2025-11-01) | 2.12.1 (2025-10-21) | yes |
|
|
72
72
|
| 0.22.x (2025-09-26) | 2.11.1 (2025-08-18) | yes |
|
|
73
73
|
| 0.21.x (2025-08-18) | 2.11.0 (2025-07-03) | yes |
|
|
74
74
|
| 0.20.x (2025-07-17) | 2.8.0 (2025-01-07) | yes |
|
data/ext/librdkafka.so
CHANGED
|
Binary file
|
|
@@ -4,7 +4,8 @@ module Rdkafka
|
|
|
4
4
|
class Admin
|
|
5
5
|
# Report for create ACL operation result
|
|
6
6
|
class CreateAclReport
|
|
7
|
-
# Upon successful creation of Acl RD_KAFKA_RESP_ERR_NO_ERROR - 0 is returned as
|
|
7
|
+
# Upon successful creation of Acl RD_KAFKA_RESP_ERR_NO_ERROR - 0 is returned as
|
|
8
|
+
# rdkafka_response
|
|
8
9
|
# @return [Integer]
|
|
9
10
|
attr_reader :rdkafka_response
|
|
10
11
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Handle for delete records operation
|
|
6
|
+
class DeleteRecordsHandle < AbstractHandle
|
|
7
|
+
layout :pending, :bool,
|
|
8
|
+
:response, :int
|
|
9
|
+
|
|
10
|
+
# @return [String] the name of the operation
|
|
11
|
+
def operation_name
|
|
12
|
+
"delete records"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @return [DeleteRecordsReport] report prepared by the background event callback, with the
|
|
16
|
+
# post-deletion low-watermark offsets (or per-partition errors)
|
|
17
|
+
def create_result
|
|
18
|
+
prepared_result
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Raises an error if the operation failed
|
|
22
|
+
# @raise [RdkafkaError]
|
|
23
|
+
def raise_error
|
|
24
|
+
raise RdkafkaError.new(
|
|
25
|
+
self[:response],
|
|
26
|
+
broker_message: broker_message
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Report for delete records operation result
|
|
6
|
+
class DeleteRecordsReport
|
|
7
|
+
# Per-partition results. Each partition's `offset` is the post-deletion low-watermark (the
|
|
8
|
+
# smallest available offset of all live replicas) and its `err` carries the per-partition
|
|
9
|
+
# error code, if deletion failed for that partition.
|
|
10
|
+
# @return [Rdkafka::Consumer::TopicPartitionList]
|
|
11
|
+
attr_reader :offsets
|
|
12
|
+
|
|
13
|
+
# @param result_ptr [FFI::Pointer] pointer to the `rd_kafka_DeleteRecords_result_t`
|
|
14
|
+
def initialize(result_ptr)
|
|
15
|
+
@offsets = Rdkafka::Consumer::TopicPartitionList.new
|
|
16
|
+
|
|
17
|
+
return if result_ptr.null?
|
|
18
|
+
|
|
19
|
+
native_tpl = Bindings.rd_kafka_DeleteRecords_result_offsets(result_ptr)
|
|
20
|
+
|
|
21
|
+
@offsets = Rdkafka::Consumer::TopicPartitionList.from_native_tpl(native_tpl)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -4,7 +4,8 @@ module Rdkafka
|
|
|
4
4
|
class Admin
|
|
5
5
|
# Report for describe ACL operation result
|
|
6
6
|
class DescribeAclReport
|
|
7
|
-
# acls that exists in the cluster for the resource_type, resource_name and pattern_type
|
|
7
|
+
# acls that exists in the cluster for the resource_type, resource_name and pattern_type
|
|
8
|
+
# filters provided in the request.
|
|
8
9
|
# @return [Rdkafka::Bindings::AclBindingResult] array of matching acls.
|
|
9
10
|
attr_reader :acls
|
|
10
11
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Handle for list consumer groups operation
|
|
6
|
+
class ListConsumerGroupsHandle < AbstractHandle
|
|
7
|
+
layout :pending, :bool,
|
|
8
|
+
:response, :int
|
|
9
|
+
|
|
10
|
+
# @return [String] the name of the operation
|
|
11
|
+
def operation_name
|
|
12
|
+
"list consumer groups"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @return [ListConsumerGroupsReport] report prepared by the background event callback, with
|
|
16
|
+
# the listed consumer groups.
|
|
17
|
+
def create_result
|
|
18
|
+
prepared_result
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Raises an error if the operation failed
|
|
22
|
+
# @raise [RdkafkaError]
|
|
23
|
+
def raise_error
|
|
24
|
+
raise RdkafkaError.new(
|
|
25
|
+
self[:response],
|
|
26
|
+
broker_message: broker_message
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Report for list consumer groups operation result
|
|
6
|
+
class ListConsumerGroupsReport
|
|
7
|
+
# Consumer groups listed cluster-wide. Each entry is a hash with:
|
|
8
|
+
# - `:group_id` [String] the consumer group id
|
|
9
|
+
# - `:is_simple_consumer_group` [Boolean] `true` for a "simple" consumer group - one that
|
|
10
|
+
# assigns partitions manually (via `assign`) and uses Kafka only for offset storage,
|
|
11
|
+
# rather than joining the group-management protocol and letting Kafka assign partitions
|
|
12
|
+
# and rebalance automatically (`subscribe`). Simple groups have no members from the
|
|
13
|
+
# broker's point of view, so they never rebalance.
|
|
14
|
+
# - `:state` [Integer] the group state as a `Bindings::RD_KAFKA_CONSUMER_GROUP_STATE_*`
|
|
15
|
+
# code, one of: `RD_KAFKA_CONSUMER_GROUP_STATE_UNKNOWN`,
|
|
16
|
+
# `RD_KAFKA_CONSUMER_GROUP_STATE_PREPARING_REBALANCE`,
|
|
17
|
+
# `RD_KAFKA_CONSUMER_GROUP_STATE_COMPLETING_REBALANCE`,
|
|
18
|
+
# `RD_KAFKA_CONSUMER_GROUP_STATE_STABLE`, `RD_KAFKA_CONSUMER_GROUP_STATE_DEAD`,
|
|
19
|
+
# `RD_KAFKA_CONSUMER_GROUP_STATE_EMPTY`
|
|
20
|
+
# - `:state_name` [String] human-readable name of that state (e.g. `"Stable"`, `"Empty"`)
|
|
21
|
+
# @return [Array<Hash>]
|
|
22
|
+
attr_reader :groups
|
|
23
|
+
|
|
24
|
+
# Per-broker errors reported alongside the (partial) group listing. `ListConsumerGroups`
|
|
25
|
+
# fans out to every broker and returns valid groups and errors separately, so a broker
|
|
26
|
+
# being unreachable does not discard the groups the reachable brokers returned.
|
|
27
|
+
# @return [Array<RdkafkaError>]
|
|
28
|
+
attr_reader :errors
|
|
29
|
+
|
|
30
|
+
# @param result_ptr [FFI::Pointer] pointer to the `rd_kafka_ListConsumerGroups_result_t`
|
|
31
|
+
def initialize(result_ptr)
|
|
32
|
+
@groups = []
|
|
33
|
+
@errors = []
|
|
34
|
+
|
|
35
|
+
return if result_ptr.null?
|
|
36
|
+
|
|
37
|
+
extract_groups(result_ptr)
|
|
38
|
+
extract_errors(result_ptr)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
# @param result_ptr [FFI::Pointer] pointer to the result
|
|
44
|
+
def extract_groups(result_ptr)
|
|
45
|
+
count_ptr = FFI::MemoryPointer.new(:size_t)
|
|
46
|
+
array_ptr = Bindings.rd_kafka_ListConsumerGroups_result_valid(result_ptr, count_ptr)
|
|
47
|
+
|
|
48
|
+
return if array_ptr.null?
|
|
49
|
+
|
|
50
|
+
array_ptr.read_array_of_pointer(count_ptr.read(:size_t)).each do |listing_ptr|
|
|
51
|
+
state = Bindings.rd_kafka_ConsumerGroupListing_state(listing_ptr)
|
|
52
|
+
group_id_ptr = Bindings.rd_kafka_ConsumerGroupListing_group_id(listing_ptr)
|
|
53
|
+
state_name_ptr = Bindings.rd_kafka_consumer_group_state_name(state)
|
|
54
|
+
|
|
55
|
+
@groups << {
|
|
56
|
+
group_id: group_id_ptr.null? ? nil : group_id_ptr.read_string,
|
|
57
|
+
is_simple_consumer_group:
|
|
58
|
+
Bindings.rd_kafka_ConsumerGroupListing_is_simple_consumer_group(listing_ptr) != 0,
|
|
59
|
+
state: state,
|
|
60
|
+
state_name: state_name_ptr.null? ? nil : state_name_ptr.read_string
|
|
61
|
+
}
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# @param result_ptr [FFI::Pointer] pointer to the result
|
|
66
|
+
def extract_errors(result_ptr)
|
|
67
|
+
count_ptr = FFI::MemoryPointer.new(:size_t)
|
|
68
|
+
array_ptr = Bindings.rd_kafka_ListConsumerGroups_result_errors(result_ptr, count_ptr)
|
|
69
|
+
|
|
70
|
+
return if array_ptr.null?
|
|
71
|
+
|
|
72
|
+
array_ptr.read_array_of_pointer(count_ptr.read(:size_t)).each do |error_ptr|
|
|
73
|
+
string_ptr = Bindings.rd_kafka_error_string(error_ptr)
|
|
74
|
+
|
|
75
|
+
@errors << RdkafkaError.new(
|
|
76
|
+
Bindings.rd_kafka_error_code(error_ptr),
|
|
77
|
+
broker_message: string_ptr.null? ? nil : string_ptr.read_string
|
|
78
|
+
)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
data/lib/rdkafka/admin.rb
CHANGED
|
@@ -108,10 +108,6 @@ module Rdkafka
|
|
|
108
108
|
# @return [nil]
|
|
109
109
|
# @raise [Rdkafka::ClosedAdminError] if called on a closed admin client
|
|
110
110
|
#
|
|
111
|
-
# @note This method holds the inner lock until the queue is empty or `:stop` is returned.
|
|
112
|
-
# Other admin operations will wait until this method returns.
|
|
113
|
-
# @note This method is thread-safe as it uses @native_kafka.with_inner synchronization
|
|
114
|
-
#
|
|
115
111
|
# @example Drain all pending events
|
|
116
112
|
# admin.events_poll_nb_each { |_count| }
|
|
117
113
|
#
|
|
@@ -120,6 +116,9 @@ module Rdkafka
|
|
|
120
116
|
# admin.events_poll_nb_each do |_count|
|
|
121
117
|
# :stop if monotonic_now >= deadline
|
|
122
118
|
# end
|
|
119
|
+
# @note This method holds the inner lock until the queue is empty or `:stop` is returned.
|
|
120
|
+
# Other admin operations will wait until this method returns.
|
|
121
|
+
# @note This method is thread-safe as it uses @native_kafka.with_inner synchronization
|
|
123
122
|
def events_poll_nb_each
|
|
124
123
|
closed_admin_check(__method__)
|
|
125
124
|
|
|
@@ -283,6 +282,172 @@ module Rdkafka
|
|
|
283
282
|
delete_groups_handle
|
|
284
283
|
end
|
|
285
284
|
|
|
285
|
+
# Deletes all messages in the given partitions up to (but not including) the given offset.
|
|
286
|
+
#
|
|
287
|
+
# The programmatic equivalent of `kafka-delete-records.sh`. Useful for GDPR/right-to-erasure
|
|
288
|
+
# compliance, clearing out poison messages, or retention cleanup outside of the configured
|
|
289
|
+
# time/size-based retention policy.
|
|
290
|
+
#
|
|
291
|
+
# @param topic_partition_offsets [Hash{String => Array<Hash>}] hash mapping topic names to
|
|
292
|
+
# arrays of partition delete specifications. Each specification is a hash with:
|
|
293
|
+
# - `:partition` [Integer] partition number
|
|
294
|
+
# - `:offset` [Symbol, Integer] delete all messages before this offset (exclusive) - an
|
|
295
|
+
# integer offset, or `:end` to delete all data currently in the partition
|
|
296
|
+
#
|
|
297
|
+
# @return [DeleteRecordsHandle] handle that can be used to wait for the result
|
|
298
|
+
# @raise [RdkafkaError] when deleting records fails
|
|
299
|
+
#
|
|
300
|
+
# @example Delete all messages before offset 100 in one partition, and all data in another
|
|
301
|
+
# report = admin.delete_records(
|
|
302
|
+
# "my_topic" => [
|
|
303
|
+
# { partition: 0, offset: 100 },
|
|
304
|
+
# { partition: 1, offset: :end }
|
|
305
|
+
# ]
|
|
306
|
+
# ).wait(max_wait_timeout_ms: 15_000)
|
|
307
|
+
#
|
|
308
|
+
# report.offsets.to_h
|
|
309
|
+
# # => { "my_topic" => [#<Partition @partition=0, @offset=100, @err=0>, ...] }
|
|
310
|
+
def delete_records(topic_partition_offsets)
|
|
311
|
+
closed_admin_check(__method__)
|
|
312
|
+
|
|
313
|
+
parsed = topic_partition_offsets.flat_map do |topic, partitions|
|
|
314
|
+
partitions.map do |spec|
|
|
315
|
+
offset = spec.fetch(:offset)
|
|
316
|
+
|
|
317
|
+
native_offset = case offset
|
|
318
|
+
when :end then Rdkafka::Bindings::RD_KAFKA_OFFSET_END
|
|
319
|
+
when Integer then offset
|
|
320
|
+
else
|
|
321
|
+
raise ArgumentError, "Unknown offset specification: #{offset.inspect}"
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
[topic, spec.fetch(:partition), native_offset]
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
tpl = Rdkafka::Bindings.rd_kafka_topic_partition_list_new(parsed.size)
|
|
329
|
+
|
|
330
|
+
parsed.each do |topic, partition, native_offset|
|
|
331
|
+
Rdkafka::Bindings.rd_kafka_topic_partition_list_add(tpl, topic, partition)
|
|
332
|
+
Rdkafka::Bindings.rd_kafka_topic_partition_list_set_offset(tpl, topic, partition, native_offset)
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
# rd_kafka_DeleteRecords_new copies the tpl it is given, so it does not need to (and must
|
|
336
|
+
# not) outlive this call - it is destroyed below, independently of the wrapping
|
|
337
|
+
# DeleteRecords_t object.
|
|
338
|
+
delete_records_ptr = Rdkafka::Bindings.rd_kafka_DeleteRecords_new(tpl)
|
|
339
|
+
Rdkafka::Bindings.rd_kafka_topic_partition_list_destroy(tpl)
|
|
340
|
+
|
|
341
|
+
pointer_array = [delete_records_ptr]
|
|
342
|
+
records_array_ptr = FFI::MemoryPointer.new(:pointer)
|
|
343
|
+
records_array_ptr.write_array_of_pointer(pointer_array)
|
|
344
|
+
|
|
345
|
+
# Get a pointer to the queue that our request will be enqueued on
|
|
346
|
+
queue_ptr = @native_kafka.with_inner do |inner|
|
|
347
|
+
Rdkafka::Bindings.rd_kafka_queue_get_background(inner)
|
|
348
|
+
end
|
|
349
|
+
if queue_ptr.null?
|
|
350
|
+
Rdkafka::Bindings.rd_kafka_DeleteRecords_destroy(delete_records_ptr)
|
|
351
|
+
raise Rdkafka::Config::ConfigError.new("rd_kafka_queue_get_background was NULL")
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
# Create and register the handle we will return to the caller
|
|
355
|
+
handle = DeleteRecordsHandle.new
|
|
356
|
+
handle[:pending] = true
|
|
357
|
+
handle[:response] = Rdkafka::Bindings::RD_KAFKA_PARTITION_UA
|
|
358
|
+
DeleteRecordsHandle.register(handle)
|
|
359
|
+
|
|
360
|
+
admin_options_ptr = @native_kafka.with_inner do |inner|
|
|
361
|
+
Rdkafka::Bindings.rd_kafka_AdminOptions_new(inner, Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_DELETERECORDS)
|
|
362
|
+
end
|
|
363
|
+
Rdkafka::Bindings.rd_kafka_AdminOptions_set_opaque(admin_options_ptr, handle.to_ptr)
|
|
364
|
+
|
|
365
|
+
begin
|
|
366
|
+
@native_kafka.with_inner do |inner|
|
|
367
|
+
Rdkafka::Bindings.rd_kafka_DeleteRecords(
|
|
368
|
+
inner,
|
|
369
|
+
records_array_ptr,
|
|
370
|
+
1,
|
|
371
|
+
admin_options_ptr,
|
|
372
|
+
queue_ptr
|
|
373
|
+
)
|
|
374
|
+
end
|
|
375
|
+
rescue Exception
|
|
376
|
+
DeleteRecordsHandle.remove(handle.to_ptr.address)
|
|
377
|
+
raise
|
|
378
|
+
ensure
|
|
379
|
+
Rdkafka::Bindings.rd_kafka_AdminOptions_destroy(admin_options_ptr)
|
|
380
|
+
Rdkafka::Bindings.rd_kafka_queue_destroy(queue_ptr)
|
|
381
|
+
Rdkafka::Bindings.rd_kafka_DeleteRecords_destroy(delete_records_ptr)
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
handle
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
# Lists consumer groups cluster-wide.
|
|
388
|
+
#
|
|
389
|
+
# librdkafka issues a single `ListConsumerGroups` request that is fanned out to every broker
|
|
390
|
+
# internally, so the result covers all consumer groups in the cluster, not only those
|
|
391
|
+
# coordinated by the connected broker.
|
|
392
|
+
#
|
|
393
|
+
# @return [ListConsumerGroupsHandle] handle that can be used to wait for the result
|
|
394
|
+
# @raise [RdkafkaError] when listing the consumer groups fails
|
|
395
|
+
#
|
|
396
|
+
# @example List every consumer group in the cluster and print its name and attributes
|
|
397
|
+
# report = admin.list_consumer_groups.wait(max_wait_timeout_ms: 15_000)
|
|
398
|
+
#
|
|
399
|
+
# report.groups.each do |group|
|
|
400
|
+
# puts "#{group[:group_id]} - #{group[:state_name]} " \
|
|
401
|
+
# "(simple: #{group[:is_simple_consumer_group]})"
|
|
402
|
+
# end
|
|
403
|
+
#
|
|
404
|
+
# # Any brokers that could not be reached are reported separately
|
|
405
|
+
# report.errors.each { |error| warn "partial listing error: #{error.message}" }
|
|
406
|
+
def list_consumer_groups
|
|
407
|
+
closed_admin_check(__method__)
|
|
408
|
+
|
|
409
|
+
# Get a pointer to the queue that our request will be enqueued on
|
|
410
|
+
queue_ptr = @native_kafka.with_inner do |inner|
|
|
411
|
+
Rdkafka::Bindings.rd_kafka_queue_get_background(inner)
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
if queue_ptr.null?
|
|
415
|
+
raise Rdkafka::Config::ConfigError.new("rd_kafka_queue_get_background was NULL")
|
|
416
|
+
end
|
|
417
|
+
|
|
418
|
+
# Create and register the handle we will return to the caller
|
|
419
|
+
handle = ListConsumerGroupsHandle.new
|
|
420
|
+
handle[:pending] = true
|
|
421
|
+
handle[:response] = Rdkafka::Bindings::RD_KAFKA_PARTITION_UA
|
|
422
|
+
ListConsumerGroupsHandle.register(handle)
|
|
423
|
+
|
|
424
|
+
admin_options_ptr = @native_kafka.with_inner do |inner|
|
|
425
|
+
Rdkafka::Bindings.rd_kafka_AdminOptions_new(
|
|
426
|
+
inner,
|
|
427
|
+
Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_LISTCONSUMERGROUPS
|
|
428
|
+
)
|
|
429
|
+
end
|
|
430
|
+
Rdkafka::Bindings.rd_kafka_AdminOptions_set_opaque(admin_options_ptr, handle.to_ptr)
|
|
431
|
+
|
|
432
|
+
begin
|
|
433
|
+
@native_kafka.with_inner do |inner|
|
|
434
|
+
Rdkafka::Bindings.rd_kafka_ListConsumerGroups(
|
|
435
|
+
inner,
|
|
436
|
+
admin_options_ptr,
|
|
437
|
+
queue_ptr
|
|
438
|
+
)
|
|
439
|
+
end
|
|
440
|
+
rescue Exception
|
|
441
|
+
ListConsumerGroupsHandle.remove(handle.to_ptr.address)
|
|
442
|
+
raise
|
|
443
|
+
ensure
|
|
444
|
+
Rdkafka::Bindings.rd_kafka_AdminOptions_destroy(admin_options_ptr)
|
|
445
|
+
Rdkafka::Bindings.rd_kafka_queue_destroy(queue_ptr)
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
handle
|
|
449
|
+
end
|
|
450
|
+
|
|
286
451
|
# Deletes the named topic
|
|
287
452
|
#
|
|
288
453
|
# @param topic_name [String] name of the topic to delete
|
|
@@ -345,7 +510,8 @@ module Rdkafka
|
|
|
345
510
|
#
|
|
346
511
|
# @param topic_name [String] name of the topic
|
|
347
512
|
# @param partition_count [Integer] how many partitions we want to end up with for given topic
|
|
348
|
-
# @return [CreatePartitionsHandle] Create partitions handle that can be used to wait for the
|
|
513
|
+
# @return [CreatePartitionsHandle] Create partitions handle that can be used to wait for the
|
|
514
|
+
# result
|
|
349
515
|
# @raise [ConfigError] When the partition count or replication factor are out of valid range
|
|
350
516
|
# @raise [RdkafkaError] When the topic name is invalid or the topic already exists
|
|
351
517
|
# @raise [RdkafkaError] When the topic configuration is invalid
|
|
@@ -434,7 +600,8 @@ module Rdkafka
|
|
|
434
600
|
# @param permission_type [Integer] rd_kafka_AclPermissionType_t value:
|
|
435
601
|
# - RD_KAFKA_ACL_PERMISSION_TYPE_DENY = 2
|
|
436
602
|
# - RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW = 3
|
|
437
|
-
# @return [CreateAclHandle] Create acl handle that can be used to wait for the result of
|
|
603
|
+
# @return [CreateAclHandle] Create acl handle that can be used to wait for the result of
|
|
604
|
+
# creating the acl
|
|
438
605
|
# @raise [RdkafkaError]
|
|
439
606
|
def create_acl(resource_type:, resource_name:, resource_pattern_type:, principal:, host:, operation:, permission_type:)
|
|
440
607
|
closed_admin_check(__method__)
|
|
@@ -535,7 +702,8 @@ module Rdkafka
|
|
|
535
702
|
# @param permission_type [Integer] rd_kafka_AclPermissionType_t value:
|
|
536
703
|
# - RD_KAFKA_ACL_PERMISSION_TYPE_DENY = 2
|
|
537
704
|
# - RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW = 3
|
|
538
|
-
# @return [DeleteAclHandle] Delete acl handle that can be used to wait for the result of
|
|
705
|
+
# @return [DeleteAclHandle] Delete acl handle that can be used to wait for the result of
|
|
706
|
+
# deleting the acl
|
|
539
707
|
# @raise [RdkafkaError]
|
|
540
708
|
def delete_acl(resource_type:, resource_name:, resource_pattern_type:, principal:, host:, operation:, permission_type:)
|
|
541
709
|
closed_admin_check(__method__)
|
|
@@ -638,7 +806,8 @@ module Rdkafka
|
|
|
638
806
|
# @param permission_type [Integer] rd_kafka_AclPermissionType_t value:
|
|
639
807
|
# - RD_KAFKA_ACL_PERMISSION_TYPE_DENY = 2
|
|
640
808
|
# - RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW = 3
|
|
641
|
-
# @return [DescribeAclHandle] Describe acl handle that can be used to wait for the result of
|
|
809
|
+
# @return [DescribeAclHandle] Describe acl handle that can be used to wait for the result of
|
|
810
|
+
# fetching acls
|
|
642
811
|
# @raise [RdkafkaError]
|
|
643
812
|
def describe_acl(resource_type:, resource_name:, resource_pattern_type:, principal:, host:, operation:, permission_type:)
|
|
644
813
|
closed_admin_check(__method__)
|