rdkafka 0.28.0 → 0.29.1

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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -0
  3. data/README.md +3 -2
  4. data/bin/verify_kafka_warnings +5 -0
  5. data/dist/{librdkafka-2.14.1.tar.gz → librdkafka-2.14.2.tar.gz} +0 -0
  6. data/docker-compose-ssl.yml +4 -1
  7. data/docker-compose.yml +4 -1
  8. data/lib/rdkafka/abstract_handle.rb +31 -2
  9. data/lib/rdkafka/admin/config_binding_result.rb +2 -2
  10. data/lib/rdkafka/admin/create_acl_handle.rb +6 -5
  11. data/lib/rdkafka/admin/create_acl_report.rb +2 -1
  12. data/lib/rdkafka/admin/create_partitions_handle.rb +4 -6
  13. data/lib/rdkafka/admin/create_topic_handle.rb +4 -6
  14. data/lib/rdkafka/admin/delete_acl_handle.rb +5 -7
  15. data/lib/rdkafka/admin/delete_groups_handle.rb +4 -6
  16. data/lib/rdkafka/admin/delete_records_handle.rb +31 -0
  17. data/lib/rdkafka/admin/delete_records_report.rb +25 -0
  18. data/lib/rdkafka/admin/delete_topic_handle.rb +4 -6
  19. data/lib/rdkafka/admin/describe_acl_handle.rb +5 -7
  20. data/lib/rdkafka/admin/describe_acl_report.rb +2 -1
  21. data/lib/rdkafka/admin/describe_configs_handle.rb +4 -10
  22. data/lib/rdkafka/admin/describe_configs_report.rb +1 -5
  23. data/lib/rdkafka/admin/incremental_alter_configs_handle.rb +4 -10
  24. data/lib/rdkafka/admin/incremental_alter_configs_report.rb +1 -5
  25. data/lib/rdkafka/admin/list_consumer_groups_handle.rb +31 -0
  26. data/lib/rdkafka/admin/list_consumer_groups_report.rb +83 -0
  27. data/lib/rdkafka/admin/list_offsets_handle.rb +5 -10
  28. data/lib/rdkafka/admin/list_offsets_report.rb +5 -2
  29. data/lib/rdkafka/admin.rb +238 -145
  30. data/lib/rdkafka/bindings.rb +61 -16
  31. data/lib/rdkafka/callbacks/base_handler.rb +62 -0
  32. data/lib/rdkafka/callbacks/create_acl_handler.rb +37 -0
  33. data/lib/rdkafka/callbacks/create_partitions_handler.rb +37 -0
  34. data/lib/rdkafka/callbacks/create_topic_handler.rb +37 -0
  35. data/lib/rdkafka/callbacks/delete_acl_handler.rb +42 -0
  36. data/lib/rdkafka/callbacks/delete_groups_handler.rb +37 -0
  37. data/lib/rdkafka/callbacks/delete_records_handler.rb +38 -0
  38. data/lib/rdkafka/callbacks/delete_topic_handler.rb +37 -0
  39. data/lib/rdkafka/callbacks/describe_acl_handler.rb +35 -0
  40. data/lib/rdkafka/callbacks/describe_configs_handler.rb +42 -0
  41. data/lib/rdkafka/callbacks/incremental_alter_configs_handler.rb +42 -0
  42. data/lib/rdkafka/callbacks/list_consumer_groups_handler.rb +39 -0
  43. data/lib/rdkafka/callbacks/list_offsets_handler.rb +42 -0
  44. data/lib/rdkafka/callbacks.rb +54 -246
  45. data/lib/rdkafka/config.rb +69 -50
  46. data/lib/rdkafka/consumer/headers.rb +19 -5
  47. data/lib/rdkafka/consumer/partition.rb +8 -1
  48. data/lib/rdkafka/consumer/topic_partition_list.rb +58 -30
  49. data/lib/rdkafka/consumer.rb +211 -52
  50. data/lib/rdkafka/defaults.rb +24 -7
  51. data/lib/rdkafka/helpers/list_offsets.rb +127 -0
  52. data/lib/rdkafka/helpers/metadata.rb +29 -0
  53. data/lib/rdkafka/helpers/oauth.rb +10 -5
  54. data/lib/rdkafka/metadata.rb +86 -19
  55. data/lib/rdkafka/native_kafka.rb +22 -11
  56. data/lib/rdkafka/producer/delivery_handle.rb +4 -5
  57. data/lib/rdkafka/producer/partitions_count_cache.rb +24 -38
  58. data/lib/rdkafka/producer.rb +81 -61
  59. data/lib/rdkafka/version.rb +3 -3
  60. data/lib/rdkafka.rb +19 -0
  61. data/package-lock.json +3 -3
  62. data/rdkafka.gemspec +1 -0
  63. metadata +22 -6
  64. data/Gemfile +0 -13
  65. data/Gemfile.lint +0 -14
  66. data/Gemfile.lint.lock +0 -123
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c811b180607c5cfb8ac4b81046d47f0f1a3cf86d00485ed924484993a2c2888
4
- data.tar.gz: 4b541fbec39c2cbdd14d419cfad1cc6af2f85c0d3b19d5a7dd7f8d52069b932d
3
+ metadata.gz: 9df14d82195673f4747cc9a5d20eeb705a547295b1fa25f6554a5f9fac415ff0
4
+ data.tar.gz: d98858ef1d0c6694acd2de1726e0727a17aae1694adf2d75ee9890bdf8608d57
5
5
  SHA512:
