work_shaper 0.1.3.1rc4 → 0.1.3.1rc6

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: 883a72259f3ae672a2456139e8b309da4cb72be8ae36e85293a4dfc5a21ad502
4
- data.tar.gz: 4fa2fc7b182c6865fd4d761548676a7ada9ae903264f76056d317d90bd7607e2
3
+ metadata.gz: b86b6e151780b23abcdeb4c148775a3344f2b41a0da426f9ff0da148eca1ea5a
4
+ data.tar.gz: 4af867aee488107d5e934fe02c844a4c2f0b6548305bea935bc8b32b143c2808
5
5
  SHA512:
6
- metadata.gz: b4caa694ff8cf25082c05bea23b37254ff0d57bd6bbaa1b0a2eb081ceedca2c935dd395c3bfa01640d4ab635ab72535fc81d40d725cfe16ab933e1a8c367a0a5
7
- data.tar.gz: 7106024e8f782582836661ad809dd3d033464cb6c2daa68c1e8e10764ea74eeffcf6b688cbdc9c43f93203e750bb3486bbbd24ac89cbbaffeec98a9808d9b5f1
6
+ metadata.gz: 8cb3139f6e36a665bbcfad2291c11d6e785c4c41df11ab8cc69b35111a5b897da12fe13ac6fc2f5cfac55a6673314256b4bd2215171c722ba6b7c3299ab77c2a
7
+ data.tar.gz: 8342797e7b562d0fd8be90c802a8d83c4e480c81311e4474a9e78ce911d7f83bb15dbbb01c63d4a1394b5b40dc6e7a5223d499eb0a505ba2538a9e4836eacce9
@@ -25,7 +25,6 @@ module WorkShaper
25
25
  @workers = {}
26
26
  @last_ack = {}
27
27
  @received_offsets = {}
28
- @completed_offsets = {}
29
28
  @max_in_queue = max_in_queue
30
29
  @semaphore = Mutex.new
31
30
  @shutting_down = false
@@ -45,7 +44,7 @@ module WorkShaper
45
44
 
46
45
  @offset_manager = Thread.new do
47
46
  while true
48
- @completed_offsets.each_key do |partition|
47
+ @received_offsets.each_key do |partition|
49
48
  offset_ack(partition)
50
49
  end
51
50
  sleep offset_commit_period_ms / 1000.0
@@ -77,7 +76,6 @@ module WorkShaper
77
76
  method(:offset_ack),
78
77
  @on_error,
79
78
  @last_ack,
80
- @completed_offsets,
81
79
  @semaphore,
82
80
  @max_in_queue
83
81
  )
@@ -91,7 +89,7 @@ module WorkShaper
91
89
  # the consumer restarts.
92
90
  def flush(safe: true)
93
91
  sleep 5
94
- @completed_offsets.each_key do |k|
92
+ @received_offsets.each_key do |k|
95
93
  safe ? offset_ack(k) : offset_ack_unsafe(k)
96
94
  end
97
95
  end
@@ -137,12 +135,11 @@ module WorkShaper
137
135
  end
138
136
 
139
137
  def offset_ack_unsafe(partition)
140
- completed = @completed_offsets[partition].sort!
141
138
  received = @received_offsets[partition].sort!
142
139
 
143
140
  begin
144
- offset = completed.first
145
- while received.any? && received.first == offset
141
+ offset = received.first
142
+ while offset && offset.completed?
146
143
  # We observed Kafka sending the same message twice, even after
147
144
  # having committed the offset. Here we skip this offset if we
148
145
  # know it has already been committed.
@@ -172,7 +169,6 @@ module WorkShaper
172
169
  WorkShaper.logger.warn(
173
170
  { message: 'Failed to Ack Offset, likely re-balance',
174
171
  offset: "#{partition}:#{offset}",
175
- completed: @completed_offsets[partition].to_a[0..10].join(','),
176
172
  received: @received_offsets[partition].to_a[0..10].join(',')
177
173
  })
178
174
  else
@@ -181,12 +177,10 @@ module WorkShaper
181
177
 
182
178
  @total_acked += 1
183
179
  WorkShaper.logger.debug "@total_acked: #{@total_acked}"
184
- WorkShaper.logger.debug "completed: [#{completed.join(', ')}]"
185
180
  WorkShaper.logger.debug "received: [#{received.join(', ')}]"
186
- completed.delete(offset)
187
181
  received.delete(offset)
188
182
 
189
- offset = completed.first
183
+ offset = received.first
190
184
  end
191
185
  rescue => e
192
186
  WorkShaper.logger.error({ message: 'Error in offset_ack', error: e })
@@ -24,14 +24,14 @@ module WorkShaper
24
24
 
25
25
  if r == 0
26
26
  r = STATES[state] <=> STATES[other.state]
27
- puts "States: #{r} | #{STATES[state]} #{STATES[other.state]}"
27
+ WorkShaper.logger.debug "States: #{r} | #{STATES[state]} #{STATES[other.state]}"
28
28
  end
29
29
 
30
30
  if r == 0
31
31
  r = @at <=> other.instance_variable_get(:@at)
32
- puts "At: #{r}"
32
+ WorkShaper.logger.debug "At: #{r}"
33
33
  end
34
- puts "Final: #{r}"
34
+ WorkShaper.logger.debug "Final: #{r}"
35
35
  r
36
36
  end
37
37
 
@@ -43,6 +43,10 @@ module WorkShaper
43
43
  @state = :completed
44
44
  end
45
45
 
46
+ def completed?
47
+ @state == :completed
48
+ end
49
+
46
50
  def to_i
47
51
  offset
48
52
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WorkShaper
4
- VERSION = "0.1.3.1rc4"
4
+ VERSION = "0.1.3.1rc6"
5
5
  end
@@ -6,14 +6,13 @@ module WorkShaper
6
6
  # @param work [Lambda] Lambda that we will #call(message) to execute work.
7
7
  # @param on_done [Lambda] Lambda that we #call(partition, offset) when work is done.
8
8
  # @param on_error [Lambda] Lambda that we #call(exception) if an error is encountered.
9
- def initialize(work, on_done, ack_handler, on_error, last_ack, offset_stack, semaphore, max_in_queue)
9
+ def initialize(work, on_done, ack_handler, on_error, last_ack, semaphore, max_in_queue)
10
10
  @jobs = []
11
11
  @work = work
12
12
  @on_done = on_done
13
13
  @ack_handler = ack_handler
14
14
  @on_error = on_error
15
15
  @last_ack = last_ack
16
- @completed_offsets = offset_stack
17
16
  @semaphore = semaphore
18
17
  @max_in_queue = max_in_queue
19
18
  @thread_pool = Concurrent::FixedThreadPool.new(1, auto_terminate: false)
@@ -38,7 +37,6 @@ module WorkShaper
38
37
  @semaphore.synchronize do
39
38
  WorkShaper.logger.debug "Completed: #{partition}:#{offset}"
40
39
  offset_holder.complete!
41
- (@completed_offsets[partition] ||= Array.new) << offset_holder
42
40
  end
43
41
  end
44
42
  # rubocop:enable Style/RescueStandardError
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: work_shaper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3.1rc4
4
+ version: 0.1.3.1rc6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerry Fernholz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-21 00:00:00.000000000 Z
11
+ date: 2024-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby