karafka 2.0.11 → 2.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00fdec9b351cb2da897d141a0dbb97816d7b0e53d7548b86d1ff48c5a8d5af3a
4
- data.tar.gz: 514964e409f4904932ee9e7cc1aa27094820d2cbe875c75ad49c82ce41b8afbf
3
+ metadata.gz: 2c407cd113e41314102fc910cf0b35e8081c55bdadae66635afe59491b58e390
4
+ data.tar.gz: 336dad28cc65218e33a2b3bc42b69a166ff4e8e6a10c65a435e57f75eca5ac90
5
5
  SHA512:
6
- metadata.gz: ba9281c9bfdb3a7a2a4c4121c26d1debb4bd39af07a190172a15f34705ee65bd9a1c8ce2e3773ccb3fe749dc83025bf96e0dde31664f1c6541e5923cad87b7a5
7
- data.tar.gz: 95f150e80a77f68c16f0ecce849403a7afdcaf50f67bdaa1471074173f8b27b5a6b66d8a5cda8c3dc39106d8153ba843a35c9123883dc803b7bb05ec2c1f47c3
6
+ metadata.gz: 82ffee28acdaa1d126944426a7b31628380fc04aca24002ea55067f6c80a0b72a885d246a656913ea35e79fa82a9d741c35125e31b75abbbf7fb0022360e3b2b
7
+ data.tar.gz: b64f9dc4fb2461f3cbe3a774231a661365af5b1be88a6c95b1543521d19d8171514eb5111f88ceb53e309b5ab433f982b9535c2bbb4919e4c07850570424605a
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Karafka framework changelog
2
2
 
3
+ ## 2.0.12 (2022-10-06)
4
+ - Commit stored offsets upon rebalance revocation event to reduce number of messages that are re-processed.
5
+ - Support cooperative-sticky rebalance strategy.
6
+ - Replace offset commit after each batch with a per-rebalance commit.
7
+ - User instrumentation to publish internal rebalance errors.
8
+
3
9
  ## 2.0.11 (2022-09-29)
4
10
  - Report early on errors related to network and on max poll interval being exceeded to indicate critical problems that will be retries but may mean some underlying problems in the system.
