karafka-rdkafka 0.14.3 → 0.14.4

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: 5fee43511074dfab207280d7114f70f8fb5cc7b6055fdb348cd9da302ee037d2
4
- data.tar.gz: 22656cc0b49a6d3aa7d6fad85c1b3c936b49089802ed07f4f43d8fdd85a16f2d
3
+ metadata.gz: d22e33d93f77f138063f03111b25386c08e1667012b6ab4c8449fef61754ad44
4
+ data.tar.gz: b8cc0557cbb945e5d7b7e025198a292a7cf601ce9decef97cb5102fd25af742b
5
5
  SHA512:
6
- metadata.gz: cdc7873ca1dda1d2afc6193c8e189850d5d3f865f19307cd997cc76c3fa39a919f2757ed610cf18854dc1ff61b270d1a9c85f880257c1c833435d7af9992a27a
7
- data.tar.gz: ed37156d9f17e8be5804720b426424260c3e70567cf2e24dc385ed5e8d66763199fb056a2c47e11fec1ff80ddaae8b2926f9420b05d1c9e88dc38735c32b4eb1
6
+ metadata.gz: cfc9af0e70030f513c4c34b00f9b94b6b3b9c828add2ac6cd742ebe2eb308a1e1a5489bf4c4280c34a98d2f0118d741608918314fa8f267b7cf98b22b3d8782d
7
+ data.tar.gz: 315b552a77691b62e5a30fd5eaec1bf89efd8ec5789f9f0deeadf3997eeca9dc83bb6466ee8365e40e53d2e09707d3d68a57278b3637b170ad027b5080838519
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Rdkafka Changelog
2
2
 
3
+ ## 0.14.4 (2023-12-19)
4
+ - [Enhancement] Add ability to store offsets in a transaction (mensfeld)
5
+
3
6
  ## 0.14.3 (2023-12-17)
4
7
  - [Enhancement] Replace `rd_kafka_offset_store` with `rd_kafka_offsets_store` (mensfeld)
5
8
  - [Fix] Missing ACL `RD_KAFKA_RESOURCE_BROKER` constant reference (mensfeld)
@@ -205,6 +205,9 @@ module Rdkafka
205
205
  attach_function :rd_kafka_seek, [:pointer, :int32, :int64, :int], :int, blocking: true
206
206
  attach_function :rd_kafka_offsets_for_times, [:pointer, :pointer, :int], :int, blocking: true
207
207
  attach_function :rd_kafka_position, [:pointer, :pointer], :int, blocking: true
208
+ # those two are used for eos support
209
+ attach_function :rd_kafka_consumer_group_metadata, [:pointer], :pointer, blocking: true
210
+ attach_function :rd_kafka_consumer_group_metadata_destroy, [:pointer], :void, blocking: true
208
211
 
209
212
  # Headers
210
213
  attach_function :rd_kafka_header_get_all, [:pointer, :size_t, :pointer, :pointer, SizePtr], :int
@@ -276,6 +279,7 @@ module Rdkafka
276
279
  callback :delivery_cb, [:pointer, :pointer, :pointer], :void
277
280
  attach_function :rd_kafka_conf_set_dr_msg_cb, [:pointer, :delivery_cb], :void
278
281
  attach_function :rd_kafka_init_transactions, [:pointer, :int], :pointer, blocking: true
282
+ attach_function :rd_kafka_send_offsets_to_transaction, [:pointer, :pointer, :pointer, :int], :pointer, blocking: true
279
283
  attach_function :rd_kafka_begin_transaction, [:pointer], :pointer, blocking: true
280
284
  attach_function :rd_kafka_abort_transaction, [:pointer, :int], :pointer, blocking: true
281
285
  attach_function :rd_kafka_commit_transaction, [:pointer, :int], :pointer, blocking: true
@@ -671,6 +671,22 @@ module Rdkafka
671
671
  end
672
672
  end
673
673
 
674
+ # Returns pointer to the consumer group metadata. It is used only in the context of
675
+ # exactly-once-semantics in transactions, this is why it is never remapped to Ruby
676
+ #
677
+ # This API is **not** usable by itself from Ruby
678
+ #
679
+ # @note This pointer **needs** to be removed with `#rd_kafka_consumer_group_metadata_destroy`
680
+ #
681
+ # @private
682
+ def consumer_group_metadata_pointer
683
+ closed_consumer_check(__method__)
684
+
685
+ @native_kafka.with_inner do |inner|
686
+ Bindings.rd_kafka_consumer_group_metadata(inner)
687
+ end
688
+ end
689
+
674
690
  private
675
691
 
676
692
  def closed_consumer_check(method)
@@ -81,7 +81,7 @@ module Rdkafka
81
81
  @native_kafka.with_inner do |inner|
82
82
  response_ptr = Rdkafka::Bindings.rd_kafka_begin_transaction(inner)
83
83
 
84
- Rdkafka::RdkafkaError.validate!(response_ptr)
84
+ Rdkafka::RdkafkaError.validate!(response_ptr) || true
85
85
  end
86
86
  end
87
87
 
@@ -91,7 +91,7 @@ module Rdkafka
91
91
  @native_kafka.with_inner do |inner|
92
92
  response_ptr = Rdkafka::Bindings.rd_kafka_commit_transaction(inner, timeout_ms)
93
93
 
94
- Rdkafka::RdkafkaError.validate!(response_ptr)
94
+ Rdkafka::RdkafkaError.validate!(response_ptr) || true
95
95
  end
