lhm-teak 3.6.2 → 3.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/lhm/chunk_insert.rb +3 -3
- data/lib/lhm/chunker.rb +2 -0
- data/lib/lhm/id_set_chunk_finder.rb +3 -2
- data/lib/lhm/version.rb +1 -1
- data/spec/unit/id_set_chunk_finder_spec.rb +17 -17
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59c1ce06a43af4778d128caf1e9befb3a08ceb65def5b4504cbc79688f3fdc6e
|
4
|
+
data.tar.gz: f8caaafbf327cb89dd36723d8e3d42beab863d043cf42fdd103617f7ec57a4a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb7ad68e346dbafac173a3d500910aa679e669e01cf8f50843158b95ec7c606df06b1577738ba9835dc83768dd37a3455ad85099f0d0865e97a5fe808ce5d196
|
7
|
+
data.tar.gz: d17226a55fc7a20dff47bfa78bb7f392a4178fe1d71eef08702b01b591a98041575f299fcf4f77440c428164c732c840fc54b92b259148f5d1747b2d5f208ac7
|
data/Gemfile.lock
CHANGED
data/lib/lhm/chunk_insert.rb
CHANGED
@@ -6,12 +6,12 @@ module Lhm
|
|
6
6
|
|
7
7
|
LOG_PREFIX = "ChunkInsert"
|
8
8
|
|
9
|
-
def initialize(migration, connection, lowest, highest,
|
9
|
+
def initialize(migration, connection, lowest, highest, options = {})
|
10
10
|
@migration = migration
|
11
11
|
@connection = connection
|
12
12
|
@lowest = lowest
|
13
13
|
@highest = highest
|
14
|
-
@
|
14
|
+
@options = options
|
15
15
|
end
|
16
16
|
|
17
17
|
def insert_and_return_count_of_rows_created
|
@@ -27,7 +27,7 @@ module Lhm
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def expected_rows
|
30
|
-
top - bottom + 1
|
30
|
+
@options.fetch(:expected_rows, top - bottom + 1)
|
31
31
|
end
|
32
32
|
|
33
33
|
private
|
data/lib/lhm/chunker.rb
CHANGED
@@ -28,6 +28,7 @@ module Lhm
|
|
28
28
|
@throttler.connection = @connection if @throttler.respond_to?(:connection=)
|
29
29
|
end
|
30
30
|
@printer = options[:printer] || Printer::Percentage.new
|
31
|
+
@pause_before_switch = options[:pause_before_switch]
|
31
32
|
@retry_options = options[:retriable] || {}
|
32
33
|
@retry_helper = SqlRetry.new(
|
33
34
|
@connection,
|
@@ -62,6 +63,7 @@ module Lhm
|
|
62
63
|
@printer.notify(@chunk_finder.processed_rows, @chunk_finder.max_rows)
|
63
64
|
end
|
64
65
|
@printer.end
|
66
|
+
sleep @pause_before_switch if @pause_before_switch
|
65
67
|
rescue => e
|
66
68
|
@printer.exception(e) if @printer.respond_to?(:exception)
|
67
69
|
raise
|
@@ -23,9 +23,10 @@ module Lhm
|
|
23
23
|
@processed_rows = 0
|
24
24
|
while @processed_rows < ids.length
|
25
25
|
next_idx = [@processed_rows + @throttler.stride, @ids.length].min
|
26
|
-
|
26
|
+
range = @processed_rows...next_idx
|
27
|
+
ids_to_insert = ids[range]
|
27
28
|
@processed_rows = next_idx
|
28
|
-
yield
|
29
|
+
yield ChunkInsert.new(@migration, @connection, ids_to_insert[0], ids_to_insert[-1], expected_rows: range.count)
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
data/lib/lhm/version.rb
CHANGED
@@ -43,11 +43,11 @@ describe Lhm::IdSetChunkFinder do
|
|
43
43
|
|
44
44
|
@connection.expects(:select_values).with(regexp_matches(/order by id asc/),EXPECTED_RETRY_FLAGS_CHUNKER).returns((1..20).select(&:odd?))
|
45
45
|
|
46
|
-
@connection.expects(:update).with(regexp_matches(/`id`
|
47
|
-
@connection.expects(:update).with(regexp_matches(/`id`
|
48
|
-
@connection.expects(:update).with(regexp_matches(/`id`
|
49
|
-
@connection.expects(:update).with(regexp_matches(/`id`
|
50
|
-
@connection.expects(:update).with(regexp_matches(/`id`
|
46
|
+
@connection.expects(:update).with(regexp_matches(/`id` between 1 and 3/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(2)
|
47
|
+
@connection.expects(:update).with(regexp_matches(/`id` between 5 and 7/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(2)
|
48
|
+
@connection.expects(:update).with(regexp_matches(/`id` between 9 and 11/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(2)
|
49
|
+
@connection.expects(:update).with(regexp_matches(/`id` between 13 and 15/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(2)
|
50
|
+
@connection.expects(:update).with(regexp_matches(/`id` between 17 and 19/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(2)
|
51
51
|
|
52
52
|
@chunker.run
|
53
53
|
end
|
@@ -66,10 +66,10 @@ describe Lhm::IdSetChunkFinder do
|
|
66
66
|
|
67
67
|
@connection.expects(:select_values).with(regexp_matches(/order by id asc/),EXPECTED_RETRY_FLAGS_CHUNKER).returns((1..20).select(&:odd?))
|
68
68
|
|
69
|
-
@connection.expects(:update).with(regexp_matches(/`id`
|
70
|
-
@connection.expects(:update).with(regexp_matches(/`id`
|
71
|
-
@connection.expects(:update).with(regexp_matches(/`id`
|
72
|
-
@connection.expects(:update).with(regexp_matches(/`id`
|
69
|
+
@connection.expects(:update).with(regexp_matches(/`id` between 1 and 3/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(2)
|
70
|
+
@connection.expects(:update).with(regexp_matches(/`id` between 5 and 9/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(2)
|
71
|
+
@connection.expects(:update).with(regexp_matches(/`id` between 11 and 15/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(2)
|
72
|
+
@connection.expects(:update).with(regexp_matches(/`id` between 17 and 19/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(2)
|
73
73
|
|
74
74
|
@connection.expects(:execute).twice.with(regexp_matches(/show warnings/),EXPECTED_RETRY_FLAGS_CHUNKER).returns([])
|
75
75
|
|
@@ -81,7 +81,7 @@ describe Lhm::IdSetChunkFinder do
|
|
81
81
|
:chunk_finder => Lhm::IdSetChunkFinder)
|
82
82
|
|
83
83
|
@connection.expects(:select_values).with(regexp_matches(/order by id asc/),EXPECTED_RETRY_FLAGS_CHUNKER).returns([1])
|
84
|
-
@connection.expects(:update).with(regexp_matches(/`id`
|
84
|
+
@connection.expects(:update).with(regexp_matches(/`id` between 1 and 1/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(1)
|
85
85
|
|
86
86
|
@chunker.run
|
87
87
|
end
|
@@ -95,11 +95,11 @@ describe Lhm::IdSetChunkFinder do
|
|
95
95
|
|
96
96
|
@connection.expects(:select_values).with(regexp_matches(/order by id asc/),EXPECTED_RETRY_FLAGS_CHUNKER).returns((2..10).to_a)
|
97
97
|
|
98
|
-
@connection.expects(:update).with(regexp_matches(/`id`
|
99
|
-
@connection.expects(:update).with(regexp_matches(/`id`
|
100
|
-
@connection.expects(:update).with(regexp_matches(/`id`
|
101
|
-
@connection.expects(:update).with(regexp_matches(/`id`
|
102
|
-
@connection.expects(:update).with(regexp_matches(/`id`
|
98
|
+
@connection.expects(:update).with(regexp_matches(/`id` between 2 and 3/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(2)
|
99
|
+
@connection.expects(:update).with(regexp_matches(/`id` between 4 and 5/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(2)
|
100
|
+
@connection.expects(:update).with(regexp_matches(/`id` between 6 and 7/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(2)
|
101
|
+
@connection.expects(:update).with(regexp_matches(/`id` between 8 and 9/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(2)
|
102
|
+
@connection.expects(:update).with(regexp_matches(/`id` between 10 and 10/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(1)
|
103
103
|
|
104
104
|
@chunker.run
|
105
105
|
end
|
@@ -113,7 +113,7 @@ describe Lhm::IdSetChunkFinder do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
@connection.expects(:select_values).with(regexp_matches(/order by id asc/),EXPECTED_RETRY_FLAGS_CHUNKER).returns([1, 2])
|
116
|
-
@connection.expects(:update).with(regexp_matches(/where \(foo.created_at > '2013-07-10' or foo.baz = 'quux'\) and `foo`.*`id`
|
116
|
+
@connection.expects(:update).with(regexp_matches(/where \(foo.created_at > '2013-07-10' or foo.baz = 'quux'\) and `foo`.*`id` between 1 and 2/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(1)
|
117
117
|
@connection.expects(:execute).with(regexp_matches(/show warnings/),EXPECTED_RETRY_FLAGS_CHUNKER).returns([])
|
118
118
|
|
119
119
|
def @migration.conditions
|
@@ -132,7 +132,7 @@ describe Lhm::IdSetChunkFinder do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
@connection.expects(:select_values).with(regexp_matches(/order by id asc/),EXPECTED_RETRY_FLAGS_CHUNKER).returns([1,2])
|
135
|
-
@connection.expects(:update).with(regexp_matches(/inner join bar on foo.id = bar.foo_id and.*`id`
|
135
|
+
@connection.expects(:update).with(regexp_matches(/inner join bar on foo.id = bar.foo_id and.*`id` between 1 and 2/),EXPECTED_RETRY_FLAGS_CHUNK_INSERT).returns(1)
|
136
136
|
@connection.expects(:execute).with(regexp_matches(/show warnings/),EXPECTED_RETRY_FLAGS_CHUNKER).returns([])
|
137
137
|
|
138
138
|
def @migration.conditions
|