5
11
  - Fix support of Ruby 2.7.0 to 2.7.2 (#1045)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka (2.0.11)
4
+ karafka (2.0.12)
5
5
  karafka-core (>= 2.0.2, < 3.0.0)
6
6
  rdkafka (>= 0.12)
7
7
  thor (>= 0.20)
@@ -65,7 +65,7 @@ GEM
65
65
  karafka-core (>= 2.0.2, < 3.0.0)
66
66
  rdkafka (>= 0.10)
67
67
  zeitwerk (~> 2.3)
68
- zeitwerk (2.6.0)
68
+ zeitwerk (2.6.1)
69
69
 
70
70
  PLATFORMS
71
71
  x86_64-linux
@@ -118,10 +118,6 @@ module Karafka
118
118
  build_and_schedule_consumption_jobs
119
119
 
120
120
  wait
121
-
122
- # We don't use the `#commit_offsets!` here for performance reasons. This can be achieved
123
- # if needed by using manual offset management.
124
- @client.commit_offsets
125
121
  end
126
122
 
127
123
  # If we are stopping we will no longer schedule any jobs despite polling.
@@ -14,6 +14,9 @@ module Karafka
14
14
  # that are lost, are those that got revoked but did not get re-assigned back. We do not
15
15
  # expose this concept outside and we normalize to have them revoked, as it is irrelevant
16
16
  # from the rest of the code perspective as only those that are lost are truly revoked.
17
+ #
18
+ # @note For cooperative-sticky `#assigned_partitions` holds only the recently assigned
19
+ # partitions, not all the partitions that are owned
17
20
  class RebalanceManager
18
21
  # Empty array for internal usage not to create new objects
19
22
  EMPTY_ARRAY = [].freeze
@@ -0,0 +1,132 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Karafka
4
+ module Patches
5
+ module Rdkafka
6
+ # Binding patches that slightly change how rdkafka operates in certain places
7
+ module Bindings
8
+ include ::Rdkafka::Bindings
9
+
10
+ # Alias internally
11
+ RB = ::Rdkafka::Bindings
12
+
13
+ class << self
14
+ # Handle assignments on cooperative rebalance
15
+ #
16
+ # @param client_ptr [FFI::Pointer]
17
+ # @param code [Integer]
18
+ # @param partitions_ptr [FFI::Pointer]
19
+ def on_cooperative_rebalance(client_ptr, code, partitions_ptr)
20
+ case code
21
+ when RB::RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS
22
+ RB.rd_kafka_incremental_assign(client_ptr, partitions_ptr)
23
+ when RB::RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS
24
+ RB.rd_kafka_commit(client_ptr, nil, false)
25
+ RB.rd_kafka_incremental_unassign(client_ptr, partitions_ptr)
26
+ else
27
+ RB.rd_kafka_assign(client_ptr, FFI::Pointer::NULL)
28
+ end
29
+ end
30
+
31
+ # Handle assignments on a eager rebalance
32
+ #
33
+ # @param client_ptr [FFI::Pointer]
34
+ # @param code [Integer]
35
+ # @param partitions_ptr [FFI::Pointer]
36
+ def on_eager_rebalance(client_ptr, code, partitions_ptr)
37
+ case code
38
+ when RB::RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS
39
+ RB.rd_kafka_assign(client_ptr, partitions_ptr)
40
+ when RB::RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS
41
+ RB.rd_kafka_commit(client_ptr, nil, false)
42
+ RB.rd_kafka_assign(client_ptr, FFI::Pointer::NULL)
43
+ else
44
+ RB.rd_kafka_assign(client_ptr, FFI::Pointer::NULL)
45
+ end
46
+ end
47
+
48
+ # Trigger Karafka callbacks
49
+ #
50
+ # @param code [Integer]
51
+ # @param opaque [Rdkafka::Opaque]
52
+ # @param consumer [Rdkafka::Consumer]
53
+ # @param tpl [Rdkafka::Consumer::TopicPartitionList]
54
+ def trigger_callbacks(code, opaque, consumer, tpl)
55
+ case code
56
+ when RB::RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS
57
+ opaque.call_on_partitions_assigned(consumer, tpl)
58
+ when RB::RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS
59
+ opaque.call_on_partitions_revoked(consumer, tpl)
60
+ end
61
+ rescue StandardError => e
62
+ Karafka.monitor.instrument(
63
+ 'error.occurred',
64
+ caller: self,
65
+ error: e,
66
+ type: 'connection.client.rebalance_callback.error'
67
+ )
68
+ end
69
+ end
70
+
71
+ # This patch changes few things:
72
+ # - it commits offsets (if any) upon partition revocation, so less jobs need to be
73
+ # reprocessed if they are assigned to a different process
74
+ # - reports callback errors into the errors instrumentation instead of the logger
75
+ # - catches only StandardError instead of Exception as we fully control the directly
76
+ # executed callbacks
77
+ #
78
+ # @see https://docs.confluent.io/2.0.0/clients/librdkafka/classRdKafka_1_1RebalanceCb.html
79
+ RebalanceCallback = FFI::Function.new(
80
+ :void, %i[pointer int pointer pointer]
81
+ ) do |client_ptr, code, partitions_ptr, opaque_ptr|
82
+ # Patch reference
83
+ pr = ::Karafka::Patches::Rdkafka::Bindings
84
+
85
+ if RB.rd_kafka_rebalance_protocol(client_ptr) == 'COOPERATIVE'
86
+ pr.on_cooperative_rebalance(client_ptr, code, partitions_ptr)
87
+ else
88
+ pr.on_eager_rebalance(client_ptr, code, partitions_ptr)
89
+ end
90
+
91
+ opaque = ::Rdkafka::Config.opaques[opaque_ptr.to_i]
92
+ return unless opaque
93
+
94
+ tpl = ::Rdkafka::Consumer::TopicPartitionList.from_native_tpl(partitions_ptr).freeze
95
+ consumer = ::Rdkafka::Consumer.new(client_ptr)
96
+
97
+ pr.trigger_callbacks(code, opaque, consumer, tpl)
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ # We need to replace the original callback with ours.
105
+ # At the moment there is no API in rdkafka-ruby to do so
106
+ ::Rdkafka::Bindings.send(
107
+ :remove_const,
108
+ 'RebalanceCallback'
109
+ )
110
+
111
+ ::Rdkafka::Bindings.const_set(
112
+ 'RebalanceCallback',
113
+ Karafka::Patches::Rdkafka::Bindings::RebalanceCallback
114
+ )
115
+
116
+ ::Rdkafka::Bindings.attach_function(
117
+ :rd_kafka_rebalance_protocol,
118
+ %i[pointer],
119
+ :string
120
+ )
121
+
122
+ ::Rdkafka::Bindings.attach_function(
123
+ :rd_kafka_incremental_assign,
124
+ %i[pointer pointer],
125
+ :string
126
+ )
127
+
128
+ ::Rdkafka::Bindings.attach_function(
129
+ :rd_kafka_incremental_unassign,
130
+ %i[pointer pointer],
131
+ :string
132
+ )
@@ -3,5 +3,5 @@
3
3
  # Main module namespace
4
4
  module Karafka
5
5
  # Current Karafka version
6
- VERSION = '2.0.11'
6
+ VERSION = '2.0.12'
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: karafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.11
4
+ version: 2.0.12
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-09-29 00:00:00.000000000 Z
38
+ date: 2022-10-06 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: karafka-core
@@ -212,6 +212,7 @@ files:
212
212
  - lib/karafka/messages/messages.rb
213
213
  - lib/karafka/messages/metadata.rb
214
214
  - lib/karafka/messages/seek.rb
215
+ - lib/karafka/patches/rdkafka/bindings.rb
215
216
  - lib/karafka/patches/rdkafka/consumer.rb
216
217
  - lib/karafka/pro.rb
217
218
  - lib/karafka/pro/active_job/consumer.rb
metadata.gz.sig CHANGED
@@ -1,3 +1,2 @@
1
- a��Z���hR�h)�/Q��(ΊW�y�F�
2
- H]�mm�(����� C��#�����NJ^)d P���W�� q��Y���N��d��� 031x?�yb ��F��_ܥ�#p|�gοv��Jݤa ��h_���T��V��5v�/����5-�IM�fH���Әm��)�?�4@ ���c �����L��wg_e�ꁬ���33����39�����@�u��/��P�u�U�(d�0а�ZI�Y1 -�[��͸��hr�j������e2��q{��9������[�Y�)�2�d�wLu��9�G�
3
- �L���9V����~6�?�M�X�S0�~{�2�r%�j��dO_�z K5x� ���l�D������e+�:�q�%���
1
+ �JMT
2
+ 6���]�������˪�`�m/��Sݔ1`��#7�@���8x7|��d��W�pчHk.�9�<