waterdrop 2.10.10 → 2.10.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf52057f67473d68a4ec20e57ac3d45f3ae84d5fe9dd1e42655ef7d02c1384a8
4
- data.tar.gz: ad9cb21f3a98a8ddad666355e507839f38a3c08a02a14d2c9fed89260a2ba1a3
3
+ metadata.gz: ea63c502e1050986468202c5b255aeafb4d120579b8a175534156dc5dd423b39
4
+ data.tar.gz: f8c84425802853f77642fbabb63b3ee8b36018d36888ddadb0815e0956105b90
5
5
  SHA512:
6
- metadata.gz: 472757b2946e50858b02601f71976bcafbd496cd8674e3863068725ef4dbf750d850add9553eed3e1515563fd6275a409d05a214120b2eaef51b06c8c4376543
7
- data.tar.gz: bc795ef820ae4c995f5f770858f674e3069dac85e1819ed72c02ab34aa1dba74099a5ab7a8485e69bad90a1adb8cebd4855b7de45931d535aa24bea6622d598b
6
+ metadata.gz: e0983557e2c383ea14a035638f315874ce5a0e5ee830b28618ea2a9a1d42fa046c6b2b726932432ac8c8b842b90f8a887fa494a1da28ef88c632dc50ece22e50
7
+ data.tar.gz: f45f7764bc4787d3ad755a8eeef67a2d939192074f941cf672632cd39519f17ea13b47e5a6ee3fb310a64dc52442f41c25644b4714ac83b0fcd25334f2d23c02
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 4.0.9
1
+ 4.0.10
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # WaterDrop changelog
2
2
 
3
+ ## v2.10.11 (2026-11-20)
4
+ - [Feature] Add the `produce` / `produce!`, `produce_many` / `produce_many!`, `tombstone` / `tombstone!`, `tombstone_many` / `tombstone_many!` and `flush` / `flush!` aliases of the `_async` / `_sync` methods.
5
+ - [Change] Require `karafka-core` `>=` `2.6.8`.
6
+ - [Fix] Treat `enable.idempotence` as on only when it is `true` or `"true"`. For a non-transactional producer, any other value (e.g. `"false"`) now makes `Producer#idempotent?` return `false`; it returns a Boolean. This includes values librdkafka reads as true, e.g. `1` and `"TRUE"`.
7
+ - [Fix] Wrap the `Rdkafka::Config::ConfigError` raised at dispatch for an invalid variant `topic_config` in `ProduceError` / `ProduceManyError` and instrument it as `error.occurred`, like the other produce errors.
8
+ - [Fix] Stop `#close` and `#disconnect` of a `:fd` polling producer from writing a stray byte into a file or socket that reuses the poller pipe fd number.
9
+
3
10
  ## v2.10.10 (2026-11-10)
4
11
  - [Feature] Add the `partition_count_cache_ttl_ms` setting to configure the process-wide karafka-rdkafka partition count cache TTL (default `nil` leaves it untouched).
5
12
  - [Change] Require `karafka-rdkafka` `>=` `0.32.0`.
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- waterdrop (2.10.10)
5
- karafka-core (>= 2.5.12, < 3.0.0)
4
+ waterdrop (2.10.11)
5
+ karafka-core (>= 2.6.8, < 3.0.0)
6
6
  karafka-rdkafka (>= 0.32.0)
7
7
  zeitwerk (~> 2.3)
8
8
 
@@ -13,7 +13,7 @@ GEM
13
13
  drb (2.2.3)
14
14
  ffi (1.17.4)
15
15
  json (3.1.0)
16
- karafka-core (2.6.6)
16
+ karafka-core (2.6.8)
17
17
  karafka-rdkafka (>= 0.20.0)
18
18
  logger (>= 1.6.0)
19
19
  karafka-rdkafka (0.32.0)
@@ -56,7 +56,7 @@ CHECKSUMS
56
56
  drb (2.2.3) sha256=0b00d6fdb50995fe4a45dea13663493c841112e4068656854646f418fda13373
57
57
  ffi (1.17.4) sha256=bcd1642e06f0d16fc9e09ac6d49c3a7298b9789bcb58127302f934e437d60acf
