waterdrop 2.4.4 → 2.4.5

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: e260fd0633bf1672fc6f84613d9cf47722d68112dbcc8575f1dca40a2628401b
4
- data.tar.gz: 9528c011ffb175a22b34d59808dee41b735a008fca09f839b4a6418c2e198a2c
3
+ metadata.gz: e1cabe8225d1038bc9fab5c41efaf5822b3d6a633dac233f92058874be8cb5ae
4
+ data.tar.gz: ac830393a2c6ed2d50042a08fbd59a6d2ebbd0de505a53953c67b3d50ac1dd22
5
5
  SHA512:
6
- metadata.gz: d1021407b74f56a864cb06013c31303a5485b7ef85e1c7214374f679cc7a9c0a04a59e3600d56b1f36929af9870ff3997f4fac320a01e9c4a1256453142c6a8b
7
- data.tar.gz: 2bcf613fa8be571699534cdd5fb08fe3665024cb2767096d2ba343f6965ec1a5c7db50bdb45fb078931b0eff2572e0176604b667af35d2c1f87d2ce8e508e583
6
+ metadata.gz: d757751cb8a62fee91c5aff7ac30260e3b45d62d17db71eedcd23b77881b4564b8dc0bef534eb060049a65b5d99610c09c86eeb13913a999d864dffc3adee5e3
7
+ data.tar.gz: 51cb53cc3a4f168b3157ad840157f2df8a9479381972fe0d8cc13b445449099373acd76d37cf0206ec35d625fb75723b3ab4a3e0c193413de9844c54106209c5
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # WaterDrop changelog
2
2
 
3
+ ## 2.4.5 (2022-12-10)
4
+ - Fix invalid error scope visibility.
5
+ - Cache partition count to improve messages production and lower stress on Kafka when `partition_key` is on.
6
+
3
7
  ## 2.4.4 (2022-12-09)
4
8
  - Add temporary patch on top of `rdkafka-ruby` to mitigate metadata fetch timeout failures.
5
9
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- waterdrop (2.4.4)
4
+ waterdrop (2.4.5)
5
5
  karafka-core (>= 2.0.6, < 3.0.0)
6
6
  zeitwerk (~> 2.3)
7
7
 
@@ -18,7 +18,7 @@ module WaterDrop
18
18
  attempt += 1
19
19
 
20
20
  super(*args)
21
- rescue Rdkafka::RdkafkaError => e
21
+ rescue ::Rdkafka::RdkafkaError => e
22
22
  raise unless e.code == :timed_out
23
23
  raise if attempt > 10
24
24
 
@@ -7,6 +7,25 @@ module WaterDrop
7
7
  module Rdkafka
8
8
  # Rdkafka::Producer patches
9
9
  module Producer
10
+ # Cache partitions count for 30 seconds
11
+ PARTITIONS_COUNT_TTL = 30_000
12
+
13
+ private_constant :PARTITIONS_COUNT_TTL
14
+
15
+ # @param args [Object] arguments accepted by the original rdkafka producer
16
+ def initialize(*args)
17
+ super
18
+
19
+ @_partitions_count_cache = Concurrent::Hash.new do |cache, topic|
20
+ topic_metadata = ::Rdkafka::Metadata.new(inner_kafka, topic).topics&.first
21
+
22
+ cache[topic] = [
23
+ now,
24
+ topic_metadata ? topic_metadata[:partition_count] : nil
25
+ ]
26
+ end
27
+ end
28
+
10
29
  # Adds a method that allows us to get the native kafka producer name
11
30
  #
12
31
  # In between rdkafka versions, there are internal changes that force us to add some extra
@@ -14,23 +33,49 @@ module WaterDrop
14
33
  #
15
34
  # @return [String] producer instance name
16
35
  def name
17
- unless @_native
36
+ @_name ||= ::Rdkafka::Bindings.rd_kafka_name(inner_kafka)
37
+ end
38
+
39
+ # This patch makes sure we cache the partition count for a given topic for given time
40
+ # This prevents us in case someone uses `partition_key` from querying for the count with
41
+ # each message. Instead we query once every 30 seconds at most
42
+ #
43
+ # @param topic [String] topic name
44
+ # @return [Integer] partition count for a given topic
45
+ def partition_count(topic)
46
+ closed_producer_check(__method__)
47
+
48
+ @_partitions_count_cache.delete_if do |_, cached|
49
+ now - cached.first > PARTITIONS_COUNT_TTL
50
+ end
51
+
52
+ @_partitions_count_cache[topic].last
53
+ end
54
+
55
+ # @return [FFI::Pointer] pointer to the raw librdkafka
56
+ def inner_kafka
57
+ unless @_inner_kafka
18
58
  version = ::Gem::Version.new(::Rdkafka::VERSION)
19
59
 
20
60
  if version < ::Gem::Version.new('0.12.0')
21
- @native = @native_kafka
61
+ @_inner_kafka = @native_kafka
22
62
  elsif version < ::Gem::Version.new('0.13.0.beta.1')
23
- @_native = @client.native
63
+ @_inner_kafka = @client.native
24
64
  else
25
- @_native = @native_kafka.inner
65
+ @_inner_kafka = @native_kafka.inner
26
66
  end
27
67
  end
28
68
 
29
- ::Rdkafka::Bindings.rd_kafka_name(@_native)
69
+ @_inner_kafka
70
+ end
71
+
72
+ # @return [Float] current clock time
73
+ def now
74
+ ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) * 1_000
30
75
  end
31
76
  end
32
77
  end
33
78
  end
34
79
  end
35
80
 
36
- ::Rdkafka::Producer.include ::WaterDrop::Patches::Rdkafka::Producer
81
+ ::Rdkafka::Producer.prepend ::WaterDrop::Patches::Rdkafka::Producer
@@ -3,5 +3,5 @@
3
3
  # WaterDrop library
4
4
  module WaterDrop
5
5
  # Current WaterDrop version
6
- VERSION = '2.4.4'
6
+ VERSION = '2.4.5'
7
7
  end
data.tar.gz.sig CHANGED
Binary file
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.4.4
4
+ version: 2.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -35,7 +35,7 @@ cert_chain:
35
35
  Qf04B9ceLUaC4fPVEz10FyobjaFoY4i32xRto3XnrzeAgfEe4swLq8bQsR3w/EF3
36
36
  MGU0FeSV2Yj7Xc2x/7BzLK8xQn5l7Yy75iPF+KP3vVmDHnNl
37
37
  -----END CERTIFICATE-----
38
- date: 2022-12-09 00:00:00.000000000 Z
38
+ date: 2022-12-10 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: karafka-core
metadata.gz.sig CHANGED
Binary file