96
96
  end
97
97
 
@@ -100,8 +100,35 @@ module Rdkafka
100
100
 
101
101
  @native_kafka.with_inner do |inner|
102
102
  response_ptr = Rdkafka::Bindings.rd_kafka_abort_transaction(inner, timeout_ms)
103
+ Rdkafka::RdkafkaError.validate!(response_ptr) || true
104
+ end
105
+ end
106
+
107
+ # Sends provided offsets of a consumer to the transaction for collective commit
108
+ #
109
+ # @param consumer [Consumer] consumer that owns the given tpls
110
+ # @param tpl [Consumer::TopicPartitionList]
111
+ # @param timeout_ms [Integer] offsets send timeout
112
+ # @note Use **only** in the context of an active transaction
113
+ def send_offsets_to_transaction(consumer, tpl, timeout_ms = 5_000)
114
+ closed_producer_check(__method__)
115
+
116
+ return if tpl.empty?
117
+
118
+ cgmetadata = consumer.consumer_group_metadata_pointer
119
+ native_tpl = tpl.to_native_tpl
120
+
121
+ @native_kafka.with_inner do |inner|
122
+ response_ptr = Bindings.rd_kafka_send_offsets_to_transaction(inner, native_tpl, cgmetadata, timeout_ms)
123
+
103
124
  Rdkafka::RdkafkaError.validate!(response_ptr)
104
125
  end
126
+ ensure
127
+ if cgmetadata && !cgmetadata.null?
128
+ Bindings.rd_kafka_consumer_group_metadata_destroy(cgmetadata)
129
+ end
130
+
131
+ Rdkafka::Bindings.rd_kafka_topic_partition_list_destroy(native_tpl) unless native_tpl.nil?
105
132
  end
106
133
 
107
134
  # Close this producer and wait for the internal poll queue to empty.
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rdkafka
4
- VERSION = "0.14.3"
4
+ VERSION = "0.14.4"
5
5
  LIBRDKAFKA_VERSION = "2.3.0"
6
6
  LIBRDKAFKA_SOURCE_SHA256 = "2d49c35c77eeb3d42fa61c43757fcbb6a206daa560247154e60642bcdcc14d12"
7
7
  end
@@ -360,7 +360,6 @@ describe Rdkafka::Consumer do
360
360
  end
361
361
  end
362
362
 
363
-
364
363
  describe "#position, #commit, #committed and #store_offset" do
365
364
  # Make sure there are messages to work with
366
365
  let!(:report) do
@@ -1142,6 +1141,14 @@ describe Rdkafka::Consumer do
1142
1141
  end
1143
1142
  end
1144
1143
 
1144
+ describe '#consumer_group_metadata_pointer' do
1145
+ it 'expect to yield pointer' do
1146
+ consumer.consumer_group_metadata_pointer do |pointer|
1147
+ expect(pointer).to be_a(FFI::Pointer)
1148
+ end
1149
+ end
1150
+ end
1151
+
1145
1152
  describe "a rebalance listener" do
1146
1153
  let(:consumer) do
1147
1154
  config = rdkafka_consumer_config
@@ -883,5 +883,30 @@ describe Rdkafka::Producer do
883
883
  expect { producer2.commit_transaction }.not_to raise_error
884
884
  end
885
885
  end
886
+
887
+ context 'when having a consumer with tpls for exactly once semantics' do
888
+ let(:tpl) do
889
+ producer.produce(topic: 'consume_test_topic', payload: 'data1', partition: 0).wait
890
+ result = producer.produce(topic: 'consume_test_topic', payload: 'data1', partition: 0).wait
891
+
892
+ Rdkafka::Consumer::TopicPartitionList.new.tap do |list|
893
+ list.add_topic_and_partitions_with_offsets("consume_test_topic", 0 => result.offset + 1)
894
+ end
895
+ end
896
+
897
+ before do
898
+ consumer.subscribe("consume_test_topic")
899
+ wait_for_assignment(consumer)
900
+ producer.init_transactions
901
+ producer.begin_transaction
902
+ end
903
+
904
+ after { consumer.unsubscribe }
905
+
906
+ it 'expect to store offsets and not crash' do
907
+ producer.send_offsets_to_transaction(consumer, tpl)
908
+ producer.commit_transaction
909
+ end
910
+ end
886
911
  end
887
912
  end
data/spec/spec_helper.rb CHANGED
@@ -107,10 +107,6 @@ def wait_for_unassignment(consumer)
107
107
  end
108
108
  end
109
109
 
110
- def objects_of_type_count(type)
111
- ObjectSpace.each_object(type).count
112
- end
113
-
114
110
  def notify_listener(listener, &block)
115
111
  # 1. subscribe and poll
116
112
  consumer.subscribe("consume_test_topic")
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karafka-rdkafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.3
4
+ version: 0.14.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thijs Cadier
@@ -35,7 +35,7 @@ cert_chain:
35
35
  AnG1dJU+yL2BK7vaVytLTstJME5mepSZ46qqIJXMuWob/YPDmVaBF39TDSG9e34s
36
36
  msG3BiCqgOgHAnL23+CN3Rt8MsuRfEtoTKpJVcCfoEoNHOkc
37
37
  -----END CERTIFICATE-----
38
- date: 2023-12-17 00:00:00.000000000 Z
38
+ date: 2023-12-19 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: ffi
metadata.gz.sig CHANGED
Binary file