6
- metadata.gz: add2edda65ab8a0600faef30b0e25f4a80f8324c0809ee807baf6b90d0125d2ef404b99efaefd1c3bc8dcafb71b1fd86592e7d608657b7d1c3750b636f666c48
7
- data.tar.gz: f8c1def0cf19994dc964f388fd334ac932c30ae080d6f3c834c4f72b4dc4373f035337d9905f8c03b56c291dd24e6760167ac3107ad7d302e5512e163765c102
6
+ metadata.gz: 82715ad307088ce3559789b9445c968fb1dcbfa2e87ba70b8e90c786ff92066c37497b8592153e8512ed297706a8499d38e2c04754129390665478a3174bcf0e
7
+ data.tar.gz: 00fd0221b7afde5cf110437d3b83f7672b820b3ebc596d2ad7126c248f31bb89b35d29ced75c24da0a17af2828a2fc4f7feb4397cdcfe6d04bf78882f2ee02b6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,47 @@
1
1
  # Rdkafka Changelog
2
2
 
3
+ ## 0.29.1 (2026-09-04)
4
+ - [Enhancement] Add `Admin#delete_records` to delete all messages in a partition up to a given offset.
5
+ - [Enhancement] Add `Admin#list_consumer_groups` to list the cluster's consumer groups.
6
+ - [Enhancement] Name the failing topic and partition in the `RdkafkaError` raised for per-partition `list_offsets` errors.
7
+ - [Enhancement] Add `Consumer#list_offsets` to query partition offsets on an existing consumer handle without opening a dedicated admin connection.
8
+ - [Fix] Make `NativeKafka#close` fork-aware so a forked child no longer segfaults on exit.
9
+ - [Fix] Stabilize the `to_native_tpl` leak integration spec.
10
+ - [Fix] Stabilize the flaky partitions count cache statistics spec.
11
+
12
+ ## 0.29.0 (2026-07-10)
13
+ - [Enhancement] Bump librdkafka to `2.14.2`
14
+ - [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.
15
+ - [Enhancement] Support offset-commit metadata: `Consumer#store_offset(message, metadata)` stores an optional metadata string alongside the offset, `Consumer::Partition#metadata` exposes it, and `TopicPartitionList` marshals it to and from the native list (read back via `Consumer#committed`).
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] Extract the admin background-event result handlers into one class per operation under `lib/rdkafka/callbacks/`. Internal reorganization with no API or behavior change.
18
+ - [Enhancement] Reuse per-thread scratch pointers in `Consumer::Headers.from_native`, removing the per-message native allocations from the consumer hot path.
19
+ - [Enhancement] Remove the unused `DeliveryHandle` `:topic_name` struct field and its per-message allocation. Use `DeliveryHandle#topic` or `DeliveryReport#topic_name`, both unchanged.
20
+ - [Fix] Cache the partition count for a missing topic, so `produce` with a `partition_key` to a missing topic no longer re-runs a blocking metadata query on every message.
21
+ - [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.
22
+ - [Fix] Surface per-message build errors inline in `Consumer#poll_batch`/`#poll_batch_nb` instead of discarding the batch, preserving the messages that built successfully.
23
+ - [Fix] Bound the `Metadata` retry loop by a ~5s wall-clock budget with a floor of 3 attempts, cap the backoff at 1s, and stop overwriting the request timeout with the backoff value, which could block a synchronous fetch for minutes.
24
+ - [Fix] Synchronize `AbstractHandle::REGISTRY` mutations with a mutex, which could otherwise lose a write on JRuby and leave a handle unregistered or leaked.
25
+ - [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`.
26
+ - [Fix] Actually populate `ConfigBindingResult#synonyms`. The synonym loop built the synonym binding objects and discarded them, so `#synonyms` was always an empty array; they are now appended.
27
+ - [Fix] Stop leaking the native `rd_kafka_topic_conf_t` in `Producer#set_topic_config` when a per-topic config value is rejected.
28
+ - [Fix] Add the missing `closed_consumer_check` to `Consumer#position`, the only public consumer method without one; calling it on a closed consumer now raises a consistent `ClosedConsumerError` instead of failing deeper in the call.
29
+ - [Fix] Guard the OAuthBearer token refresh callback against a NULL client pointer before calling `rd_kafka_name` on it.
30
+ - [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`.
31
+ - [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`.
32
+ - [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`.
33
+ - [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.
34
+ - [Fix] Stop `Metadata` from leaking the native metadata struct on every retried fetch; each attempt now frees its own native resources.
35
+ - [Fix] Stop `Producer#produce` from orphaning the delivery handle in the process-global registry when it fails after registering it.
36
+ - [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.
37
+ - [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.
38
+ - [Fix] Destroy the native topic-partition list in `TopicPartitionList#to_native_tpl` when population fails partway (e.g. an invalid partition). The caller-owned list was leaked on any exception mid-build; it is now destroyed before the error propagates.
39
+ - [Fix] Raise instead of silently dropping a rejected `incremental_alter_configs` entry, which previously left the alter request reporting success.
40
+ - [Fix] Allocate the admin result-count out-parameter as `:size_t` instead of `:int32`, fixing a 4-byte overflow on every admin result parse.
41
+ - [Fix] Stabilize the flaky `Consumer#lag` "calculates the consumer lag" spec on overloaded CI.
42
+ - [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.
43
+ - [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.
44
+
3
45
  ## 0.28.0 (2026-06-03)
4
46
  - [Enhancement] Bump librdkafka to `2.14.1`
5
47
  - [Enhancement] Replace version-gated `Warning[:performance]` with dynamic `Warning.categories` opt-in in spec helper so new Ruby warning categories are automatically enabled without manual updates.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Rdkafka
2
2
 
3
- [![Build Status](https://github.com/karafka/rdkafka-ruby/actions/workflows/ci_linux_ubuntu_x86_64_gnu.yml/badge.svg)](https://github.com/karafka/rdkafka-ruby/actions/workflows/ci_linux_x86_64_gnu.yml)
3
+ [![Build Status](https://github.com/karafka/rdkafka-ruby/actions/workflows/ci_linux_ubuntu_x86_64_gnu.yml/badge.svg)](https://github.com/karafka/rdkafka-ruby/actions/workflows/ci_linux_ubuntu_x86_64_gnu.yml)
4
4
  [![Gem Version](https://badge.fury.io/rb/rdkafka.svg)](https://badge.fury.io/rb/rdkafka)
5
5
  [![Join the chat at https://slack.karafka.io](https://raw.githubusercontent.com/karafka/misc/master/slack.svg)](https://slack.karafka.io)
6
6
 
@@ -163,6 +163,7 @@ bundle exec rake produce_messages
163
163
 
164
164
  | rdkafka-ruby | librdkafka | patches |
165
165
  |-|-|-|
166
+ | 0.29.x (2026-07-10) | 2.14.2 (2026-06-03) | yes |
166
167
  | 0.28.x (2026-06-03) | 2.14.1 (2026-04-15) | yes |
167
168
  | 0.27.x (2026-05-07) | 2.14.0 (2026-04-01) | yes |
168
169
  | 0.26.x (2026-03-30) | 2.13.2 (2026-03-02) | yes |
@@ -173,7 +174,7 @@ bundle exec rake produce_messages
173
174
  | 0.21.x (2025-02-13) | 2.8.0 (2025-01-07) | yes |
174
175
  | 0.20.0 (2025-01-07) | 2.6.1 (2024-11-18) | yes |
175
176
  | 0.19.0 (2024-10-01) | 2.5.3 (2024-09-02) | yes |
176
- | 0.18.0 (2024-09-02) | 2.5.0 (2024-06-10) | yes |
177
+ | 0.18.0 (2024-09-02) | 2.5.0 (2024-07-10) | yes |
177
178
  | 0.17.0 (2024-08-03) | 2.4.0 (2024-05-07) | no |
178
179
  | 0.16.0 (2024-06-13) | 2.3.0 (2023-10-25) | no |
179
180
  | 0.15.0 (2023-12-03) | 2.3.0 (2023-10-25) | no |
@@ -4,6 +4,11 @@
4
4
  # Only specified warnings are allowed, all others should trigger failure
5
5
 
6
6
  allowed_patterns=(
7
+ # Enabling share groups (KIP-932) requires "share" in group.coordinator.rebalance.protocols
8
+ # on cp-kafka 8.3.0 (Kafka 4.x). That mechanism is deprecated in favour of the share.version
9
+ # feature flag (Kafka 5.0), but is still functionally required to enable share groups in this
10
+ # version, so the broker logs this deprecation warning on every startup. Expected here.
11
+ "group.coordinator.rebalance.protocols. is deprecated"
7
12
  "Performing controller activation"
8
13
  "registered with feature metadata.version"
9
14
  "Replayed TopicRecord for"
@@ -1,7 +1,7 @@
1
1
  services:
2
2
  kafka:
3
3
  container_name: kafka
4
- image: confluentinc/cp-kafka:8.2.1
4
+ image: confluentinc/cp-kafka:8.3.0
5
5
  ports:
6
6
  - 9092:9092 # Support PLAINTEXT so we can run one docker setup for SSL and PLAINTEXT
7
7
  - 9093:9093
@@ -22,6 +22,9 @@ services:
22
22
  KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false'
23
23
  KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
24
24
  KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
25
+ KAFKA_GROUP_COORDINATOR_REBALANCE_PROTOCOLS: 'classic,consumer,share'
26
+ KAFKA_SHARE_COORDINATOR_STATE_TOPIC_REPLICATION_FACTOR: 1
27
+ KAFKA_SHARE_COORDINATOR_STATE_TOPIC_MIN_ISR: 1
25
28
  KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "true"
26
29
  KAFKA_AUTHORIZER_CLASS_NAME: org.apache.kafka.metadata.authorizer.StandardAuthorizer
27
30
 
data/docker-compose.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  services:
2
2
  kafka:
3
3
  container_name: kafka
4
- image: confluentinc/cp-kafka:8.2.1
4
+ image: confluentinc/cp-kafka:8.3.0
5
5
 
6
6
  ports:
7
7
  - 9092:9092
@@ -21,5 +21,8 @@ services:
21
21
  KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false'
22
22
  KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
23
23
  KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
24
+ KAFKA_GROUP_COORDINATOR_REBALANCE_PROTOCOLS: 'classic,consumer,share'
25
+ KAFKA_SHARE_COORDINATOR_STATE_TOPIC_REPLICATION_FACTOR: 1
26
+ KAFKA_SHARE_COORDINATOR_STATE_TOPIC_MIN_ISR: 1
24
27
  KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "true"
25
28
  KAFKA_AUTHORIZER_CLASS_NAME: org.apache.kafka.metadata.authorizer.StandardAuthorizer
@@ -14,9 +14,16 @@ module Rdkafka
14
14
 
15
15
  # Registry for registering all the handles.
16
16
  REGISTRY = {}
17
+ # Guards REGISTRY mutations. The registry is shared across producing/consuming threads and the
18
+ # background polling thread (which removes handles from FFI callbacks), so the Hash must not be
19
+ # mutated concurrently. This is effectively safe on MRI under the GVL but not on JRuby, where a
20
+ # lost write could leave a handle unregistered (never unlocked -> `wait` times out for a
21
+ # delivered message) or never removed (permanent leak).
22
+ REGISTRY_MUTEX = Mutex.new
17
23
  # Default wait timeout is 31 years
18
24
  MAX_WAIT_TIMEOUT_FOREVER = 10_000_000_000
19
25
 
26
+ private_constant :REGISTRY_MUTEX
20
27
  private_constant :MAX_WAIT_TIMEOUT_FOREVER
21
28
 
22
29
  class << self
@@ -25,17 +32,28 @@ module Rdkafka
25
32
  # @param handle [AbstractHandle] any handle we want to register
26
33
  def register(handle)
27
34
  address = handle.to_ptr.address
28
- REGISTRY[address] = handle
35
+ REGISTRY_MUTEX.synchronize { REGISTRY[address] = handle }
29
36
  end
30
37
 
31
38
  # Removes handle from the register based on the handle address
32
39
  #
33
40
  # @param address [Integer] address of the registered handle we want to remove
34
41
  def remove(address)
35
- REGISTRY.delete(address)
42
+ REGISTRY_MUTEX.synchronize { REGISTRY.delete(address) }
36
43
  end
37
44
  end
38
45
 
46
+ # Operation result prepared by the background event callback. Background events are
47
+ # destroyed as soon as the callback returns, so anything the waiting thread needs has to be
48
+ # copied out of event-owned memory into Ruby objects and stored here before `#unlock` runs.
49
+ # When result parsing fails, holds the captured exception so it can be re-raised on the
50
+ # waiting thread.
51
+ attr_accessor :result
52
+
53
+ # Broker-provided error message copied out of event-owned memory by the background event
54
+ # callback, used by `#raise_error`.
55
+ attr_accessor :broker_message
56
+
39
57
  def initialize
40
58
  @mutex = Thread::Mutex.new
41
59
  @resource = Thread::ConditionVariable.new
@@ -122,6 +140,17 @@ module Rdkafka
122
140
  raise "Must be implemented by subclass!"
123
141
  end
124
142
 
143
+ # Returns the operation result prepared by the background event callback, re-raising an
144
+ # exception that was captured while the event memory was still readable.
145
+ #
146
+ # @return [Object] operation-specific result
147
+ # @raise [RdkafkaError] when result parsing in the event callback failed
148
+ def prepared_result
149
+ raise(result) if result.is_a?(Exception)
150
+
151
+ result
152
+ end
153
+
125
154
  # Allow subclasses to override
126
155
  def raise_error
127
156
  raise RdkafkaError.new(self[:response])
@@ -17,12 +17,12 @@ module Rdkafka
17
17
  @synonyms = []
18
18
 
19
19
  # The code below builds up the config synonyms using same config binding
20
- pointer_to_size_t = FFI::MemoryPointer.new(:int32)
20
+ pointer_to_size_t = FFI::MemoryPointer.new(:size_t)
21
21
  synonym_ptr = Bindings.rd_kafka_ConfigEntry_synonyms(config_ptr, pointer_to_size_t)
22
22
  synonyms_ptr = synonym_ptr.read_array_of_pointer(pointer_to_size_t.read_int)
23
23
 
24
24
  (1..pointer_to_size_t.read_int).map do |ar|
25
- self.class.new synonyms_ptr[ar - 1]
25
+ @synonyms << self.class.new(synonyms_ptr[ar - 1])
26
26
  end
27
27
  end
28
28
  end
@@ -5,17 +5,18 @@ module Rdkafka
5
5
  # Handle for create ACL operation
6
6
  class CreateAclHandle < AbstractHandle
7
7
  layout :pending, :bool,
8
- :response, :int,
9
- :response_string, :pointer
8
+ :response, :int
10
9
 
11
10
  # @return [String] the name of the operation
12
11
  def operation_name
13
12
  "create acl"
14
13
  end
15
14
 
16
- # @return [CreateAclReport] instance with rdkafka_response value as 0 and rdkafka_response_string value as empty string if the acl creation was successful
15
+ # @return [CreateAclReport] report prepared by the background event callback, with
16
+ # rdkafka_response value as 0 and rdkafka_response_string value as empty string if the
17
+ # acl creation was successful
17
18
  def create_result
18
- CreateAclReport.new(rdkafka_response: self[:response], rdkafka_response_string: self[:response_string])
19
+ prepared_result
19
20
  end
20
21
 
21
22
  # Raises an error if the operation failed
@@ -23,7 +24,7 @@ module Rdkafka
23
24
  def raise_error
24
25
  raise RdkafkaError.new(
25
26
  self[:response],
26
- broker_message: self[:response_string].read_string
27
+ broker_message: broker_message
27
28
  )
28
29
  end
29
30
  end
@@ -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 rdkafka_response
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
 
@@ -3,18 +3,16 @@ module Rdkafka
3
3
  # Handle for create partitions operation
4
4
  class CreatePartitionsHandle < AbstractHandle
5
5
  layout :pending, :bool,
6
- :response, :int,
7
- :error_string, :pointer,
8
- :result_name, :pointer
6
+ :response, :int
9
7
 
10
8
  # @return [String] the name of the operation
11
9
  def operation_name
12
10
  "create partitions"
13
11
  end
14
12
 
15
- # @return [Boolean] whether the create topic was successful
13
+ # @return [CreatePartitionsReport] report prepared by the background event callback
16
14
  def create_result
17
- CreatePartitionsReport.new(self[:error_string], self[:result_name])
15
+ prepared_result
18
16
  end
19
17
 
20
18
  # Raises an error if the operation failed
@@ -22,7 +20,7 @@ module Rdkafka
22
20
  def raise_error
23
21
  raise RdkafkaError.new(
24
22
  self[:response],
25
- broker_message: CreateTopicReport.new(self[:error_string], self[:result_name]).error_string
23
+ broker_message: broker_message
26
24
  )
27
25
  end
28
26
  end
@@ -5,18 +5,16 @@ module Rdkafka
5
5
  # Handle for create topic operation
6
6
  class CreateTopicHandle < AbstractHandle
7
7
  layout :pending, :bool,
8
- :response, :int,
9
- :error_string, :pointer,
10
- :result_name, :pointer
8
+ :response, :int
11
9
 
12
10
  # @return [String] the name of the operation
13
11
  def operation_name
14
12
  "create topic"
15
13
  end
16
14
 
17
- # @return [Boolean] whether the create topic was successful
15
+ # @return [CreateTopicReport] report prepared by the background event callback
18
16
  def create_result
19
- CreateTopicReport.new(self[:error_string], self[:result_name])
17
+ prepared_result
20
18
  end
21
19
 
22
20
  # Raises an error if the operation failed
@@ -24,7 +22,7 @@ module Rdkafka
24
22
  def raise_error
25
23
  raise RdkafkaError.new(
26
24
  self[:response],
27
- broker_message: CreateTopicReport.new(self[:error_string], self[:result_name]).error_string
25
+ broker_message: broker_message
28
26
  )
29
27
  end
30
28
  end
@@ -5,19 +5,17 @@ module Rdkafka
5
5
  # Handle for delete ACL operation
6
6
  class DeleteAclHandle < AbstractHandle
7
7
  layout :pending, :bool,
8
- :response, :int,
9
- :response_string, :pointer,
10
- :matching_acls, :pointer,
11
- :matching_acls_count, :int
8
+ :response, :int
12
9
 
13
10
  # @return [String] the name of the operation
14
11
  def operation_name
15
12
  "delete acl"
16
13
  end
17
14
 
18
- # @return [DeleteAclReport] instance with an array of matching_acls
15
+ # @return [DeleteAclReport] report prepared by the background event callback, with an
16
+ # array of matching_acls
19
17
  def create_result
20
- DeleteAclReport.new(matching_acls: self[:matching_acls], matching_acls_count: self[:matching_acls_count])
18
+ prepared_result
21
19
  end
22
20
 
23
21
  # Raises an error if the operation failed
@@ -25,7 +23,7 @@ module Rdkafka
25
23
  def raise_error
26
24
  raise RdkafkaError.new(
27
25
  self[:response],
28
- broker_message: self[:response_string].read_string
26
+ broker_message: broker_message
29
27
  )
30
28
  end
31
29
  end
@@ -4,10 +4,8 @@ module Rdkafka
4
4
  class Admin
5
5
  # Handle for delete groups operation
6
6
  class DeleteGroupsHandle < AbstractHandle
7
- layout :pending, :bool, # TODO: ???
8
- :response, :int,
9
- :error_string, :pointer,
10
- :result_name, :pointer
7
+ layout :pending, :bool,
8
+ :response, :int
11
9
 
12
10
  # @return [String] the name of the operation
13
11
  def operation_name
@@ -17,7 +15,7 @@ module Rdkafka
17
15
  # Creates the result report
18
16
  # @return [DeleteGroupsReport]
19
17
  def create_result
20
- DeleteGroupsReport.new(self[:error_string], self[:result_name])
18
+ prepared_result
21
19
  end
22
20
 
23
21
  # Raises an error if the operation failed
@@ -25,7 +23,7 @@ module Rdkafka
25
23
  def raise_error
26
24
  raise RdkafkaError.new(
27
25
  self[:response],
28
- broker_message: create_result.error_string
26
+ broker_message: broker_message
29
27
  )
30
28
  end
31
29
  end
@@ -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
@@ -5,18 +5,16 @@ module Rdkafka
5
5
  # Handle for delete topic operation
6
6
  class DeleteTopicHandle < AbstractHandle
7
7
  layout :pending, :bool,
8
- :response, :int,
9
- :error_string, :pointer,
10
- :result_name, :pointer
8
+ :response, :int
11
9
 
12
10
  # @return [String] the name of the operation
13
11
  def operation_name
14
12
  "delete topic"
15
13
  end
16
14
 
17
- # @return [Boolean] whether the delete topic was successful
15
+ # @return [DeleteTopicReport] report prepared by the background event callback
18
16
  def create_result
19
- DeleteTopicReport.new(self[:error_string], self[:result_name])
17
+ prepared_result
20
18
  end
21
19
 
22
20
  # Raises an error if the operation failed
@@ -24,7 +22,7 @@ module Rdkafka
24
22
  def raise_error
25
23
  raise RdkafkaError.new(
26
24
  self[:response],
27
- broker_message: DeleteTopicReport.new(self[:error_string], self[:result_name]).error_string
25
+ broker_message: broker_message
28
26
  )
29
27
  end
30
28
  end
@@ -5,19 +5,17 @@ module Rdkafka
5
5
  # Handle for describe ACL operation
6
6
  class DescribeAclHandle < AbstractHandle
7
7
  layout :pending, :bool,
8
- :response, :int,
9
- :response_string, :pointer,
10
- :acls, :pointer,
11
- :acls_count, :int
8
+ :response, :int
12
9
 
13
10
  # @return [String] the name of the operation.
14
11
  def operation_name
15
12
  "describe acl"
16
13
  end
17
14
 
18
- # @return [DescribeAclReport] instance with an array of acls that matches the request filters.
15
+ # @return [DescribeAclReport] report prepared by the background event callback, with an
16
+ # array of acls that matches the request filters.
19
17
  def create_result
20
- DescribeAclReport.new(acls: self[:acls], acls_count: self[:acls_count])
18
+ prepared_result
21
19
  end
22
20
 
23
21
  # Raises an error if the operation failed
@@ -25,7 +23,7 @@ module Rdkafka
25
23
  def raise_error
26
24
  raise RdkafkaError.new(
27
25
  self[:response],
28
- broker_message: self[:response_string].read_string
26
+ broker_message: broker_message
29
27
  )
30
28
  end
31
29
  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 filters provided in the request.
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
 
@@ -5,22 +5,16 @@ module Rdkafka
5
5
  # Handle for describe configs operation
6
6
  class DescribeConfigsHandle < AbstractHandle
7
7
  layout :pending, :bool,
8
- :response, :int,
9
- :response_string, :pointer,
10
- :config_entries, :pointer,
11
- :entry_count, :int
8
+ :response, :int
12
9
 
13
10
  # @return [String] the name of the operation.
14
11
  def operation_name
15
12
  "describe configs"
16
13
  end
17
14
 
18
- # @return [DescribeAclReport] instance with an array of acls that matches the request filters.
15
+ # @return [DescribeConfigsReport] report prepared by the background event callback
19
16
  def create_result
20
- DescribeConfigsReport.new(
21
- config_entries: self[:config_entries],
22
- entry_count: self[:entry_count]
23
- )
17
+ prepared_result
24
18
  end
25
19
 
26
20
  # Raises an error if the operation failed
@@ -28,7 +22,7 @@ module Rdkafka
28
22
  def raise_error
29
23
  raise RdkafkaError.new(
30
24
  self[:response],
31
- broker_message: self[:response_string].read_string
25
+ broker_message: broker_message
32
26
  )
33
27
  end
34
28
  end
@@ -19,7 +19,7 @@ module Rdkafka
19
19
  .each do |config_resource_result_ptr|
20
20
  config_resource_result = ConfigResourceBindingResult.new(config_resource_result_ptr)
21
21
 
22
- pointer_to_size_t = FFI::MemoryPointer.new(:int32)
22
+ pointer_to_size_t = FFI::MemoryPointer.new(:size_t)
23
23
  configs_ptr = Bindings.rd_kafka_ConfigResource_configs(
24
24
  config_resource_result_ptr,
25
25
  pointer_to_size_t
@@ -32,10 +32,6 @@ module Rdkafka
32
32
 
33
33
  @resources << config_resource_result
34
34
  end
35
- ensure
36
- return if config_entries == FFI::Pointer::NULL
37
-
38
- Bindings.rd_kafka_ConfigResource_destroy_array(config_entries, entry_count)
39
35
  end
40
36
 
41
37
  private
@@ -5,22 +5,16 @@ module Rdkafka
5
5
  # Handle for incremental alter configs operation
6
6
  class IncrementalAlterConfigsHandle < AbstractHandle
7
7
  layout :pending, :bool,
8
- :response, :int,
9
- :response_string, :pointer,
10
- :config_entries, :pointer,
11
- :entry_count, :int
8
+ :response, :int
12
9
 
13
10
  # @return [String] the name of the operation.
14
11
  def operation_name
15
12
  "incremental alter configs"
16
13
  end
17
14
 
18
- # @return [DescribeAclReport] instance with an array of acls that matches the request filters.
15
+ # @return [IncrementalAlterConfigsReport] report prepared by the background event callback
19
16
  def create_result
20
- IncrementalAlterConfigsReport.new(
21
- config_entries: self[:config_entries],
22
- entry_count: self[:entry_count]
23
- )
17
+ prepared_result
24
18
  end
25
19
 
26
20
  # Raises an error if the operation failed
@@ -28,7 +22,7 @@ module Rdkafka
28
22
  def raise_error
29
23
  raise RdkafkaError.new(
30
24
  self[:response],
31
- broker_message: self[:response_string].read_string
25
+ broker_message: broker_message
32
26
  )
33
27
  end
34
28
  end
@@ -19,7 +19,7 @@ module Rdkafka
19
19
  .each do |config_resource_result_ptr|
20
20
  config_resource_result = ConfigResourceBindingResult.new(config_resource_result_ptr)
21
21
 
22
- pointer_to_size_t = FFI::MemoryPointer.new(:int32)
22
+ pointer_to_size_t = FFI::MemoryPointer.new(:size_t)
23
23
  configs_ptr = Bindings.rd_kafka_ConfigResource_configs(
24
24
  config_resource_result_ptr,
25
25
  pointer_to_size_t
@@ -32,10 +32,6 @@ module Rdkafka
32
32
 
33
33
  @resources << config_resource_result
34
34
  end
35
- ensure
36
- return if config_entries == FFI::Pointer::NULL
37
-
38
- Bindings.rd_kafka_ConfigResource_destroy_array(config_entries, entry_count)
39
35
  end
40
36
 
41
37
  private