58
58
  json (3.1.0) sha256=3ce7ccf8fde58960177a3a756c31f292a4c1e1dedee884547096a5b0604e3bd8
59
- karafka-core (2.6.6) sha256=be14a9898c2133eecf1e2edefbdc127d105d902360d93c4ce63328ad8e74a440
59
+ karafka-core (2.6.8) sha256=6a1fdacedc89148068db8f89550925d7ee5f1781fbed12374e92530a7db424ce
60
60
  karafka-rdkafka (0.32.0) sha256=07983e15df25e69c958b991fe50ea85f2b6170821816eb05248f77a9de7ffa2b
61
61
  logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
62
62
  mini_portile2 (2.8.9) sha256=0cd7c7f824e010c072e33f68bc02d85a00aeb6fce05bb4819c03dfd3c140c289
@@ -68,7 +68,7 @@ CHECKSUMS
68
68
  ruby2_keywords (0.0.5) sha256=ffd13740c573b7301cf7a2e61fc857b2a8e3d3aff32545d6f8300d8bae10e3ef
69
69
  simplecov (1.3.2) sha256=2a22ec1759f1b8db60881a2e038758956fc69ef93ed669be0bde0678de6d0e85
70
70
  warning (1.6.0) sha256=a49cdfae19fb77d19afff2efbe45f8ab759e9cd25b4e4ce2c79dbaf46bdb6c9e
71
- waterdrop (2.10.10)
71
+ waterdrop (2.10.11)
72
72
  zeitwerk (2.8.3) sha256=2c85125a8467ce069e20123d1e709a08955c9d29c118c25b46b7b7fafdbb92e5
73
73
 
74
74
  BUNDLED WITH
@@ -19,6 +19,7 @@ module WaterDrop
19
19
  # @param client [Rdkafka::Producer] the rdkafka client
20
20
  # @raise [StandardError] if enable_queue_io_events fails
21
21
  def initialize(client)
22
+ @client = client
22
23
  @reader, @writer = IO.pipe
23
24
 
24
25
  # Tell librdkafka to write to our pipe when events arrive on the main queue
@@ -42,14 +43,29 @@ module WaterDrop
42
43
  # Pipe closed during drain
43
44
  end
44
45
 
45
- # Closes both ends of the pipe
46
+ # Disables librdkafka queue IO events and closes both ends of the pipe
47
+ #
48
+ # @note The IO events must be disabled before the pipe is closed. librdkafka keeps the
49
+ # writer fd number and writes to it whenever an op lands on the queue (statistics,
50
+ # errors, delivery reports during destroy). Once the pipe is closed, that number can be
51
+ # reused by any file or socket opened in this process, which would then get the payload.
46
52
  def close
53
+ disable_queue_io_events
47
54
  close_io(@reader)
48
55
  close_io(@writer)
49
56
  end
50
57
 
51
58
  private
52
59
 
60
+ # Tells librdkafka to stop writing to our pipe (fd -1 disables the IO events)
61
+ def disable_queue_io_events
62
+ return if @writer.closed?
63
+
64
+ @client.enable_queue_io_events(-1)
65
+ rescue Rdkafka::ClosedInnerError, Rdkafka::ClosedProducerError
66
+ # Client already closed, librdkafka no longer holds our fd
67
+ end
68
+
53
69
  # Safely closes an IO object
54
70
  # @param io [IO] the IO to close
55
71
  def close_io(io)
@@ -21,7 +21,7 @@ module WaterDrop
21
21
  "message.produced_async",
22
22
  producer_id: id,
23
23
  message: message
24
- ) { produce(message, "produce_async") }
24
+ ) { dispatch(message, "produce_async") }
25
25
  rescue *SUPPORTED_FLOW_ERRORS => e
26
26
  # We use this syntax here because we want to preserve the original `#cause` when we
27
27
  # instrument the error and there is no way to manually assign `#cause` value
@@ -40,6 +40,8 @@ module WaterDrop
40
40
  end
41
41
  end
42
42
 
43
+ alias_method :produce, :produce_async
44
+
43
45
  # Produces many messages to Kafka and does not wait for them to be delivered
44
46
  #
45
47
  # @param messages [Array<Hash>] array with messages that comply with the
@@ -67,7 +69,7 @@ module WaterDrop
67
69
  ) do
68
70
  with_transaction_if_transactional do
69
71
  messages.each do |message|
70
- dispatched << produce(message, "produce_many_async")
72
+ dispatched << dispatch(message, "produce_many_async")
71
73
  end
72
74
  end
73
75
 
@@ -89,6 +91,8 @@ module WaterDrop
89
91
  rescue Errors::ProducerClosedError => e
90
92
  raise Errors::ProducerClosedError.new(e.message, dispatched: dispatched)
91
93
  end
94
+
95
+ alias_method :produce_many, :produce_many_async
92
96
  end
93
97
  end
94
98
  end
@@ -70,9 +70,11 @@ module WaterDrop
70
70
  "buffer.flushed_async",
71
71
  producer_id: id,
72
72
  messages: messages
73
- ) { flush(false) }
73
+ ) { flush_buffer(false) }
74
74
  end
75
75
 
76
+ alias_method :flush, :flush_async
77
+
76
78
  # Flushes the internal buffer to Kafka in a sync way
77
79
  # @return [Array<Rdkafka::Producer::DeliveryHandle>] delivery handles for messages that were
78
80
  # flushed (handles are in final state, call `#create_result` to get delivery report)
@@ -81,9 +83,11 @@ module WaterDrop
81
83
  "buffer.flushed_sync",
82
84
  producer_id: id,
83
85
  messages: messages
84
- ) { flush(true) }
86
+ ) { flush_buffer(true) }
85
87
  end
86
88
 
89
+ alias_method :flush!, :flush_sync
90
+
87
91
  private
88
92
 
89
93
  # Method for triggering the buffer
@@ -94,7 +98,7 @@ module WaterDrop
94
98
  # @raise [Errors::ProducerClosedError] when the producer got closed during flushing
95
99
  # @note We use this method underneath to provide a different instrumentation for sync and
96
100
  # async flushing within the public API
97
- def flush(sync)
101
+ def flush_buffer(sync)
98
102
  fresh = nil
99
103
  requeued = nil
100
104
  data_for_dispatch = []
@@ -10,7 +10,9 @@ module WaterDrop
10
10
  return true if transactional?
11
11
  return @idempotent unless @idempotent.nil?
12
12
 
13
- @idempotent = config.kafka.to_h.fetch(:"enable.idempotence", false)
13
+ @idempotent = ::Karafka::Core::Helpers::Kafka::Config.enabled?(
14
+ config.kafka.to_h[:"enable.idempotence"]
15
+ )
14
16
  end
15
17
 
16
18
  # Checks if the given error should trigger an idempotent producer reload
@@ -62,7 +64,7 @@ module WaterDrop
62
64
  # them, but a thread that waited here may arrive after another has already reloaded -
63
65
  # resetting @client to nil and moving the producer to the configured state. Running
64
66
  # reload! again would call methods on a nil @client and raise NoMethodError, so we bail
65
- # out and let #produce retry against the freshly reloaded client. This mirrors the
67
+ # out and let #produce_to_client retry against the freshly reloaded client. This mirrors the
66
68
  # `return if @status.configured?` guard on the transactional reload path.
67
69
  next if @client.nil? || @status.configured?
68
70
 
@@ -24,7 +24,7 @@ module WaterDrop
24
24
  producer_id: id,
25
25
  message: message
26
26
  ) do
27
- wait(produce(message, "produce_sync"))
27
+ wait(dispatch(message, "produce_sync"))
28
28
  end
29
29
  rescue *SUPPORTED_FLOW_ERRORS => e
30
30
  # We use this syntax here because we want to preserve the original `#cause` when we
@@ -44,6 +44,8 @@ module WaterDrop
44
44
  end
45
45
  end
46
46
 
47
+ alias_method :produce!, :produce_sync
48
+
47
49
  # Produces many messages to Kafka and waits for them to be delivered
48
50
  #
