waterdrop 2.10.3 → 2.10.4
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/.gitignore +2 -0
- data/.ruby-version +1 -1
- data/.yard-lint.yml +29 -1
- data/CHANGELOG.md +29 -23
- data/Gemfile.lint.lock +8 -7
- data/Gemfile.lock +10 -10
- data/lib/waterdrop/clients/buffered.rb +1 -2
- data/lib/waterdrop/clients/rdkafka.rb +2 -2
- data/lib/waterdrop/config.rb +2 -2
- data/lib/waterdrop/connection_pool.rb +3 -8
- data/lib/waterdrop/instrumentation/monitor.rb +4 -5
- data/lib/waterdrop/polling/config.rb +0 -2
- data/lib/waterdrop/polling/poller.rb +4 -6
- data/lib/waterdrop/polling/state.rb +6 -7
- data/lib/waterdrop/polling.rb +0 -1
- data/lib/waterdrop/producer/tombstone.rb +2 -2
- data/lib/waterdrop/producer/transactions.rb +4 -4
- data/lib/waterdrop/producer/variant.rb +1 -1
- data/lib/waterdrop/producer.rb +33 -7
- data/lib/waterdrop/version.rb +1 -2
- data/lib/waterdrop.rb +0 -1
- data/package-lock.json +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 32f1c3b166f74db06dc75080800f4972207facc943d00d7eeab73a6c33668aed
|
|
4
|
+
data.tar.gz: 8de1c8eecf566e241bc375fea7de5f568cd055be35a83effcf5de23b7c92f468
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 901c6f6a576c38807eee47641675b12f9ef3907325fb2435c6b2e8656724c4f57be6593a10b7b85348b8cadd317216fe84ba182a9ccfaf3fa0208119c0609686
|
|
7
|
+
data.tar.gz: 25720c9a6ac31520400f181af47b389eae9def35f384cf9b1d89f8466c4cafc904c0390fbe14a1222c6917b3b26fbcc38d9580e9a0fa45db07d1cc9528c3bb85
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
4.0.
|
|
1
|
+
4.0.6
|
data/.yard-lint.yml
CHANGED
|
@@ -61,6 +61,34 @@ Documentation/BlankLineBeforeDefinition:
|
|
|
61
61
|
SingleBlankLine: true
|
|
62
62
|
OrphanedDocs: true
|
|
63
63
|
|
|
64
|
+
Documentation/DuplicateNamespaceComment:
|
|
65
|
+
Description: Detects namespaces documented with a YARD comment in more than one file.
|
|
66
|
+
Enabled: true
|
|
67
|
+
Severity: error
|
|
68
|
+
|
|
69
|
+
Documentation/UnderfilledLines:
|
|
70
|
+
Description: Detects documentation prose that wraps too early and wastes horizontal space.
|
|
71
|
+
Enabled: true
|
|
72
|
+
Severity: error
|
|
73
|
+
# Aligned with RuboCop's Layout/LineLength (Max: 100) so documentation prose
|
|
74
|
+
# wraps to the same width as code.
|
|
75
|
+
MaxLength: 100
|
|
76
|
+
|
|
77
|
+
Documentation/LineLength:
|
|
78
|
+
Description: Detects documentation lines that exceed the maximum length.
|
|
79
|
+
Enabled: true
|
|
80
|
+
Severity: error
|
|
81
|
+
# Aligned with RuboCop's Layout/LineLength (Max: 100).
|
|
82
|
+
MaxLength: 100
|
|
83
|
+
|
|
84
|
+
Documentation/TextSubstitution:
|
|
85
|
+
Description: Detects em/en-dashes in documentation and replaces them with hyphens.
|
|
86
|
+
Enabled: true
|
|
87
|
+
Severity: error
|
|
88
|
+
Substitutions:
|
|
89
|
+
"—": "-" # em-dash (U+2014)
|
|
90
|
+
"–": "-" # en-dash (U+2013)
|
|
91
|
+
|
|
64
92
|
# Tags validators
|
|
65
93
|
Tags/Order:
|
|
66
94
|
Description: Enforces consistent ordering of YARD tags.
|
|
@@ -141,7 +169,7 @@ Tags/OptionTags:
|
|
|
141
169
|
Tags/ExampleSyntax:
|
|
142
170
|
Description: Validates Ruby syntax in @example tags.
|
|
143
171
|
Enabled: true
|
|
144
|
-
Severity:
|
|
172
|
+
Severity: error
|
|
145
173
|
|
|
146
174
|
Tags/RedundantParamDescription:
|
|
147
175
|
Description: Detects meaningless parameter descriptions that add no value.
|
data/CHANGELOG.md
CHANGED
|
@@ -1,43 +1,49 @@
|
|
|
1
1
|
# WaterDrop changelog
|
|
2
2
|
|
|
3
|
+
## 2.10.4 (2026-08-26)
|
|
4
|
+
- [Fix] Avoid a `FrozenError` on `Producer#close` when the producer is configured with a frozen string id (for example a frozen string literal, `config.id = "rspec"`).
|
|
5
|
+
- [Fix] Emit `connection_pool.shutdown` only once when shutting down the global connection pool.
|
|
6
|
+
- [Fix] Retry a produce that races a concurrent idempotent fatal-error reload instead of leaking a raw `Rdkafka::ClosedProducerError`/`Rdkafka::ClosedInnerError`.
|
|
7
|
+
- [Maintenance] Stop the `#partition_count when topic does not exist` spec from flaking on slow CI runners by waiting for authoritative broker metadata before asserting the count.
|
|
8
|
+
|
|
3
9
|
## 2.10.3 (2026-07-15)
|
|
4
|
-
- [Feature] Add `wait_timeout_on_transaction_abort` (default `0`, disabled) - an opt-in mitigation for [librdkafka#4849](https://github.com/confluentinc/librdkafka/issues/4849)
|
|
10
|
+
- [Feature] Add `wait_timeout_on_transaction_abort` (default `0`, disabled) - an opt-in mitigation for [librdkafka#4849](https://github.com/confluentinc/librdkafka/issues/4849) that waits (up to the given ms) for the first delivery to be acknowledged before aborting, avoiding a fatal `INVALID_TXN_STATE`. Off by default because it changes abort semantics: the awaited message is written to the log (aborted) instead of being purged.
|
|
5
11
|
|
|
6
12
|
## 2.10.2 (2026-06-15)
|
|
7
|
-
- [Feature] Expose `Producer#current_variant` as a public method
|
|
8
|
-
- [Enhancement] Stop allocating one interpolated string per message in `LoggerListener` batch produce handlers.
|
|
13
|
+
- [Feature] Expose `Producer#current_variant` as a public method returning the variant active for the current dispatch on the current fiber, so middleware and instrumentation listeners can read the effective per-dispatch settings (`topic_config`, `max_wait_timeout`, `default?`).
|
|
14
|
+
- [Enhancement] Stop allocating one interpolated string per message in `LoggerListener` batch produce handlers.
|
|
9
15
|
- [Enhancement] Use `Array#concat` in `Producer#buffer_many` instead of appending messages one by one.
|
|
10
|
-
- [Enhancement] Skip building the `message.acknowledged` instrumentation payload in the delivery callback when nothing is subscribed to that event.
|
|
11
|
-
- [Enhancement] Resolve the fiber-local variant once per `#produce` call and once per `#produce_many_sync` wait phase instead of re-resolving it for every usage
|
|
12
|
-
- [Enhancement] Do not allocate the fiber-local variants hash on the `Producer#current_variant` read path
|
|
13
|
-
- [Enhancement] Cache the variant validation contract in a constant instead of instantiating a new `Contracts::Variant` on every `Producer#with` / `Producer#variant` call
|
|
14
|
-
- [Enhancement] Cache the tombstone validation contract in a constant instead of instantiating a new `Contracts::Tombstone` per tombstone message
|
|
15
|
-
- [Enhancement] Replace explicit `Warning[:performance]` opt-in with a dynamic approach using `Warning.categories`
|
|
16
|
-
- [Fix] Prevent a deadlock between a transactional single-message dispatch and `#close
|
|
17
|
-
- [Fix] Prevent a deadlock (`ThreadError: deadlock; recursive locking`) when closing an idempotent producer (with `reload_on_idempotent_fatal_error` enabled)
|
|
18
|
-
- [Fix] Make concurrent idempotent fatal-error reload thread-safe
|
|
19
|
-
- [Fix] Stop `#flush_async` / `#flush_sync` from silently dropping valid buffered messages when the dispatch fails
|
|
20
|
-
- [Fix] Make `Producer#close` fork-safe so the GC finalizer inherited by a forked child can no longer
|
|
21
|
-
- [Fix] Guard the internal buffer appends in `Producer#buffer` and `Producer#buffer_many` with `@buffer_mutex
|
|
22
|
-
- [Fix] Stop a nested same-producer variant call from clobbering the outer variant inside a variant `transaction` block
|
|
23
|
-
- [Fix] Stop `ConnectionPool#shutdown` and `#reload` from silently dropping in-flight messages.
|
|
24
|
-
- [Fix] Close a race in the FD poller where a producer registered while the last one was being torn down could be left permanently unpolled
|
|
16
|
+
- [Enhancement] Skip building the `message.acknowledged` instrumentation payload in the delivery callback when nothing is subscribed to that event.
|
|
17
|
+
- [Enhancement] Resolve the fiber-local variant once per `#produce` call and once per `#produce_many_sync` wait phase instead of re-resolving it for every usage.
|
|
18
|
+
- [Enhancement] Do not allocate the fiber-local variants hash on the `Producer#current_variant` read path when variants are never used.
|
|
19
|
+
- [Enhancement] Cache the variant validation contract in a constant instead of instantiating a new `Contracts::Variant` on every `Producer#with` / `Producer#variant` call.
|
|
20
|
+
- [Enhancement] Cache the tombstone validation contract in a constant instead of instantiating a new `Contracts::Tombstone` per tombstone message.
|
|
21
|
+
- [Enhancement] Replace explicit `Warning[:performance]` opt-in with a dynamic approach using `Warning.categories` to enable all stable opt-in warning categories in the test suite.
|
|
22
|
+
- [Fix] Prevent a deadlock between a transactional single-message dispatch and `#close` caused by an inverted lock order; transactional dispatches now take `@transaction_mutex` before the operation is counted.
|
|
23
|
+
- [Fix] Prevent a deadlock (`ThreadError: deadlock; recursive locking`) when closing an idempotent producer (with `reload_on_idempotent_fatal_error` enabled) whose final buffer flush surfaces a fatal librdkafka error; the idempotent reload is now skipped on the closing path.
|
|
24
|
+
- [Fix] Make concurrent idempotent fatal-error reload thread-safe so a second thread's reload can no longer raise `NoMethodError` after the first reset `@client`.
|
|
25
|
+
- [Fix] Stop `#flush_async` / `#flush_sync` from silently dropping valid buffered messages when the dispatch fails; unsent messages are now re-buffered so they can be retried instead of being lost.
|
|
26
|
+
- [Fix] Make `Producer#close` fork-safe so the GC finalizer inherited by a forked child can no longer flush and close the parent's client.
|
|
27
|
+
- [Fix] Guard the internal buffer appends in `Producer#buffer` and `Producer#buffer_many` with `@buffer_mutex` so a concurrent flush/purge/close swap can no longer drop a message into an orphaned array.
|
|
28
|
+
- [Fix] Stop a nested same-producer variant call from clobbering the outer variant inside a variant `transaction` block; the wrapper now saves and restores the previous fiber-local entry instead of deleting it.
|
|
29
|
+
- [Fix] Stop `ConnectionPool#shutdown` and `#reload` from silently dropping in-flight messages. They now close producers gracefully by default (`#reload` always; `#shutdown` unless called with the new `force: true`); pass `pool.shutdown(force: true)` to keep the old force-and-purge behavior.
|
|
30
|
+
- [Fix] Close a race in the FD poller where a producer registered while the last one was being torn down could be left permanently unpolled; the poller now decides to stop and clears its thread reference in a single mutex section.
|
|
25
31
|
|
|
26
32
|
## 2.10.1 (2026-05-25)
|
|
27
33
|
- [Fix] Prevent `Producer#close` from raising `ThreadError: can't be called from trap context` when invoked from a Ruby signal trap context (e.g. Puma's `after_stopped` DSL hook in single mode). `close` now detects this case and delegates to a background thread, joining it so the caller blocks until the producer is fully closed (#866).
|
|
28
34
|
|
|
29
35
|
## 2.10.0 (2026-05-07)
|
|
30
|
-
- [Fix] Clean up native rdkafka client, global instrumentation callbacks, and poller registration when `init_transactions` fails during producer client construction
|
|
31
|
-
- **[Breaking]** Skip emitting librdkafka statistics when nothing is subscribed to `statistics.emitted` at the time the underlying rdkafka client is constructed
|
|
32
|
-
- **[Breaking]** Raise `WaterDrop::Errors::StatisticsNotEnabledError` when attempting to subscribe to `statistics.emitted`
|
|
36
|
+
- [Fix] Clean up native rdkafka client, global instrumentation callbacks, and poller registration when `init_transactions` fails during producer client construction, so failed attempts no longer leak native threads, file descriptors, and callback registry entries.
|
|
37
|
+
- **[Breaking]** Skip emitting librdkafka statistics when nothing is subscribed to `statistics.emitted` at the time the underlying rdkafka client is constructed (`statistics.interval.ms` is forced to `0`), saving substantial allocations in the hot path. To use statistics, subscribe a listener to `statistics.emitted` BEFORE the first producer use.
|
|
38
|
+
- **[Breaking]** Raise `WaterDrop::Errors::StatisticsNotEnabledError` when attempting to subscribe to `statistics.emitted` on a monitor where librdkafka statistics have been disabled at client build time, replacing the previous "silent nothing" failure mode.
|
|
33
39
|
- [Feature] Add tombstone API (`#tombstone_sync`, `#tombstone_async`, `#tombstone_many_sync`, `#tombstone_many_async`) for producing tombstone records (nil-payload messages) with required key and partition validation. Works with variants.
|
|
34
|
-
- [Fix] Add `ensure_same_process!` to `Poller#unregister` for fork safety
|
|
40
|
+
- [Fix] Add `ensure_same_process!` to `Poller#unregister` for fork safety, so a child that inherited a pre-fork producer no longer deadlocks on `producer.close`.
|
|
35
41
|
|
|
36
42
|
## 2.9.0 (2026-04-08)
|
|
37
43
|
- [Fix] Use `delete` in the variant ensure block to avoid leaving stale nil entries in `Fiber.current.waterdrop_clients` and prevent memory leaks in long-running processes (#836).
|
|
38
44
|
- [Fix] Exclude test files, `.github/`, and `log/` directories from gem releases to reduce package size.
|
|
39
45
|
- **[Breaking]** Switch default polling mode from `:thread` to `:fd`. If you experience any issues, you can revert to the previous behavior by setting `config.polling.mode = :thread`. The `:thread` mode will be deprecated in 2.10 and removed in 2.11.
|
|
40
|
-
- **[Breaking]** Statistics decorator now only decorates keys used by the built-in Datadog metrics listener (`tx`, `txretries`, `txerrs`, `rxerrs`) and skips unused subtrees
|
|
46
|
+
- **[Breaking]** Statistics decorator now only decorates keys used by the built-in Datadog metrics listener (`tx`, `txretries`, `txerrs`, `rxerrs`) and skips unused subtrees, greatly reducing decoration cost on large clusters. Users who rely on other `_d` or `_fd` keys in custom instrumentation should provide a custom decorator via `config.statistics_decorator`.
|
|
41
47
|
- [Feature] Add `config.statistics_decorator` setting to allow full control over the `StatisticsDecorator` instance used for statistics decoration. Users can provide a custom decorator with different `only_keys` and `excluded_keys` to match their instrumentation needs.
|
|
42
48
|
- [Change] Upscale default timeout values 3x closer to librdkafka defaults to prevent intermediate timeouts during node recovery (`message.timeout.ms`: 50s → 150s, `transaction.timeout.ms`: 55s → 165s, `max_wait_timeout`: 60s → 180s).
|
|
43
49
|
|
data/Gemfile.lint.lock
CHANGED
|
@@ -58,11 +58,11 @@ GEM
|
|
|
58
58
|
unicode-display_width (3.2.0)
|
|
59
59
|
unicode-emoji (~> 4.1)
|
|
60
60
|
unicode-emoji (4.2.0)
|
|
61
|
-
yard (0.9.
|
|
62
|
-
yard-lint (1.
|
|
61
|
+
yard (0.9.45)
|
|
62
|
+
yard-lint (1.10.1)
|
|
63
63
|
yard (~> 0.9)
|
|
64
64
|
zeitwerk (~> 2.6)
|
|
65
|
-
zeitwerk (2.
|
|
65
|
+
zeitwerk (2.8.2)
|
|
66
66
|
|
|
67
67
|
PLATFORMS
|
|
68
68
|
ruby
|
|
@@ -79,6 +79,7 @@ DEPENDENCIES
|
|
|
79
79
|
|
|
80
80
|
CHECKSUMS
|
|
81
81
|
ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
|
|
82
|
+
bundler (4.0.17) sha256=214e21431b5665dd2f99df8a5511c6b151d7a72e8015c8b38f8b775b61cbb6c1
|
|
82
83
|
json (2.18.0) sha256=b10506aee4183f5cf49e0efc48073d7b75843ce3782c68dbeb763351c08fd505
|
|
83
84
|
language_server-protocol (3.17.0.5) sha256=fd1e39a51a28bf3eec959379985a72e296e9f9acfce46f6a79d31ca8760803cc
|
|
84
85
|
lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
|
|
@@ -100,9 +101,9 @@ CHECKSUMS
|
|
|
100
101
|
standard-performance (1.9.0) sha256=49483d31be448292951d80e5e67cdcb576c2502103c7b40aec6f1b6e9c88e3f2
|
|
101
102
|
unicode-display_width (3.2.0) sha256=0cdd96b5681a5949cdbc2c55e7b420facae74c4aaf9a9815eee1087cb1853c42
|
|
102
103
|
unicode-emoji (4.2.0) sha256=519e69150f75652e40bf736106cfbc8f0f73aa3fb6a65afe62fefa7f80b0f80f
|
|
103
|
-
yard (0.9.
|
|
104
|
-
yard-lint (1.
|
|
105
|
-
zeitwerk (2.
|
|
104
|
+
yard (0.9.45) sha256=52e211493f7cb8a3ebf7e104a25a1e73937a3103092545d34cb88fafebb3dc51
|
|
105
|
+
yard-lint (1.10.1) sha256=172ea1905304580bd515c093d82831ec4889e725100c49d5bf77e62101f49129
|
|
106
|
+
zeitwerk (2.8.2) sha256=7212a61311083c604184b1ea2574b9aa05cd14f855a0841c06985cabe9181d12
|
|
106
107
|
|
|
107
108
|
BUNDLED WITH
|
|
108
|
-
|
|
109
|
+
4.0.17
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
waterdrop (2.10.
|
|
4
|
+
waterdrop (2.10.4)
|
|
5
5
|
karafka-core (>= 2.5.12, < 3.0.0)
|
|
6
6
|
karafka-rdkafka (>= 0.24.0)
|
|
7
7
|
zeitwerk (~> 2.3)
|
|
@@ -15,11 +15,11 @@ GEM
|
|
|
15
15
|
drb (2.2.3)
|
|
16
16
|
ffi (1.17.4)
|
|
17
17
|
io-console (0.8.2)
|
|
18
|
-
json (2.
|
|
18
|
+
json (2.21.2)
|
|
19
19
|
karafka-core (2.6.2)
|
|
20
20
|
karafka-rdkafka (>= 0.20.0)
|
|
21
21
|
logger (>= 1.6.0)
|
|
22
|
-
karafka-rdkafka (0.
|
|
22
|
+
karafka-rdkafka (0.28.0)
|
|
23
23
|
ffi (~> 1.17.1)
|
|
24
24
|
json (> 2.0)
|
|
25
25
|
logger
|
|
@@ -38,9 +38,9 @@ GEM
|
|
|
38
38
|
reline (0.6.3)
|
|
39
39
|
io-console (~> 0.5)
|
|
40
40
|
ruby2_keywords (0.0.5)
|
|
41
|
-
simplecov (1.
|
|
41
|
+
simplecov (1.1.1)
|
|
42
42
|
warning (1.6.0)
|
|
43
|
-
zeitwerk (2.8.
|
|
43
|
+
zeitwerk (2.8.3)
|
|
44
44
|
|
|
45
45
|
PLATFORMS
|
|
46
46
|
ruby
|
|
@@ -62,9 +62,9 @@ CHECKSUMS
|
|
|
62
62
|
drb (2.2.3) sha256=0b00d6fdb50995fe4a45dea13663493c841112e4068656854646f418fda13373
|
|
63
63
|
ffi (1.17.4) sha256=bcd1642e06f0d16fc9e09ac6d49c3a7298b9789bcb58127302f934e437d60acf
|
|
64
64
|
io-console (0.8.2) sha256=d6e3ae7a7cc7574f4b8893b4fca2162e57a825b223a177b7afa236c5ef9814cc
|
|
65
|
-
json (2.
|
|
65
|
+
json (2.21.2) sha256=1f1d3b7cf2b3ba1a69beca0bb6db13d5438b80bff3cd54cdaaa620b9b07c1c6a
|
|
66
66
|
karafka-core (2.6.2) sha256=c2fd7f277201b8ca97b824b364ad76bf776b8f5527bc422dafb71f7ae48d3a13
|
|
67
|
-
karafka-rdkafka (0.
|
|
67
|
+
karafka-rdkafka (0.28.0) sha256=fd845140c42341c5892215cac1e8adacda53b0461688f2e16379d82cb33eb006
|
|
68
68
|
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
|
|
69
69
|
mini_portile2 (2.8.9) sha256=0cd7c7f824e010c072e33f68bc02d85a00aeb6fce05bb4819c03dfd3c140c289
|
|
70
70
|
minitest (6.0.6) sha256=153ea36d1d987a62942382b61075745042a2b3123b1cd48f4c3675af9cc7d6f1
|
|
@@ -74,10 +74,10 @@ CHECKSUMS
|
|
|
74
74
|
rake (13.4.2) sha256=cb825b2bd5f1f8e91ca37bddb4b9aaf345551b4731da62949be002fa89283701
|
|
75
75
|
reline (0.6.3) sha256=1198b04973565b36ec0f11542ab3f5cfeeec34823f4e54cebde90968092b1835
|
|
76
76
|
ruby2_keywords (0.0.5) sha256=ffd13740c573b7301cf7a2e61fc857b2a8e3d3aff32545d6f8300d8bae10e3ef
|
|
77
|
-
simplecov (1.
|
|
77
|
+
simplecov (1.1.1) sha256=25825ef13f0b2e74694d769817dad6ab8e90131dabdaa666e522fea105521e78
|
|
78
78
|
warning (1.6.0) sha256=a49cdfae19fb77d19afff2efbe45f8ab759e9cd25b4e4ce2c79dbaf46bdb6c9e
|
|
79
|
-
waterdrop (2.10.
|
|
80
|
-
zeitwerk (2.8.
|
|
79
|
+
waterdrop (2.10.4)
|
|
80
|
+
zeitwerk (2.8.3) sha256=2c85125a8467ce069e20123d1e709a08955c9d29c118c25b46b7b7fafdbb92e5
|
|
81
81
|
|
|
82
82
|
BUNDLED WITH
|
|
83
83
|
4.0.6
|
|
@@ -80,8 +80,7 @@ module WaterDrop
|
|
|
80
80
|
@topics[topic]
|
|
81
81
|
end
|
|
82
82
|
|
|
83
|
-
# Clears internal buffer
|
|
84
|
-
# Used in between specs so messages do not leak out
|
|
83
|
+
# Clears internal buffer. Used in between specs so messages do not leak out
|
|
85
84
|
def reset
|
|
86
85
|
@transaction_level = 0
|
|
87
86
|
@transaction_active = false
|
|
@@ -51,7 +51,7 @@ module WaterDrop
|
|
|
51
51
|
# saves a significant number of allocations on the Ruby side (no JSON parsing, no
|
|
52
52
|
# statistics hash materialization, no decorator work). Any listener subscribed after
|
|
53
53
|
# the client has been built will not receive `statistics.emitted` events because
|
|
54
|
-
# librdkafka never emits them in the first place
|
|
54
|
+
# librdkafka never emits them in the first place - to use statistics, subscribe a
|
|
55
55
|
# listener BEFORE the first producer use.
|
|
56
56
|
#
|
|
57
57
|
# When statistics end up disabled (either because the user explicitly set the interval
|
|
@@ -94,7 +94,7 @@ module WaterDrop
|
|
|
94
94
|
|
|
95
95
|
# Registers the global callbacks (statistics, error, oauth refresh) for this producer
|
|
96
96
|
# on the shared `Karafka::Core::Instrumentation` managers. The statistics callback is
|
|
97
|
-
# only registered when librdkafka is actually going to emit statistics
|
|
97
|
+
# only registered when librdkafka is actually going to emit statistics - otherwise it
|
|
98
98
|
# would never fire and would only waste memory and a manager slot.
|
|
99
99
|
#
|
|
100
100
|
# @param producer [WaterDrop::Producer]
|
data/lib/waterdrop/config.rb
CHANGED
|
@@ -36,7 +36,7 @@ module WaterDrop
|
|
|
36
36
|
constructor: ->(id) { id || "waterdrop-#{SecureRandom.hex(6)}" }
|
|
37
37
|
)
|
|
38
38
|
# option [Instance] logger that we want to use
|
|
39
|
-
#
|
|
39
|
+
# Due to how rdkafka works, this setting is global for all the producers
|
|
40
40
|
setting(
|
|
41
41
|
:logger,
|
|
42
42
|
default: false,
|
|
@@ -169,7 +169,7 @@ module WaterDrop
|
|
|
169
169
|
# option [Class] class for usage when creating the underlying client used to dispatch messages
|
|
170
170
|
setting :client_class, default: Clients::Rdkafka
|
|
171
171
|
# rdkafka options
|
|
172
|
-
#
|
|
172
|
+
# See https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
|
|
173
173
|
setting :kafka, default: {}
|
|
174
174
|
# Middleware chain that can be expanded with useful middleware steps
|
|
175
175
|
setting(
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# WaterDrop library
|
|
4
3
|
module WaterDrop
|
|
5
4
|
# Connection pool wrapper for WaterDrop producers using the proven connection_pool gem.
|
|
6
5
|
#
|
|
@@ -119,15 +118,11 @@ module WaterDrop
|
|
|
119
118
|
def shutdown(force: false)
|
|
120
119
|
return unless @default_pool
|
|
121
120
|
|
|
122
|
-
|
|
121
|
+
# The instrumentation event is emitted by the instance-level #shutdown we delegate to
|
|
122
|
+
# (with `pool: self`, i.e. this same global pool). We deliberately do not emit it again
|
|
123
|
+
# here - doing so fired `connection_pool.shutdown` twice for a single global shutdown.
|
|
123
124
|
@default_pool.shutdown(force: force)
|
|
124
125
|
@default_pool = nil
|
|
125
|
-
|
|
126
|
-
# Emit global event for pool shutdown
|
|
127
|
-
WaterDrop.instrumentation.instrument(
|
|
128
|
-
"connection_pool.shutdown",
|
|
129
|
-
pool: pool
|
|
130
|
-
)
|
|
131
126
|
end
|
|
132
127
|
|
|
133
128
|
# Alias for shutdown to align with producer API
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
module WaterDrop
|
|
4
4
|
module Instrumentation
|
|
5
|
-
# WaterDrop instrumentation monitor that we use to publish events
|
|
6
|
-
#
|
|
7
|
-
# `ActiveSupport::Notifications` as well
|
|
5
|
+
# WaterDrop instrumentation monitor that we use to publish events. By default uses our internal
|
|
6
|
+
# notifications bus but can be used with `ActiveSupport::Notifications` as well
|
|
8
7
|
class Monitor < ::Karafka::Core::Monitoring::Monitor
|
|
9
8
|
# Event name for librdkafka statistics emissions
|
|
10
9
|
STATISTICS_EVENT = "statistics.emitted"
|
|
@@ -29,8 +28,8 @@ module WaterDrop
|
|
|
29
28
|
# Marks this monitor as no longer accepting new subscriptions to `statistics.emitted`.
|
|
30
29
|
# Called by the rdkafka client builder when it decides to leave librdkafka statistics
|
|
31
30
|
# disabled (because no listener was present at build time). Any subsequent attempt to
|
|
32
|
-
# subscribe to `statistics.emitted`
|
|
33
|
-
# responds to `on_statistics_emitted`
|
|
31
|
+
# subscribe to `statistics.emitted` - either via a block or via a listener object that
|
|
32
|
+
# responds to `on_statistics_emitted` - will raise
|
|
34
33
|
# `WaterDrop::Errors::StatisticsNotEnabledError` instead of silently doing nothing.
|
|
35
34
|
def freeze_statistics_listeners!
|
|
36
35
|
@statistics_listeners_frozen = true
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module WaterDrop
|
|
4
|
-
# Namespace for FD-based polling components
|
|
5
|
-
# Contains the global Poller singleton and State class for managing producer polling
|
|
6
4
|
module Polling
|
|
7
5
|
# Global poller singleton that manages a single polling thread for all FD-mode producers
|
|
8
6
|
# This replaces librdkafka's native background polling threads with a single Ruby thread
|
|
@@ -272,7 +270,8 @@ module WaterDrop
|
|
|
272
270
|
|
|
273
271
|
# Collects all IOs to monitor and builds a mapping from IO to State
|
|
274
272
|
# Uses cached arrays when possible to avoid allocations in the hot path
|
|
275
|
-
# @return [Array<Array<IO>, Hash{IO => State}, Array<State>>] tuple of ios, io-to-state map,
|
|
273
|
+
# @return [Array<Array<IO>, Hash{IO => State}, Array<State>>] tuple of ios, io-to-state map,
|
|
274
|
+
# states
|
|
276
275
|
def collect_readable_ios
|
|
277
276
|
# Fast path: return cached result if not dirty (no mutex needed)
|
|
278
277
|
# Safe because @cached_result is frozen and assigned atomically
|
|
@@ -345,9 +344,8 @@ module WaterDrop
|
|
|
345
344
|
end
|
|
346
345
|
end
|
|
347
346
|
|
|
348
|
-
# Polls all registered producers
|
|
349
|
-
#
|
|
350
|
-
# This ensures OAuth token refresh and statistics callbacks fire for all producers
|
|
347
|
+
# Polls all registered producers. Called when IO.select times out to ensure periodic polling
|
|
348
|
+
# happens. This ensures OAuth token refresh and statistics callbacks fire for all producers
|
|
351
349
|
def poll_all_producers
|
|
352
350
|
@cached_states.each { |state| poll_producer(state) }
|
|
353
351
|
end
|
|
@@ -26,7 +26,8 @@ module WaterDrop
|
|
|
26
26
|
# @param client [Rdkafka::Producer] the rdkafka producer client
|
|
27
27
|
# @param monitor [Object] the producer's monitor for error reporting
|
|
28
28
|
# @param max_poll_time [Integer] max time in ms to poll per cycle
|
|
29
|
-
# @param periodic_poll_interval [Integer] max time in ms before this producer needs periodic
|
|
29
|
+
# @param periodic_poll_interval [Integer] max time in ms before this producer needs periodic
|
|
30
|
+
# poll
|
|
30
31
|
# @raise [StandardError] if queue pipe setup fails (FD mode requires this to work)
|
|
31
32
|
def initialize(producer_id, client, monitor, max_poll_time, periodic_poll_interval)
|
|
32
33
|
@producer_id = producer_id
|
|
@@ -106,9 +107,8 @@ module WaterDrop
|
|
|
106
107
|
@last_stale_result = (now - @last_poll_time) >= @periodic_poll_interval
|
|
107
108
|
end
|
|
108
109
|
|
|
109
|
-
# Signals the poller to remove this producer
|
|
110
|
-
#
|
|
111
|
-
# Sets closing flag BEFORE signaling to ensure poller sees it
|
|
110
|
+
# Signals the poller to remove this producer. Called from any thread when the producer is
|
|
111
|
+
# being closed. Sets closing flag BEFORE signaling to ensure poller sees it
|
|
112
112
|
def signal_close
|
|
113
113
|
@closing = true
|
|
114
114
|
@queue_pipe.signal
|
|
@@ -133,9 +133,8 @@ module WaterDrop
|
|
|
133
133
|
@close_latch.release!
|
|
134
134
|
end
|
|
135
135
|
|
|
136
|
-
# Waits for this state to be closed
|
|
137
|
-
#
|
|
138
|
-
# This matches the threaded polling behavior which drains without timeout
|
|
136
|
+
# Waits for this state to be closed. Used by unregister to ensure synchronous cleanup before
|
|
137
|
+
# returning. This matches the threaded polling behavior which drains without timeout
|
|
139
138
|
def wait_for_close
|
|
140
139
|
@close_latch.wait
|
|
141
140
|
end
|
data/lib/waterdrop/polling.rb
CHANGED
|
@@ -16,7 +16,7 @@ module WaterDrop
|
|
|
16
16
|
# Produces a tombstone message to Kafka and waits for it to be delivered
|
|
17
17
|
#
|
|
18
18
|
# @param message [Hash] hash with at least `:topic`, `:key`, and `:partition` keys.
|
|
19
|
-
# `:payload` is not accepted
|
|
19
|
+
# `:payload` is not accepted - it will be silently removed if present.
|
|
20
20
|
#
|
|
21
21
|
# @return [Rdkafka::Producer::DeliveryReport] delivery report
|
|
22
22
|
#
|
|
@@ -28,7 +28,7 @@ module WaterDrop
|
|
|
28
28
|
# Produces a tombstone message to Kafka and does not wait for results
|
|
29
29
|
#
|
|
30
30
|
# @param message [Hash] hash with at least `:topic`, `:key`, and `:partition` keys.
|
|
31
|
-
# `:payload` is not accepted
|
|
31
|
+
# `:payload` is not accepted - it will be silently removed if present.
|
|
32
32
|
#
|
|
33
33
|
# @return [Rdkafka::Producer::DeliveryHandle] delivery handle
|
|
34
34
|
#
|
|
@@ -282,10 +282,10 @@ module WaterDrop
|
|
|
282
282
|
#
|
|
283
283
|
# librdkafka only marks a transaction as ongoing at the coordinator once the
|
|
284
284
|
# `AddPartitionsToTxn` **response** comes back, but it fires `EndTxn` as soon as that request
|
|
285
|
-
# has merely been **sent** (it gates on `txn_req_cnt`, bumped on send). Aborting with the
|
|
286
|
-
# produce still in flight can therefore reach a coordinator that does not yet consider
|
|
287
|
-
# transaction started, which fails the abort with a fatal `INVALID_TXN_STATE`.
|
|
288
|
-
#
|
|
285
|
+
# has merely been **sent** (it gates on `txn_req_cnt`, bumped on send). Aborting with the
|
|
286
|
+
# first produce still in flight can therefore reach a coordinator that does not yet consider
|
|
287
|
+
# the transaction started, which fails the abort with a fatal `INVALID_TXN_STATE`. See
|
|
288
|
+
# https://github.com/confluentinc/librdkafka/issues/4849
|
|
289
289
|
#
|
|
290
290
|
# A delivered message proves its partition completed registration, and that alone puts the
|
|
291
291
|
# transaction in an `ongoing` state at the coordinator - so a single acknowledged delivery is
|
|
@@ -122,7 +122,7 @@ module WaterDrop
|
|
|
122
122
|
topic_config: topic_config,
|
|
123
123
|
# We pass this to validation, to make sure no-one alters the `acks` value when operating
|
|
124
124
|
# in the transactional mode as it causes librdkafka to crash ruby
|
|
125
|
-
#
|
|
125
|
+
# See https://github.com/confluentinc/librdkafka/issues/4710
|
|
126
126
|
transactional: @producer.transactional?,
|
|
127
127
|
# We pass this for a similar reason as above
|
|
128
128
|
idempotent: @producer.idempotent?
|
data/lib/waterdrop/producer.rb
CHANGED
|
@@ -93,7 +93,9 @@ module WaterDrop
|
|
|
93
93
|
.setup(...)
|
|
94
94
|
.config
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
# dup so a frozen id (e.g. a frozen string literal) isn't used as the finalizer target, since
|
|
97
|
+
# ObjectSpace.(un)define_finalizer mutates the object and would raise FrozenError on #close
|
|
98
|
+
@id = @config.id.to_s.dup
|
|
97
99
|
@monitor = @config.monitor
|
|
98
100
|
@contract = Contracts::Message.new(max_payload_size: @config.max_payload_size)
|
|
99
101
|
@default_variant = Variant.new(self, default: true)
|
|
@@ -590,12 +592,13 @@ module WaterDrop
|
|
|
590
592
|
#
|
|
591
593
|
# For a transactional producer we wrap the whole dispatch (including the operations-counter
|
|
592
594
|
# bookkeeping) in `transaction`, so `@transaction_mutex` is acquired BEFORE
|
|
593
|
-
# `@operations_in_progress` is incremented. This makes `#produce` acquire locks in the same
|
|
594
|
-
# as `#close` (`@transaction_mutex` -> `@operating_mutex` -> operations counter) and
|
|
595
|
-
# lock-order inversion: without it, a dispatch that had already counted itself could
|
|
596
|
-
# on `@transaction_mutex` held by a concurrent `#close` that was itself waiting
|
|
597
|
-
# counter to drain. When we already own the transaction lock (inside an
|
|
598
|
-
# or the closing flush) the order is already correct, so we dispatch
|
|
595
|
+
# `@operations_in_progress` is incremented. This makes `#produce` acquire locks in the same
|
|
596
|
+
# order as `#close` (`@transaction_mutex` -> `@operating_mutex` -> operations counter) and
|
|
597
|
+
# removes a lock-order inversion: without it, a dispatch that had already counted itself could
|
|
598
|
+
# block forever on `@transaction_mutex` held by a concurrent `#close` that was itself waiting
|
|
599
|
+
# for the operations counter to drain. When we already own the transaction lock (inside an
|
|
600
|
+
# explicit transaction block or the closing flush) the order is already correct, so we dispatch
|
|
601
|
+
# directly.
|
|
599
602
|
#
|
|
600
603
|
# @param message [Hash] message we want to send
|
|
601
604
|
# @param label [String] short name of the public dispatch method (e.g. `"produce_sync"`) that
|
|
@@ -658,6 +661,29 @@ module WaterDrop
|
|
|
658
661
|
@idempotent_fatal_error_attempts = 0
|
|
659
662
|
|
|
660
663
|
result
|
|
664
|
+
rescue Rdkafka::ClosedProducerError, Rdkafka::ClosedInnerError
|
|
665
|
+
# A concurrent idempotent fatal-error reload closed the underlying client while this produce
|
|
666
|
+
# was already in flight. Unlike `#close`/`#disconnect`, which drain `@operations_in_progress`
|
|
667
|
+
# before closing the client, the idempotent reload swaps `@client` out from under sibling
|
|
668
|
+
# threads that have already passed the `@operating_mutex` gate and are inside `client.produce`.
|
|
669
|
+
# Racing with `@client.close`, such a thread sees either a producer already flagged closed
|
|
670
|
+
# (`ClosedProducerError`) or a nil inner librdkafka handle (`ClosedInnerError`) - which one
|
|
671
|
+
# depends purely on how far `close` has progressed.
|
|
672
|
+
#
|
|
673
|
+
# This is a benign, recoverable transient rather than a produce failure: the client has just
|
|
674
|
+
# been (or is being) rebuilt, so we retry the dispatch against the fresh client instead of
|
|
675
|
+
# surfacing a raw "closed producer" error to the caller - which would defeat the whole point
|
|
676
|
+
# of the transparent reload. Only the idempotent reload path closes the client with produces
|
|
677
|
+
# in flight, so we scope the retry to that configuration; anywhere else a closed client is a
|
|
678
|
+
# genuine error and must propagate. The retried pass re-runs `ensure_active!`, which raises
|
|
679
|
+
# `ProducerClosedError` once the producer is genuinely closing/closed, so this cannot spin
|
|
680
|
+
# forever.
|
|
681
|
+
raise unless config.reload_on_idempotent_fatal_error
|
|
682
|
+
raise if transactional?
|
|
683
|
+
|
|
684
|
+
@operations_in_progress.decrement
|
|
685
|
+
|
|
686
|
+
retry
|
|
661
687
|
rescue SUPPORTED_FLOW_ERRORS.first => e
|
|
662
688
|
# Check if this is a fatal error on an idempotent producer and we should reload.
|
|
663
689
|
#
|
data/lib/waterdrop/version.rb
CHANGED
data/lib/waterdrop.rb
CHANGED
data/package-lock.json
CHANGED
|
@@ -286,9 +286,9 @@
|
|
|
286
286
|
}
|
|
287
287
|
},
|
|
288
288
|
"node_modules/smol-toml": {
|
|
289
|
-
"version": "1.7.
|
|
290
|
-
"resolved": "https://registry.npmjs.org/smol-toml/-/smol-toml-1.7.
|
|
291
|
-
"integrity": "sha512-
|
|
289
|
+
"version": "1.7.1",
|
|
290
|
+
"resolved": "https://registry.npmjs.org/smol-toml/-/smol-toml-1.7.1.tgz",
|
|
291
|
+
"integrity": "sha512-PPlsspAZ4jbMBu5DMFhfUGDQLu/vrL4SyBROVS37x8ynnVmFIs1VPBz1Co8Xks3TvpIaZXmU85y4DrQ+UyVFoQ==",
|
|
292
292
|
"dev": true,
|
|
293
293
|
"license": "BSD-3-Clause",
|
|
294
294
|
"engines": {
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: waterdrop
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.10.
|
|
4
|
+
version: 2.10.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Maciej Mensfeld
|
|
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
160
160
|
- !ruby/object:Gem::Version
|
|
161
161
|
version: '0'
|
|
162
162
|
requirements: []
|
|
163
|
-
rubygems_version: 4.0.
|
|
163
|
+
rubygems_version: 4.0.16
|
|
164
164
|
specification_version: 4
|
|
165
165
|
summary: Kafka messaging made easy!
|
|
166
166
|
test_files: []
|