Skip to content

Commit d6c9a52

Browse files
committed
fix formatting issues, increase binlog size between tests, and fix error messages
1 parent 70e3b76 commit d6c9a52

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

lib/lhm/chunker.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def initialize(migration, connection = nil, options = {})
3737
)
3838
end
3939

40-
4140
def handle_max_binlog_exceeded_error
4241
@throttler.backoff_stride
4342
end
@@ -126,6 +125,5 @@ def validate
126125
return if @chunk_finder.table_empty?
127126
@chunk_finder.validate
128127
end
129-
130128
end
131129
end

lib/lhm/throttler/time.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@ def initialize(options = {})
1818
@min_stride_size = options[:min_stride_size] || MIN_STRIDE_SIZE
1919

2020
if @backoff_reduction_factor >= 1 || @backoff_reduction_factor <= 0
21-
raise ArgumentError, 'backoff_reduction_factor must be between 0 and 1'
21+
raise ArgumentError, 'backoff_reduction_factor must be between greater than 0, and less than 1'
2222
end
2323

2424
if @min_stride_size < 1
25-
raise ArgumentError, 'min_stride_size must be greater than 0'
25+
raise ArgumentError, 'min_stride_size must be and integer greater than 0'
26+
end
27+
28+
if !@min_stride_size.is_a?(Integer)
29+
raise ArgumentError, 'min_stride_size must be an integer'
2630
end
2731

2832
if @min_stride_size > @stride
2933
raise ArgumentError, 'min_stride_size must be less than or equal to stride'
3034
end
3135
end
3236

33-
3437
def backoff_stride
3538
new_stride = (@stride * (1 - @backoff_reduction_factor)).to_i
3639

spec/integration/chunker_spec.rb

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@migration = Lhm::Migration.new(@origin, @destination)
1919
@logs = StringIO.new
2020
Lhm.logger = Logger.new(@logs)
21-
set_max_binlog_size(1024 * 1024 * 100) # not sure if this is needed (iirc tests rollback all db changes)
21+
set_max_binlog_size(1024 * 1024 * 1024) # necessary since some tests recude binlog size (1gb default)
2222
end
2323

2424
def log_messages
@@ -310,11 +310,8 @@ def throttler.replica_connection(replica)
310310
end
311311

312312
it 'should reduce stride size if chunker runs into max_binlog_cache_size error' do
313-
314313
init_stride = 1000
315314

316-
317-
318315
# Create a bunch of users
319316
n = 0
320317
25.times do |i|
@@ -328,45 +325,41 @@ def throttler.replica_connection(replica)
328325
execute "COMMIT"
329326
end
330327

331-
332328
# reduce binlog size to 8kb
333329
set_max_binlog_size(1024 * 8)
334330

335-
336331
throttler = Lhm::Throttler::Time.new(stride: init_stride )
337-
338332
chunker = Lhm::Chunker.new(
339333
@migration, connection, { throttler: throttler }
340-
)
341-
334+
)
342335

343336
# start chunking
344337
chunker.run
345338
assert init_stride > throttler.stride
346339
end
347340

348-
it 'should throw an error when stride cannot be reduced beyond min stride size' do
349341

350-
init_stride = 1000
342+
it 'should throw an error when stride cannot be reduced beyond min stride size' do
343+
init_stride = 100
351344
min_stride_size = 50
352345

353346
# Create a bunch of users
354347
n = 0
355348
25.times do |i|
356349
execute "BEGIN"
357-
init_stride.times do # each batch is 10 * 1000 * i bytes, so each batch of 1000 will range from 10kb - 250kb
350+
init_stride.times do # each batch is init_stride * 250 bytes, so even at min_stride of 20,
351+
# batch_size will be greater than 4kb (50 * 250kb = 12.5kb)
358352
n += 1
359353
id = n
360-
username_data = "a" * 10 * 25
354+
username_data = "a" * 250
361355
execute "insert into origin (id, common) values (#{id}, '#{username_data}')"
362356
end
363357
execute "COMMIT"
364358
end
365359

366-
367360
# reduce binlog size to 4kb
368361
set_max_binlog_size(1024 * 4)
369-
throttler = Lhm::Throttler::Time.new(stride: init_stride, min_stride_size: min_stride_size, backoff_reduction_factor: 0.5)
362+
throttler = Lhm::Throttler::Time.new(stride: init_stride, min_stride_size: min_stride_size, backoff_reduction_factor: 0.9)
370363

371364
chunker = Lhm::Chunker.new(
372365
@migration, connection, { throttler: throttler }
@@ -379,7 +372,6 @@ def throttler.replica_connection(replica)
379372

380373
assert RuntimeError = exception.class
381374
assert "Cannot reduce stride below #{min_stride_size}" == exception.message
382-
383375
end
384376
end
385377

spec/unit/throttler_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def @instance.timeout_seconds
140140
end
141141
end
142142

143-
it 'should throw an error when backoff reduction factor is greater than zero' do
143+
it 'should throw an error when backoff reduction factor is not greater than zero' do
144144
assert_raises ArgumentError do
145145
@mock.setup_throttler(:time_throttler, backoff_reduction_factor: 0)
146146
end
@@ -152,12 +152,18 @@ def @instance.timeout_seconds
152152
end
153153
end
154154

155-
it 'should throw an error when min_stride_size is less than 1' do
155+
it 'should throw an error when min_stride_size is not an integer' do
156156
assert_raises ArgumentError do
157157
@mock.setup_throttler(:time_throttler, min_stride_size: 0.5)
158158
end
159159
end
160160

161+
it 'should throw an error when min_stride_size is not greater than 1' do
162+
assert_raises ArgumentError do
163+
@mock.setup_throttler(:time_throttler, min_stride_size: -12)
164+
end
165+
end
166+
161167
it 'should throw an error when min_stride_size is greater than inital stride size' do
162168
assert_raises ArgumentError do
163169
@mock.setup_throttler(:time_throttler, min_stride_size: 1000, stride: 500)

0 commit comments

Comments
 (0)