49
51
  # @param messages [Array<Hash>] array with messages that comply with the
@@ -89,7 +91,7 @@ module WaterDrop
89
91
  begin
90
92
  with_transaction_if_transactional do
91
93
  messages.each do |message|
92
- dispatched << produce(message, "produce_many_sync")
94
+ dispatched << dispatch(message, "produce_many_sync")
93
95
  end
94
96
  end
95
97
  rescue *SUPPORTED_FLOW_ERRORS => e
@@ -133,6 +135,8 @@ module WaterDrop
133
135
  rescue Errors::ProducerClosedError => e
134
136
  raise Errors::ProducerClosedError.new(e.message, dispatched: dispatched)
135
137
  end
138
+
139
+ alias_method :produce_many!, :produce_many_sync
136
140
  end
137
141
  end
138
142
  end
@@ -25,6 +25,8 @@ module WaterDrop
25
25
  produce_sync(prepare_tombstone(message))
26
26
  end
27
27
 
28
+ alias_method :tombstone!, :tombstone_sync
29
+
28
30
  # Produces a tombstone message to Kafka and does not wait for results
29
31
  #
30
32
  # @param message [Hash] hash with at least `:topic`, `:key`, and `:partition` keys.
@@ -37,6 +39,8 @@ module WaterDrop
37
39
  produce_async(prepare_tombstone(message))
38
40
  end
39
41
 
42
+ alias_method :tombstone, :tombstone_async
43
+
40
44
  # Produces many tombstone messages to Kafka and waits for them to be delivered
41
45
  #
42
46
  # @param messages [Array<Hash>] array of hashes, each with `:topic`, `:key`, and
@@ -49,6 +53,8 @@ module WaterDrop
49
53
  produce_many_sync(messages.map { |message| prepare_tombstone(message) })
50
54
  end
51
55
 
56
+ alias_method :tombstone_many!, :tombstone_many_sync
57
+
52
58
  # Produces many tombstone messages to Kafka and does not wait for them to be delivered
53
59
  #
54
60
  # @param messages [Array<Hash>] array of hashes, each with `:topic`, `:key`, and
@@ -61,6 +67,8 @@ module WaterDrop
61
67
  produce_many_async(messages.map { |message| prepare_tombstone(message) })
62
68
  end
63
69
 
70
+ alias_method :tombstone_many, :tombstone_many_async
71
+
64
72
  private
65
73
 
66
74
  # Validates and prepares a tombstone message by ensuring required keys are present
@@ -17,10 +17,14 @@ module WaterDrop
17
17
  # Local storage for given thread waterdrop client references for variants
18
18
  ::Fiber.send(:attr_accessor, :waterdrop_clients)
19
19
 
20
+ # Marks an `Rdkafka::Config::ConfigError` raised by a dispatch (invalid variant `topic_config`).
21
+ DispatchConfigFailure = Module.new
22
+
20
23
  # Which of the inline flow errors do we want to intercept and re-bind
21
24
  SUPPORTED_FLOW_ERRORS = [
22
25
  Rdkafka::RdkafkaError,
23
- Rdkafka::Producer::DeliveryHandle::WaitTimeoutError
26
+ Rdkafka::Producer::DeliveryHandle::WaitTimeoutError,
27
+ DispatchConfigFailure
24
28
  ].freeze
25
29
 
26
30
  # Empty hash to save on memory allocations
@@ -30,7 +34,7 @@ module WaterDrop
30
34
  EMPTY_ARRAY = [].freeze
31
35
 
32
36
  private_constant(
33
- :SUPPORTED_FLOW_ERRORS, :EMPTY_HASH, :EMPTY_ARRAY
37
+ :DispatchConfigFailure, :SUPPORTED_FLOW_ERRORS, :EMPTY_HASH, :EMPTY_ARRAY
34
38
  )
35
39
 
36
40
  def_delegators :config
@@ -452,7 +456,7 @@ module WaterDrop
452
456
  # `error.occurred` instrumentation emitted by the dispatch itself, so swallowing the
453
457
  # re-raised wrapper here does not hide it.
454
458
  begin
