karafka-rdkafka 0.32.0-aarch64-linux-gnu → 0.32.2-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 +33 -11
- data/README.md +12 -5
- data/ext/librdkafka.so +0 -0
- data/lib/rdkafka/abstract_handle.rb +26 -11
- data/lib/rdkafka/admin/config_binding_result.rb +8 -0
- data/lib/rdkafka/admin.rb +1 -1
- data/lib/rdkafka/bindings/admin/configs.rb +11 -0
- data/lib/rdkafka/bindings/callbacks.rb +3 -3
- data/lib/rdkafka/config.rb +3 -3
- data/lib/rdkafka/consumer.rb +58 -17
- data/lib/rdkafka/defaults.rb +11 -4
- data/lib/rdkafka/helpers/message_build_error.rb +30 -0
- data/lib/rdkafka/native_kafka.rb +116 -35
- data/lib/rdkafka/producer/{partitions_count_cache.rb → partition_count_cache.rb} +64 -101
- data/lib/rdkafka/producer.rb +56 -11
- data/lib/rdkafka/share_consumer.rb +11 -4
- data/lib/rdkafka/version.rb +1 -1
- data/lib/rdkafka.rb +2 -1
- data/renovate.json +28 -5
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ebc8e92b144e296bfa31f5f416524f39dcf6d5a5e3fb14eac59872697d7a3814
|
|
4
|
+
data.tar.gz: f8a5da189f30beae958702d996fca54372814dd2736481cf1fa14af673194e04
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a679105fe7a0f6297067b88138b6119c1f46f653cf638d9eddd9c9cd29ce6301979b4da8d0a582a7fa5fc30ab5a1c7e0b1fc5df60a2ed9e51627aff617e3f954
|
|
7
|
+
data.tar.gz: edb43a9b7c302912623b623138ac8f1874ce3664b6804e00ebe8c443aaeb3f276bc4fd46695f9c27652f7da98cd5f8deeeb8f17e383bd7310fe83a5080f0f994
|
data/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
# Rdkafka Changelog
|
|
2
2
|
|
|
3
|
+
## 0.32.2 (2026-11-18)
|
|
4
|
+
- [Maintenance] Release the code of 0.32.1 again, with Sigstore attestations. 0.32.1 was published without them: signing failed in the release workflows (the signer does not work with json 3.x, the default of Ruby 4.0) and the attestation patch then pushed the gems unsigned. There are no code changes; use 0.32.2 rather than 0.32.1 for the attested gems.
|
|
5
|
+
- [Maintenance] Sign each gem with `sigstore-cli` and push it with `gem push --attestation` (`.github/release/push_gem.sh`, used by every push workflow), so a failed signing stops the release instead of publishing the gem without an attestation.
|
|
6
|
+
- [Maintenance] Add the `Sigstore Check` workflow: nightly, and on pull requests that change the release scripts or push workflows, it builds the gem, signs it like a release and verifies the attestation, without pushing.
|
|
7
|
+
|
|
8
|
+
## 0.32.1 (2026-11-18)
|
|
9
|
+
- [Change] Take the partition list of `Admin#list_consumer_group_offsets` as the `topic_partition_list:` keyword instead of a positional argument. Its only caller is karafka's admin API, which passes it as a keyword from karafka 2.6.2 (released karafka does not call it).
|
|
10
|
+
- [Change] Return one shared frozen empty array from `Consumer#poll_batch` and `#poll_batch_nb` when no messages arrive, so an empty poll allocates nothing. Code that mutates an empty result now raises `FrozenError`; no Karafka ecosystem gem calls these methods.
|
|
11
|
+
- **[Feature]** Add `#source` and `#source_name` to `describe_configs` config entries and their synonyms, telling a value set on the topic from one inherited from the broker or a built-in default. Ported from rdkafka-ruby (#1120).
|
|
12
|
+
- [Enhancement] Allocate fewer objects per handle: delivery and admin handles share a fixed set of locks instead of creating their own `Mutex` and `ConditionVariable`. Ported from rdkafka-ruby (#1087).
|
|
13
|
+
- [Enhancement] Bump the bundled zlib to `1.4`. Ported from rdkafka-ruby (#1109).
|
|
14
|
+
- [Enhancement] Bump the bundled MIT Kerberos (krb5) to `1.22.3` for security fixes. Ported from rdkafka-ruby (#1119).
|
|
15
|
+
- [Enhancement] Build the bundled zlib with `-O2` in the glibc precompiled gems for faster gzip compression and decompression. Ported from rdkafka-ruby (#1112).
|
|
16
|
+
- [Enhancement] Raise `Rdkafka::Producer::PartitionCountError` from `Producer#partition_count` and `partition_key` produces when the partition count cannot be fetched. It names the topic, keeps the `RdkafkaError` code and has the original error as `cause`.
|
|
17
|
+
- **[Deprecation]** Rename `Producer::PartitionsCountCache`, `Producer.partitions_count_cache` / `.partitions_count_cache=` and `Defaults::PARTITIONS_COUNT_CACHE_TTL_MS` / `PARTITIONS_COUNT_CACHE_STALE_BACKOFF_MS` to their `partition_count` forms. The old names still work but will be removed in v1.0.0. The old methods warn; the old constants are plain aliases and do not warn. Ported from rdkafka-ruby (#1102).
|
|
18
|
+
- [Fix] Keep `close` from hanging forever after a thread using the client was killed (JRuby) or interrupted by `Thread#raise` or `Timeout` (all Rubies). Ported from rdkafka-ruby (#1082).
|
|
19
|
+
- [Fix] Keep `close` from hanging forever after a signal `trap` handler raised while the main thread used the client. Ported from rdkafka-ruby (#1100).
|
|
20
|
+
- [Fix] Keep the shared partition count cache consistent when many threads produce with `partition_key` or call `partition_count` at once. On JRuby it lost topics and raised `NoMethodError`. Ported from rdkafka-ruby (#1078).
|
|
21
|
+
- [Fix] Return `nil` from every `close` call when several threads close one consumer, producer or admin at once, instead of raising `ClosedInnerError` in the later callers. Ported from rdkafka-ruby (#1107).
|
|
22
|
+
- [Fix] Give the error of a message that fails to build (e.g. unreadable headers) its `topic`, `partition` and `offset` in `details` in `Consumer#poll`, `#poll_nb`, `#poll_nb_each`, `#poll_batch` and `#poll_batch_nb`, so the caller can seek back to it instead of losing it.
|
|
23
|
+
- [Fix] Give the error of a message that fails to build its `topic`, `partition` and `offset` in `details` in `ShareConsumer#poll` too, so in explicit acknowledgement mode the caller can acknowledge (release or reject) that record.
|
|
24
|
+
|
|
3
25
|
## 0.32.0 (2026-11-04)
|
|
4
26
|
- **[Feature]** Add `Config#consumer_offset_commit_listener`: its `#on_offsets_committed(error, list)` gets the result of every offset commit when the consumer polls or closes, so an async commit that the broker rejects reaches Ruby instead of only a `COMMITFAIL` log line. Ported from rdkafka-ruby (#1061).
|
|
5
|
-
- **[Feature]** Let the offset commit listener define `#on_offsets_commit_failed(error, list)`, called only for failed commits (not on success or `no_offset`).
|
|
27
|
+
- **[Feature]** Let the offset commit listener define `#on_offsets_commit_failed(error, list)`, called only for failed commits (not on success or `no_offset`).
|
|
6
28
|
- **[Feature]** Add `Admin#list_consumer_group_offsets` to read the committed offsets of any consumer group without joining it, with a `require_stable_offsets` option.
|
|
7
29
|
- **[Feature]** Add `validate_only:`, `operation_timeout_ms:` and `request_timeout_ms:` keyword options to `Admin#create_topic` and `#create_partitions`, and the two timeouts to `#delete_topic`. A `create_topic` topic config passed without braces keeps working. Ported from rdkafka-ruby (#1092).
|
|
8
30
|
- [Enhancement] Reduce object shape variations of the admin report classes to one shape per class.
|
|
@@ -10,16 +32,16 @@
|
|
|
10
32
|
- [Enhancement] Add `Rdkafka::Config.partition_count_cache_ttl_ms=` to set how long `partition_key` produces reuse a cached partition count (default 30 seconds).
|
|
11
33
|
- [Enhancement] Make `Producer#produce` use about 13% less CPU per call. Ported from rdkafka-ruby (#1064).
|
|
12
34
|
- [Enhancement] Allocate fewer objects per delivered message: delivery callback reports reuse the topic String given to `produce`. Ported from rdkafka-ruby (#1066).
|
|
13
|
-
- [Change] Build the precompiled `x86_64-linux-gnu` and `aarch64-linux-gnu` libraries in an Ubuntu 22.04 container
|
|
35
|
+
- [Change] Build the precompiled `x86_64-linux-gnu` and `aarch64-linux-gnu` libraries in an Ubuntu 22.04 container to keep the glibc 2.34 floor. Ported from rdkafka-ruby (#1029).
|
|
14
36
|
- [Change] Depend on `mini_portile2` and `rake` only in the source gem, as only it compiles librdkafka. Apps that got `rake` only through this gem must add it to their Gemfile.
|
|
15
|
-
- [Change] Remove the unused `Rdkafka::Defaults::NATIVE_KAFKA_SYNCHRONIZE_SLEEP_INTERVAL_MS
|
|
37
|
+
- [Change] Remove the unused `Rdkafka::Defaults::NATIVE_KAFKA_SYNCHRONIZE_SLEEP_INTERVAL_MS`. Ported from rdkafka-ruby (#1055).
|
|
16
38
|
- [Maintenance] Fix a use-after-free in the `client_shutdown_dlclose` integration test that made it crash intermittently after its own unmap.
|
|
17
39
|
- [Maintenance] Stabilize the flaky `Consumer#seek` and `#seek_by` "works when a partition is paused" specs on loaded CI runners.
|
|
18
|
-
- [Maintenance] Stop the `client_shutdown_dlclose` integration test from failing with `Errno::ESRCH
|
|
19
|
-
- [Maintenance] Stabilize the flaky `Consumer` "long running consumption" spec
|
|
40
|
+
- [Maintenance] Stop the `client_shutdown_dlclose` integration test from failing with `Errno::ESRCH`.
|
|
41
|
+
- [Maintenance] Stabilize the flaky `Consumer` "long running consumption" spec.
|
|
20
42
|
- [Maintenance] Drop `pry` from the development bundle and stop requiring it in the spec helper.
|
|
21
|
-
- [Maintenance] Stabilize the flaky `admin_describe_topics` integration test
|
|
22
|
-
- [Maintenance] Name positional String topic parameters `topic_name
|
|
43
|
+
- [Maintenance] Stabilize the flaky `admin_describe_topics` integration test.
|
|
44
|
+
- [Maintenance] Name positional String topic parameters `topic_name`. Callers are not affected. Ported from rdkafka-ruby (#1052).
|
|
23
45
|
- [Maintenance] Name the positional String topic parameters of `Producer::PartitionsCountCache` `topic_name`. Callers are not affected.
|
|
24
46
|
- [Maintenance] Cover with integration tests that coordinator errors on group offset requests do not crash the admin client or a consumer without `group.id`. Ported from rdkafka-ruby (#1044).
|
|
25
47
|
- [Maintenance] Skip the bindings signature parity spec on JRuby, whose FFI does not expose function signatures. Ported from rdkafka-ruby (#1046).
|
|
@@ -27,13 +49,13 @@
|
|
|
27
49
|
- [Maintenance] Run the `client_shutdown_dlclose` integration test on JRuby on Linux. Ported from rdkafka-ruby (#1049).
|
|
28
50
|
- [Maintenance] Check the native call balance instead of RSS in the leak integration specs on JRuby. Ported from rdkafka-ruby (#1050).
|
|
29
51
|
- [Maintenance] Give the `Consumer#lag` spec a 30 s list offsets wait.
|
|
30
|
-
- [Maintenance] Give the share group offset reset in the `ShareConsumer` specs a 30 s wait and always close its admin
|
|
52
|
+
- [Maintenance] Give the share group offset reset in the `ShareConsumer` specs a 30 s wait and always close its admin.
|
|
31
53
|
- [Maintenance] Define `Consumer.finalizer` and `Consumer.report_close_error` in a `class << self` block. Callers are not affected. Ported from rdkafka-ruby (#1068).
|
|
32
54
|
- [Maintenance] Wait 30 s for the `before(:suite)` topic creates. Ported from rdkafka-ruby (#1065).
|
|
33
55
|
- [Maintenance] Run the concurrent first produce checks on JRuby, now that `close` no longer hangs there after concurrent produces. Ported from rdkafka-ruby (#1083).
|
|
34
|
-
- [Maintenance] Create the topics of the producer `timestamp` specs with `retention.ms: -1`, so broker retention no longer deletes their
|
|
35
|
-
- [Maintenance] Time out the SSL spec step of the Ubuntu aarch64 complementary CI workflow after 25 minutes
|
|
36
|
-
- [Maintenance] Fix the YARD notes of `events_poll_nb_each` and `Consumer#poll_nb_each`: they do not hold a lock while they loop
|
|
56
|
+
- [Maintenance] Create the topics of the producer `timestamp` specs with `retention.ms: -1`, so broker retention no longer deletes their messages. Ported from rdkafka-ruby (#1077).
|
|
57
|
+
- [Maintenance] Time out the SSL spec step of the Ubuntu aarch64 complementary CI workflow after 25 minutes. Ported from rdkafka-ruby (#1086).
|
|
58
|
+
- [Maintenance] Fix the YARD notes of `events_poll_nb_each` and `Consumer#poll_nb_each`: they do not hold a lock while they loop. Ported from rdkafka-ruby (#1089).
|
|
37
59
|
- [Maintenance] Stop the fake SSL servers in integration specs without `Thread#kill`. Ported from rdkafka-ruby (#1059).
|
|
38
60
|
- [Fix] Stop `Consumer#store_offset` and other calls that pass partition metadata from raising `NoMethodError` on JRuby. Ported from rdkafka-ruby (#1045).
|
|
39
61
|
- [Fix] Pass the error buffer size to librdkafka as `size_t` when setting config options and creating clients.
|
data/README.md
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
> [!NOTE]
|
|
8
8
|
> **Karafka-Rdkafka** is a fork of the [rdkafka-ruby](https://github.com/karafka/rdkafka-ruby) gem, specifically maintained for the [Karafka ecosystem](https://karafka.io). This fork exists to provide Karafka-specific patches and optimizations that are not generic enough for inclusion in the upstream rdkafka-ruby library.
|
|
9
9
|
|
|
10
|
+
> [!WARNING]
|
|
11
|
+
> **This gem is not meant to be used outside of the Karafka ecosystem.** It is a dependency of [Karafka](https://github.com/karafka/karafka), [WaterDrop](https://github.com/karafka/waterdrop) and their companion gems, not a general-purpose Kafka client. Its API follows what these gems need and can change in any release, a patch release included, without a deprecation period. Use Karafka or WaterDrop, or [rdkafka-ruby](https://github.com/karafka/rdkafka-ruby) for a standalone Kafka client.
|
|
12
|
+
|
|
10
13
|
---
|
|
11
14
|
|
|
12
15
|
## Why This Fork Exists
|
|
@@ -41,7 +44,11 @@ However, until such integration is possible, this fork ensures that Karafka user
|
|
|
41
44
|
|
|
42
45
|
### If You're Using Standalone rdkafka
|
|
43
46
|
|
|
44
|
-
You should use the [original rdkafka-ruby gem](https://github.com/karafka/rdkafka-ruby) for general Kafka client needs. This fork is specifically designed for Karafka and
|
|
47
|
+
You should use the [original rdkafka-ruby gem](https://github.com/karafka/rdkafka-ruby) for general Kafka client needs. This fork is specifically designed for Karafka and is not supported for other use cases: depending on it directly means its API can change under you in any release.
|
|
48
|
+
|
|
49
|
+
### API Stability and the Changelog
|
|
50
|
+
|
|
51
|
+
The supported users of this gem are the Karafka ecosystem gems, which are released together with it. A change to a method signature or a return value is made together with the matching change in those gems, and the changelog marks it **[Breaking]** only when it breaks a released version of one of them. Changes that only affect code calling this gem directly are listed as **[Change]**.
|
|
45
52
|
|
|
46
53
|
### Reporting Issues
|
|
47
54
|
|
|
@@ -79,10 +86,10 @@ Contributions should generally be made to the upstream [rdkafka-ruby repository]
|
|
|
79
86
|
| 0.19.x (2025-01-20) | 2.8.0 (2025-01-07) | yes |
|
|
80
87
|
| 0.18.0 (2024-11-26) | 2.6.1 (2024-11-18) | yes |
|
|
81
88
|
| 0.17.4 (2024-09-02) | 2.5.3 (2024-09-02) | yes |
|
|
82
|
-
| 0.17.0 (2024-
|
|
83
|
-
| 0.16.0 (2024-06-
|
|
84
|
-
| 0.15.0 (
|
|
85
|
-
| 0.14.0 (2023-11-
|
|
89
|
+
| 0.17.0 (2024-07-21) | 2.5.0 (2024-07-10) | yes |
|
|
90
|
+
| 0.16.0 (2024-06-17) | 2.4.0 (2024-05-07) | no |
|
|
91
|
+
| 0.15.0 (2024-04-26) | 2.3.0 (2023-10-25) | no |
|
|
92
|
+
| 0.14.0 (2023-11-17) | 2.2.0 (2023-07-12) | no |
|
|
86
93
|
| 0.13.0 (2023-07-24) | 2.0.2 (2023-01-20) | no |
|
|
87
94
|
| 0.12.0 (2022-06-17) | 1.9.0 (2022-06-16) | no |
|
|
88
95
|
| 0.11.0 (2021-11-17) | 1.8.2 (2021-10-18) | no |
|
data/ext/librdkafka.so
CHANGED
|
Binary file
|
|
@@ -22,9 +22,20 @@ module Rdkafka
|
|
|
22
22
|
REGISTRY_MUTEX = Mutex.new
|
|
23
23
|
# Default wait timeout is 31 years
|
|
24
24
|
MAX_WAIT_TIMEOUT_FOREVER = 10_000_000_000
|
|
25
|
+
# Number of shared lock stripes (power of two)
|
|
26
|
+
LOCK_STRIPES_COUNT = 1_024
|
|
27
|
+
# Shared `[Mutex, ConditionVariable]` pairs for `#wait` and `#unlock`, so a handle does not
|
|
28
|
+
# allocate its own. A handle picks its stripe by native address, which is stable for its life.
|
|
29
|
+
# A broadcast for another handle on the same stripe is a spurious wakeup: `#wait` re-checks
|
|
30
|
+
# `pending?` after every wakeup.
|
|
31
|
+
LOCK_STRIPES = Array.new(LOCK_STRIPES_COUNT) do
|
|
32
|
+
[Thread::Mutex.new, Thread::ConditionVariable.new].freeze
|
|
33
|
+
end.freeze
|
|
25
34
|
|
|
26
35
|
private_constant :REGISTRY_MUTEX
|
|
27
36
|
private_constant :MAX_WAIT_TIMEOUT_FOREVER
|
|
37
|
+
private_constant :LOCK_STRIPES_COUNT
|
|
38
|
+
private_constant :LOCK_STRIPES
|
|
28
39
|
|
|
29
40
|
class << self
|
|
30
41
|
# Adds handle to the register
|
|
@@ -54,13 +65,6 @@ module Rdkafka
|
|
|
54
65
|
# callback, used by `#raise_error`
|
|
55
66
|
attr_accessor :broker_message
|
|
56
67
|
|
|
57
|
-
def initialize
|
|
58
|
-
@mutex = Thread::Mutex.new
|
|
59
|
-
@resource = Thread::ConditionVariable.new
|
|
60
|
-
|
|
61
|
-
super
|
|
62
|
-
end
|
|
63
|
-
|
|
64
68
|
# Whether the handle is still pending.
|
|
65
69
|
#
|
|
66
70
|
# @return [Boolean]
|
|
@@ -101,13 +105,15 @@ module Rdkafka
|
|
|
101
105
|
timeout_s = timeout_ms ? timeout_ms / 1000.0 : nil
|
|
102
106
|
timeout = timeout_s ? monotonic_now + timeout_s : MAX_WAIT_TIMEOUT_FOREVER
|
|
103
107
|
|
|
104
|
-
|
|
108
|
+
mutex, resource = lock_stripe
|
|
109
|
+
|
|
110
|
+
mutex.synchronize do
|
|
105
111
|
loop do
|
|
106
112
|
if pending?
|
|
107
113
|
to_wait = (timeout - monotonic_now)
|
|
108
114
|
|
|
109
115
|
if to_wait.positive?
|
|
110
|
-
|
|
116
|
+
resource.wait(mutex, to_wait)
|
|
111
117
|
else
|
|
112
118
|
raise WaitTimeoutError.new(
|
|
113
119
|
"Waiting for #{operation_name} timed out after #{timeout_ms} ms"
|
|
@@ -124,9 +130,11 @@ module Rdkafka
|
|
|
124
130
|
|
|
125
131
|
# Unlock the resources
|
|
126
132
|
def unlock
|
|
127
|
-
|
|
133
|
+
mutex, resource = lock_stripe
|
|
134
|
+
|
|
135
|
+
mutex.synchronize do
|
|
128
136
|
self[:pending] = false
|
|
129
|
-
|
|
137
|
+
resource.broadcast
|
|
130
138
|
end
|
|
131
139
|
end
|
|
132
140
|
|
|
@@ -163,5 +171,12 @@ module Rdkafka
|
|
|
163
171
|
# Error that is raised when waiting for the handle to complete
|
|
164
172
|
# takes longer than the specified timeout.
|
|
165
173
|
class WaitTimeoutError < RuntimeError; end
|
|
174
|
+
|
|
175
|
+
private
|
|
176
|
+
|
|
177
|
+
# @return [Array(Thread::Mutex, Thread::ConditionVariable)] lock stripe of this handle
|
|
178
|
+
def lock_stripe
|
|
179
|
+
LOCK_STRIPES[(to_ptr.address >> 4) & (LOCK_STRIPES_COUNT - 1)]
|
|
180
|
+
end
|
|
166
181
|
end
|
|
167
182
|
end
|
|
@@ -6,6 +6,12 @@ module Rdkafka
|
|
|
6
6
|
class ConfigBindingResult
|
|
7
7
|
attr_reader :name, :value, :read_only, :default, :sensitive, :synonym, :synonyms
|
|
8
8
|
|
|
9
|
+
# @return [Integer] where the value comes from, one of `Bindings::RD_KAFKA_CONFIG_SOURCE_*`
|
|
10
|
+
attr_reader :source
|
|
11
|
+
|
|
12
|
+
# @return [String] name of the source, e.g. `"DYNAMIC_TOPIC_CONFIG"`
|
|
13
|
+
attr_reader :source_name
|
|
14
|
+
|
|
9
15
|
# @param config_ptr [FFI::Pointer] config pointer
|
|
10
16
|
def initialize(config_ptr)
|
|
11
17
|
@name = Bindings.rd_kafka_ConfigEntry_name(config_ptr)
|
|
@@ -14,6 +20,8 @@ module Rdkafka
|
|
|
14
20
|
@default = Bindings.rd_kafka_ConfigEntry_is_default(config_ptr)
|
|
15
21
|
@sensitive = Bindings.rd_kafka_ConfigEntry_is_sensitive(config_ptr)
|
|
16
22
|
@synonym = Bindings.rd_kafka_ConfigEntry_is_synonym(config_ptr)
|
|
23
|
+
@source = Bindings.rd_kafka_ConfigEntry_source(config_ptr)
|
|
24
|
+
@source_name = Bindings.rd_kafka_ConfigSource_name(@source)
|
|
17
25
|
@synonyms = []
|
|
18
26
|
|
|
19
27
|
# The code below builds up the config synonyms using same config binding
|
data/lib/rdkafka/admin.rb
CHANGED
|
@@ -273,7 +273,7 @@ module Rdkafka
|
|
|
273
273
|
# or aborted; retry on this code
|
|
274
274
|
# @return [ListConsumerGroupOffsetsHandle] handle that can be used to wait for the result
|
|
275
275
|
# @raise [RdkafkaError] when listing the offsets fails
|
|
276
|
-
def list_consumer_group_offsets(group_id, topic_partition_list
|
|
276
|
+
def list_consumer_group_offsets(group_id, topic_partition_list: nil, require_stable_offsets: false)
|
|
277
277
|
closed_admin_check(__method__)
|
|
278
278
|
|
|
279
279
|
native_tpl = topic_partition_list&.to_native_tpl
|
|
@@ -16,6 +16,8 @@ module Rdkafka
|
|
|
16
16
|
attach_function :rd_kafka_ConfigEntry_is_sensitive, [:pointer], :int
|
|
17
17
|
attach_function :rd_kafka_ConfigEntry_is_synonym, [:pointer], :int
|
|
18
18
|
attach_function :rd_kafka_ConfigEntry_synonyms, [:pointer, :pointer], :pointer
|
|
19
|
+
attach_function :rd_kafka_ConfigEntry_source, [:pointer], :int
|
|
20
|
+
attach_function :rd_kafka_ConfigSource_name, [:int], :string
|
|
19
21
|
attach_function :rd_kafka_ConfigResource_error, [:pointer], :int
|
|
20
22
|
attach_function :rd_kafka_ConfigResource_error_string, [:pointer], :string
|
|
21
23
|
attach_function :rd_kafka_IncrementalAlterConfigs, [:pointer, :pointer, :size_t, :pointer, :pointer], :void, blocking: true
|
|
@@ -33,5 +35,14 @@ module Rdkafka
|
|
|
33
35
|
RD_KAFKA_ALTER_CONFIG_OP_TYPE_DELETE = 1
|
|
34
36
|
RD_KAFKA_ALTER_CONFIG_OP_TYPE_APPEND = 2
|
|
35
37
|
RD_KAFKA_ALTER_CONFIG_OP_TYPE_SUBTRACT = 3
|
|
38
|
+
|
|
39
|
+
# Config value sources (rd_kafka_ConfigSource_t)
|
|
40
|
+
RD_KAFKA_CONFIG_SOURCE_UNKNOWN_CONFIG = 0
|
|
41
|
+
RD_KAFKA_CONFIG_SOURCE_DYNAMIC_TOPIC_CONFIG = 1
|
|
42
|
+
RD_KAFKA_CONFIG_SOURCE_DYNAMIC_BROKER_CONFIG = 2
|
|
43
|
+
RD_KAFKA_CONFIG_SOURCE_DYNAMIC_DEFAULT_BROKER_CONFIG = 3
|
|
44
|
+
RD_KAFKA_CONFIG_SOURCE_STATIC_BROKER_CONFIG = 4
|
|
45
|
+
RD_KAFKA_CONFIG_SOURCE_DEFAULT_CONFIG = 5
|
|
46
|
+
RD_KAFKA_CONFIG_SOURCE_GROUP_CONFIG = 8
|
|
36
47
|
end
|
|
37
48
|
end
|
|
@@ -48,11 +48,11 @@ module Rdkafka
|
|
|
48
48
|
# Since this cache is shared, having few consumers and/or producers in one process will
|
|
49
49
|
# automatically improve the querying times even with low refresh times.
|
|
50
50
|
(stats["topics"] || EMPTY_HASH).each do |topic_name, details|
|
|
51
|
-
|
|
51
|
+
partition_count = details["partitions"].keys.count { |k| !(k == RD_KAFKA_PARTITION_UA_STR) }
|
|
52
52
|
|
|
53
|
-
next unless
|
|
53
|
+
next unless partition_count.positive?
|
|
54
54
|
|
|
55
|
-
Rdkafka::Producer.
|
|
55
|
+
Rdkafka::Producer.partition_count_cache.set(topic_name, partition_count)
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
statistics_callback.call(stats)
|
data/lib/rdkafka/config.rb
CHANGED
|
@@ -161,18 +161,18 @@ module Rdkafka
|
|
|
161
161
|
#
|
|
162
162
|
# @return [Integer] time-to-live in milliseconds
|
|
163
163
|
def self.partition_count_cache_ttl_ms
|
|
164
|
-
Rdkafka::Producer.
|
|
164
|
+
Rdkafka::Producer.partition_count_cache.ttl_ms
|
|
165
165
|
end
|
|
166
166
|
|
|
167
167
|
# Sets the time-to-live of the process-wide partitions count cache shared by all the producers.
|
|
168
168
|
# Cached counts are kept, so it can be changed at any time.
|
|
169
169
|
#
|
|
170
170
|
# @param value [Integer] time-to-live in milliseconds
|
|
171
|
-
# (defaults to {Defaults::
|
|
171
|
+
# (defaults to {Defaults::PARTITION_COUNT_CACHE_TTL_MS})
|
|
172
172
|
# @return [void]
|
|
173
173
|
# @raise [ArgumentError] when the value is not a positive Integer
|
|
174
174
|
def self.partition_count_cache_ttl_ms=(value)
|
|
175
|
-
Rdkafka::Producer.
|
|
175
|
+
Rdkafka::Producer.partition_count_cache.ttl_ms = value
|
|
176
176
|
end
|
|
177
177
|
|
|
178
178
|
# @private
|
data/lib/rdkafka/consumer.rb
CHANGED
|
@@ -16,10 +16,16 @@ module Rdkafka
|
|
|
16
16
|
include Helpers::OAuth
|
|
17
17
|
include Helpers::Metadata
|
|
18
18
|
include Helpers::ListOffsets
|
|
19
|
+
include Helpers::MessageBuildError
|
|
19
20
|
|
|
20
21
|
# Reason passed to the error callback when closing the consumer fails
|
|
21
22
|
CLOSE_ERROR_REASON = "Consumer close failed"
|
|
22
23
|
|
|
24
|
+
# Frozen result of a batch poll that got no messages
|
|
25
|
+
EMPTY_BATCH = [].freeze
|
|
26
|
+
|
|
27
|
+
private_constant :EMPTY_BATCH
|
|
28
|
+
|
|
23
29
|
# @private
|
|
24
30
|
# @param native_kafka [NativeKafka] wrapper around the native Kafka consumer handle
|
|
25
31
|
def initialize(native_kafka)
|
|
@@ -28,6 +34,8 @@ module Rdkafka
|
|
|
28
34
|
# consumer queue without capturing `self` (capturing the consumer in its own finalizer would
|
|
29
35
|
# pin it and prevent it from ever being collected).
|
|
30
36
|
@consumer_queue_holder = []
|
|
37
|
+
# Set under the native access lock once `rd_kafka_consumer_close` ran
|
|
38
|
+
@consumer_closed = false
|
|
31
39
|
|
|
32
40
|
# Makes sure the consumer is closed (consumer queue destroyed and native client destroyed)
|
|
33
41
|
# before it gets GCed by Ruby.
|
|
@@ -197,7 +205,8 @@ module Rdkafka
|
|
|
197
205
|
# @yieldreturn [Symbol, Object] Return `:stop` to break the loop, any other value continues
|
|
198
206
|
# @return [nil]
|
|
199
207
|
# @raise [Rdkafka::ClosedConsumerError] if called on a closed consumer
|
|
200
|
-
# @raise [Rdkafka::RdkafkaError] if a Kafka error occurs while polling
|
|
208
|
+
# @raise [Rdkafka::RdkafkaError] if a Kafka error occurs while polling, or if a message cannot
|
|
209
|
+
# be built; `details` then holds its `topic`, `partition` and `offset`
|
|
201
210
|
#
|
|
202
211
|
# @example Process messages until queue is empty
|
|
203
212
|
# consumer.poll_nb_each do |message|
|
|
@@ -234,7 +243,13 @@ module Rdkafka
|
|
|
234
243
|
Rdkafka::RdkafkaError.validate!(native_message, client_ptr: inner)
|
|
235
244
|
end
|
|
236
245
|
|
|
237
|
-
|
|
246
|
+
begin
|
|
247
|
+
message = Consumer::Message.new(native_message)
|
|
248
|
+
rescue Rdkafka::RdkafkaError => e
|
|
249
|
+
raise message_build_error(native_message, e)
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
result = yield message
|
|
238
253
|
break if result == :stop
|
|
239
254
|
ensure
|
|
240
255
|
Rdkafka::Bindings.rd_kafka_message_destroy(message_ptr)
|
|
@@ -251,7 +266,11 @@ module Rdkafka
|
|
|
251
266
|
|
|
252
267
|
close_response = nil
|
|
253
268
|
|
|
254
|
-
|
|
269
|
+
# The handle stays open until `NativeKafka#close`, so a late or retried closer can get here
|
|
270
|
+
# after the native consumer was already closed
|
|
271
|
+
@native_kafka.synchronize_unless_closed do |inner|
|
|
272
|
+
next if @consumer_closed
|
|
273
|
+
|
|
255
274
|
close_response = Rdkafka::Bindings.rd_kafka_consumer_close(inner)
|
|
256
275
|
|
|
257
276
|
if @consumer_queue
|
|
@@ -259,9 +278,11 @@ module Rdkafka
|
|
|
259
278
|
@consumer_queue = nil
|
|
260
279
|
@consumer_queue_holder[0] = nil
|
|
261
280
|
end
|
|
281
|
+
|
|
282
|
+
@consumer_closed = true
|
|
262
283
|
end
|
|
263
284
|
|
|
264
|
-
self.class.report_close_error(@native_kafka, close_response)
|
|
285
|
+
self.class.report_close_error(@native_kafka, close_response) unless close_response.nil?
|
|
265
286
|
|
|
266
287
|
@native_kafka.close
|
|
267
288
|
end
|
|
@@ -794,7 +815,8 @@ module Rdkafka
|
|
|
794
815
|
#
|
|
795
816
|
# @param timeout_ms [Integer] Timeout of this poll
|
|
796
817
|
# @return [Message, nil] A message or nil if there was no new message within the timeout
|
|
797
|
-
# @raise [RdkafkaError] When polling fails
|
|
818
|
+
# @raise [RdkafkaError] When polling fails, or when the message cannot be built (e.g. its
|
|
819
|
+
# headers cannot be read); `details` then holds its `topic`, `partition` and `offset`
|
|
798
820
|
def poll(timeout_ms)
|
|
799
821
|
closed_consumer_check(__method__)
|
|
800
822
|
|
|
@@ -808,7 +830,17 @@ module Rdkafka
|
|
|
808
830
|
native_message = Rdkafka::Bindings::Message.new(message_ptr)
|
|
809
831
|
|
|
810
832
|
# Create a message to pass out
|
|
811
|
-
|
|
833
|
+
if native_message[:err] == Rdkafka::Bindings::RD_KAFKA_RESP_ERR_NO_ERROR
|
|
834
|
+
# Assigned before returning: a `return` inside `begin/rescue` within this method's `ensure`
|
|
835
|
+
# compiles to a `throw`, which allocates on every message.
|
|
836
|
+
message = begin
|
|
837
|
+
Rdkafka::Consumer::Message.new(native_message)
|
|
838
|
+
rescue Rdkafka::RdkafkaError => e
|
|
839
|
+
raise message_build_error(native_message, e)
|
|
840
|
+
end
|
|
841
|
+
|
|
842
|
+
return message
|
|
843
|
+
end
|
|
812
844
|
|
|
813
845
|
# Raise error if needed - wrap just the validate! call with client access
|
|
814
846
|
@native_kafka.with_inner do |inner|
|
|
@@ -829,7 +861,8 @@ module Rdkafka
|
|
|
829
861
|
#
|
|
830
862
|
# @param timeout_ms [Integer] Timeout of this poll (default: 0 for non-blocking)
|
|
831
863
|
# @return [Message, nil] A message or nil if there was no new message within the timeout
|
|
832
|
-
# @raise [RdkafkaError] When polling fails
|
|
864
|
+
# @raise [RdkafkaError] When polling fails, or when the message cannot be built (e.g. its
|
|
865
|
+
# headers cannot be read); `details` then holds its `topic`, `partition` and `offset`
|
|
833
866
|
#
|
|
834
867
|
# @example Using with fiber scheduler
|
|
835
868
|
# # After receiving IO notification that messages are available
|
|
@@ -855,7 +888,11 @@ module Rdkafka
|
|
|
855
888
|
end
|
|
856
889
|
end
|
|
857
890
|
# Create a message to pass out
|
|
858
|
-
|
|
891
|
+
begin
|
|
892
|
+
Rdkafka::Consumer::Message.new(native_message)
|
|
893
|
+
rescue Rdkafka::RdkafkaError => e
|
|
894
|
+
raise message_build_error(native_message, e)
|
|
895
|
+
end
|
|
859
896
|
end
|
|
860
897
|
ensure
|
|
861
898
|
# Clean up rdkafka message if there is one
|
|
@@ -919,17 +956,19 @@ module Rdkafka
|
|
|
919
956
|
# rather than raised, so callers receive the complete batch - both messages and errors -
|
|
920
957
|
# and can decide how to handle each. This is particularly useful when multiple partitions
|
|
921
958
|
# signal EOF simultaneously: all signals appear in the returned array rather than only
|
|
922
|
-
# the first one being raised and the rest silently discarded.
|
|
959
|
+
# the first one being raised and the rest silently discarded. A message that cannot be built
|
|
960
|
+
# (e.g. its headers cannot be read) also comes inline as an {RdkafkaError} whose `details`
|
|
961
|
+
# hold its `topic`, `partition` and `offset`.
|
|
923
962
|
#
|
|
924
963
|
# @param timeout_ms [Integer] Timeout waiting for the first message (-1 for infinite)
|
|
925
964
|
# @param max_items [Integer] Maximum number of messages to return per call
|
|
926
|
-
# @return [Array<Message, RdkafkaError>] Batch of messages and/or error events in arrival order
|
|
965
|
+
# @return [Array<Message, RdkafkaError>] Batch of messages and/or error events in arrival order,
|
|
966
|
+
# or a frozen empty array when there are none
|
|
927
967
|
# @raise [ClosedConsumerError] When called on a closed consumer
|
|
928
968
|
def poll_batch(timeout_ms, max_items: 100)
|
|
929
969
|
closed_consumer_check(__method__)
|
|
930
970
|
|
|
931
971
|
buffer = batch_buffer(max_items)
|
|
932
|
-
results = []
|
|
933
972
|
|
|
934
973
|
count = @native_kafka.with_inner do |_inner|
|
|
935
974
|
Rdkafka::Bindings.rd_kafka_consume_batch_queue(
|
|
@@ -940,8 +979,9 @@ module Rdkafka
|
|
|
940
979
|
)
|
|
941
980
|
end
|
|
942
981
|
|
|
943
|
-
return
|
|
982
|
+
return EMPTY_BATCH if count <= 0
|
|
944
983
|
|
|
984
|
+
results = []
|
|
945
985
|
i = 0
|
|
946
986
|
begin
|
|
947
987
|
while i < count
|
|
@@ -970,7 +1010,7 @@ module Rdkafka
|
|
|
970
1010
|
# A message that fails to build (e.g. a header read error) is surfaced inline as an
|
|
971
1011
|
# error event rather than discarding the whole batch - including the messages already
|
|
972
1012
|
# built - and raising, which silently lost them once their offsets had been stored.
|
|
973
|
-
results << e
|
|
1013
|
+
results << message_build_error(native_message, e)
|
|
974
1014
|
end
|
|
975
1015
|
ensure
|
|
976
1016
|
Rdkafka::Bindings.rd_kafka_message_destroy(ptr)
|
|
@@ -996,7 +1036,8 @@ module Rdkafka
|
|
|
996
1036
|
# @param timeout_ms [Integer] Timeout waiting for the first message
|
|
997
1037
|
# (default: 0 for non-blocking)
|
|
998
1038
|
# @param max_items [Integer] Maximum number of messages to return per call
|
|
999
|
-
# @return [Array<Message, RdkafkaError>] Batch of messages and/or error events in arrival order
|
|
1039
|
+
# @return [Array<Message, RdkafkaError>] Batch of messages and/or error events in arrival order,
|
|
1040
|
+
# or a frozen empty array when there are none
|
|
1000
1041
|
# @raise [ClosedConsumerError] When called on a closed consumer
|
|
1001
1042
|
# @note Since the GVL is not released, a non-zero timeout_ms will block all Ruby
|
|
1002
1043
|
# threads/fibers for the duration. Use {#poll_batch} if you need a blocking wait.
|
|
@@ -1006,7 +1047,6 @@ module Rdkafka
|
|
|
1006
1047
|
closed_consumer_check(__method__)
|
|
1007
1048
|
|
|
1008
1049
|
buffer = batch_buffer(max_items)
|
|
1009
|
-
results = []
|
|
1010
1050
|
|
|
1011
1051
|
count = @native_kafka.with_inner do |_inner|
|
|
1012
1052
|
Rdkafka::Bindings.rd_kafka_consume_batch_queue_nb(
|
|
@@ -1017,8 +1057,9 @@ module Rdkafka
|
|
|
1017
1057
|
)
|
|
1018
1058
|
end
|
|
1019
1059
|
|
|
1020
|
-
return
|
|
1060
|
+
return EMPTY_BATCH if count <= 0
|
|
1021
1061
|
|
|
1062
|
+
results = []
|
|
1022
1063
|
i = 0
|
|
1023
1064
|
begin
|
|
1024
1065
|
while i < count
|
|
@@ -1047,7 +1088,7 @@ module Rdkafka
|
|
|
1047
1088
|
# A message that fails to build (e.g. a header read error) is surfaced inline as an
|
|
1048
1089
|
# error event rather than discarding the whole batch - including the messages already
|
|
1049
1090
|
# built - and raising, which silently lost them once their offsets had been stored.
|
|
1050
|
-
results << e
|
|
1091
|
+
results << message_build_error(native_message, e)
|
|
1051
1092
|
end
|
|
1052
1093
|
ensure
|
|
1053
1094
|
Rdkafka::Bindings.rd_kafka_message_destroy(ptr)
|
data/lib/rdkafka/defaults.rb
CHANGED
|
@@ -115,13 +115,20 @@ module Rdkafka
|
|
|
115
115
|
NATIVE_KAFKA_POLL_TIMEOUT_MS = 100
|
|
116
116
|
|
|
117
117
|
# TTL for partitions count cache entries (30 seconds)
|
|
118
|
-
# @see Producer::
|
|
119
|
-
|
|
118
|
+
# @see Producer::PartitionCountCache
|
|
119
|
+
PARTITION_COUNT_CACHE_TTL_MS = 30_000
|
|
120
|
+
|
|
121
|
+
# @deprecated Use {PARTITION_COUNT_CACHE_TTL_MS} instead. It will be removed in v1.0.0.
|
|
122
|
+
PARTITIONS_COUNT_CACHE_TTL_MS = PARTITION_COUNT_CACHE_TTL_MS
|
|
120
123
|
|
|
121
124
|
# How long an expired partitions count is served after a refresh failed on a transient
|
|
122
125
|
# (e.g. transport) error, before the next refresh attempt. Longer than one failed metadata
|
|
123
126
|
# refresh (up to ~7 s with retries), so produces are not blocked most of the time
|
|
124
|
-
# @see Producer::
|
|
125
|
-
|
|
127
|
+
# @see Producer::PartitionCountCache#get
|
|
128
|
+
PARTITION_COUNT_CACHE_STALE_BACKOFF_MS = 10_000
|
|
129
|
+
|
|
130
|
+
# @deprecated Use {PARTITION_COUNT_CACHE_STALE_BACKOFF_MS} instead.
|
|
131
|
+
# It will be removed in v1.0.0.
|
|
132
|
+
PARTITIONS_COUNT_CACHE_STALE_BACKOFF_MS = PARTITION_COUNT_CACHE_STALE_BACKOFF_MS
|
|
126
133
|
end
|
|
127
134
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
module Helpers
|
|
5
|
+
# Shared message build error handling for Consumer and ShareConsumer.
|
|
6
|
+
module MessageBuildError
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
# Rebuilds an error raised while building a message with that message's topic, partition
|
|
10
|
+
# and offset. librdkafka has already returned the message, so the caller needs them to act
|
|
11
|
+
# on it: a consumer seeks back to it, a share consumer acknowledges it.
|
|
12
|
+
# @param native_message [Rdkafka::Bindings::Message] the native message that failed to build
|
|
13
|
+
# @param error [RdkafkaError] the error raised while building it
|
|
14
|
+
# @return [RdkafkaError]
|
|
15
|
+
def message_build_error(native_message, error)
|
|
16
|
+
Rdkafka::RdkafkaError.new(
|
|
17
|
+
error.rdkafka_response,
|
|
18
|
+
error.message_prefix,
|
|
19
|
+
broker_message: error.broker_message,
|
|
20
|
+
details: {
|
|
21
|
+
topic: Rdkafka::Bindings.rd_kafka_topic_name(native_message[:rkt]),
|
|
22
|
+
partition: native_message[:partition],
|
|
23
|
+
offset: native_message[:offset]
|
|
24
|
+
}.freeze,
|
|
25
|
+
instance_name: error.instance_name
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|