455
- flush(true)
459
+ flush_buffer(true)
456
460
  rescue Errors::ProduceError
457
461
  nil
458
462
  end
@@ -619,7 +623,7 @@ module WaterDrop
619
623
  #
620
624
  # For a transactional producer we wrap the whole dispatch (including the operations-counter
621
625
  # bookkeeping) in `transaction`, so `@transaction_mutex` is acquired BEFORE
622
- # `@operations_in_progress` is incremented. This makes `#produce` acquire locks in the same
626
+ # `@operations_in_progress` is incremented. This makes `#dispatch` acquire locks in the same
623
627
  # order as `#close` (`@transaction_mutex` -> `@operating_mutex` -> operations counter) and
624
628
  # removes a lock-order inversion: without it, a dispatch that had already counted itself could
625
629
  # block forever on `@transaction_mutex` held by a concurrent `#close` that was itself waiting
@@ -632,7 +636,7 @@ module WaterDrop
632
636
  # we surface in the `message.*` queue-full error type. Passed explicitly by each public entry
633
637
  # point so we never have to walk the call stack to recover it (the number of internal frames
634
638
  # varies because the transactional path wraps the dispatch in a `transaction`).
635
- def produce(message, label)
639
+ def dispatch(message, label)
636
640
  if transactional? && !@transaction_mutex.owned?
637
641
  transaction { produce_to_client(message, label) }
638
642
  else
@@ -673,10 +677,21 @@ module WaterDrop
673
677
  message[:topic_config] ||= variant.topic_config
674
678
  end
675
679
 
676
- result = if transactional?
677
- transaction { client.produce(**message) }
678
- else
679
- client.produce(**message)
680
+ # Built before the rescue below, so an invalid `kafka` config raises as it is. The
681
+ # transactional branch takes the client again under the transaction lock, as a transactional
682
+ # reload done while this thread waits for that lock replaces it
683
+ rd_client = client
684
+
685
+ result = begin
686
+ if transactional?
687
+ transaction { client.produce(**message) }
688
+ else
689
+ rd_client.produce(**message)
690
+ end
691
+ rescue Rdkafka::Config::ConfigError => e
692
+ e.extend(DispatchConfigFailure)
693
+
694
+ raise
680
695
  end
681
696
 
682
697
  # Remember the first delivery handle of the current transaction. Aborting while the very first
@@ -715,7 +730,7 @@ module WaterDrop
715
730
  rescue SUPPORTED_FLOW_ERRORS.first => e
716
731
  # Check if this is a fatal error on an idempotent producer and we should reload.
717
732
  #
718
- # We must never reload while closing. During `#close` the final `flush` runs while this
733
+ # We must never reload while closing. During `#close` the final `flush_buffer` runs while this
719
734
  # thread already owns `@operating_mutex`; the idempotent reload re-acquires that same mutex,
720
735
  # which Ruby rejects with `ThreadError: deadlock; recursive locking`, and it would also try to
721
736
  # rebuild the very client we are tearing down. In that case we let the error propagate so
@@ -2,5 +2,5 @@
2
2
 
3
3
  module WaterDrop
4
4
  # Current WaterDrop version
5
- VERSION = "2.10.10"
5
+ VERSION = "2.10.11"
6
6
  end
data/waterdrop.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.description = spec.summary
17
17
  spec.licenses = %w[LGPL-3.0-only Commercial]
18
18
 
19
- spec.add_dependency "karafka-core", ">= 2.5.12", "< 3.0.0"
19
+ spec.add_dependency "karafka-core", ">= 2.6.8", "< 3.0.0"
20
20
  spec.add_dependency "karafka-rdkafka", ">= 0.32.0"
21
21
  spec.add_dependency "zeitwerk", "~> 2.3"
22
22
 
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.10
4
+ version: 2.10.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -15,7 +15,7 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 2.5.12
18
+ version: 2.6.8
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
21
  version: 3.0.0
@@ -25,7 +25,7 @@ dependencies:
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: 2.5.12
28
+ version: 2.6.8
29
29
  - - "<"
30
30
  - !ruby/object:Gem::Version
31
31
  version: 3.0.0