lhm 1.0.0.rc2 → 1.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.config +3 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +9 -3
  4. data/CHANGELOG.md +10 -0
  5. data/README.md +28 -24
  6. data/Rakefile +2 -1
  7. data/gemfiles/ar-2.3.gemfile +4 -0
  8. data/gemfiles/ar-3.1.gemfile +4 -0
  9. data/lhm.gemspec +1 -1
  10. data/lib/lhm.rb +30 -8
  11. data/lib/lhm/chunker.rb +53 -34
  12. data/lib/lhm/command.rb +15 -42
  13. data/lib/lhm/entangler.rb +13 -20
  14. data/lib/lhm/intersection.rb +3 -7
  15. data/lib/lhm/invoker.rb +9 -14
  16. data/lib/lhm/locked_switcher.rb +22 -26
  17. data/lib/lhm/migration.rb +2 -8
  18. data/lib/lhm/migrator.rb +76 -56
  19. data/lib/lhm/sql_helper.rb +45 -0
  20. data/lib/lhm/table.rb +2 -10
  21. data/lib/lhm/version.rb +6 -0
  22. data/spec/README.md +26 -0
  23. data/spec/bootstrap.rb +2 -5
  24. data/spec/config/.config +3 -0
  25. data/spec/config/clobber +36 -0
  26. data/spec/config/grants +25 -0
  27. data/spec/config/setup-cluster +61 -0
  28. data/spec/fixtures/destination.ddl +0 -1
  29. data/spec/fixtures/origin.ddl +0 -1
  30. data/spec/fixtures/users.ddl +1 -1
  31. data/spec/integration/chunker_spec.rb +10 -9
  32. data/spec/integration/entangler_spec.rb +16 -10
  33. data/spec/integration/integration_helper.rb +43 -12
  34. data/spec/integration/lhm_spec.rb +66 -42
  35. data/spec/integration/locked_switcher_spec.rb +11 -10
  36. data/spec/unit/chunker_spec.rb +50 -18
  37. data/spec/unit/entangler_spec.rb +2 -5
  38. data/spec/unit/intersection_spec.rb +2 -5
  39. data/spec/unit/locked_switcher_spec.rb +2 -5
  40. data/spec/unit/migration_spec.rb +2 -5
  41. data/spec/unit/migrator_spec.rb +6 -9
  42. data/spec/unit/sql_helper_spec.rb +32 -0
  43. data/spec/unit/table_spec.rb +2 -29
  44. data/spec/unit/unit_helper.rb +2 -5
  45. metadata +52 -7
  46. data/Gemfile +0 -3
@@ -1,7 +1,5 @@
1
- #
2
- # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
3
- # Schmidt
4
- #
1
+ # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
2
+ # Schmidt
5
3
 
6
4
  require File.expand_path(File.dirname(__FILE__)) + '/integration_helper'
7
5
 
@@ -12,7 +10,7 @@ require 'lhm/locked_switcher'
12
10
  describe Lhm::LockedSwitcher do
13
11
  include IntegrationHelper
14
12
 
15
- before(:each) { connect! }
13
+ before(:each) { connect_master! }
16
14
 
17
15
  describe "switching" do
18
16
  before(:each) do
@@ -25,17 +23,20 @@ describe Lhm::LockedSwitcher do
25
23
  switcher = Lhm::LockedSwitcher.new(@migration, connection)
26
24
  switcher.run
27
25
 
28
- table_exists?(@origin).must_equal true
29
- table_read(@migration.archive_name).columns.keys.must_include "origin"
26
+ slave do
27
+ table_exists?(@origin).must_equal true
28
+ table_read(@migration.archive_name).columns.keys.must_include "origin"
29
+ end
30
30
  end
31
31
 
32
32
  it "rename destination to origin" do
33
33
  switcher = Lhm::LockedSwitcher.new(@migration, connection)
34
34
  switcher.run
35
35
 
36
- table_exists?(@destination).must_equal false
37
- table_read(@origin.name).columns.keys.must_include "destination"
36
+ slave do
37
+ table_exists?(@destination).must_equal false
38
+ table_read(@origin.name).columns.keys.must_include "destination"
39
+ end
38
40
  end
39
41
  end
40
42
  end
41
-
@@ -1,7 +1,5 @@
1
- #
2
- # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
3
- # Schmidt
4
- #
1
+ # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
2
+ # Schmidt
5
3
 
6
4
  require File.expand_path(File.dirname(__FILE__)) + '/unit_helper'
7
5
 
@@ -16,7 +14,7 @@ describe Lhm::Chunker do
16
14
  @origin = Lhm::Table.new("origin")
17
15
  @destination = Lhm::Table.new("destination")
18
16
  @migration = Lhm::Migration.new(@origin, @destination)
19
- @chunker = Lhm::Chunker.new(@migration, 1, nil, { :stride => 100_000 })
17
+ @chunker = Lhm::Chunker.new(@migration, nil, { :start => 1, :limit => 10 })
20
18
  end
21
19
 
22
20
  describe "copy into" do
@@ -34,9 +32,31 @@ describe Lhm::Chunker do
34
32
  end
35
33
  end
36
34
 
35
+ describe "invalid" do
36
+ before do
37
+ @chunker = Lhm::Chunker.new(@migration, nil, { :start => 0, :limit => -1 })
38
+ end
39
+
40
+ it "should have zero chunks" do
41
+ @chunker.traversable_chunks_size.must_equal 0
42
+ end
43
+
44
+ it "should not iterate" do
45
+ @chunker.up_to do |bottom, top|
46
+ raise "should not iterate"
47
+ end
48
+ end
49
+ end
50
+
37
51
  describe "one" do
52
+ before do
53
+ @chunker = Lhm::Chunker.new(@migration, nil, {
54
+ :stride => 100_000, :start => 1, :limit => 300_000
55
+ })
56
+ end
57
+
38
58
  it "should have one chunk" do
39
- @chunker.traversable_chunks_up_to(100).must_equal 1
59
+ @chunker.traversable_chunks_size.must_equal 3
40
60
  end
41
61
 
42
62
  it "should lower bound chunk on 1" do
@@ -44,36 +64,48 @@ describe Lhm::Chunker do
44
64
  end
45
65
 
46
66
  it "should upper bound chunk on 100" do
47
- @chunker.top(chunk = 1, limit = 100).must_equal 100
67
+ @chunker.top(chunk = 1).must_equal 100_000
48
68
  end
49
69
  end
50
70
 
51
71
  describe "two" do
72
+ before do
73
+ @chunker = Lhm::Chunker.new(@migration, nil, {
74
+ :stride => 100_000, :start => 2, :limit => 150_000
75
+ })
76
+ end
77
+
52
78
  it "should have two chunks" do
53
- @chunker.traversable_chunks_up_to(150_000).must_equal 2
79
+ @chunker.traversable_chunks_size.must_equal 2
54
80
  end
55
81
 
56
82
  it "should lower bound second chunk on 100_000" do
57
- @chunker.bottom(chunk = 2).must_equal 100_001
83
+ @chunker.bottom(chunk = 2).must_equal 100_002
58
84
  end
59
85
 
60
86
  it "should upper bound second chunk on 150_000" do
61
- @chunker.top(chunk = 2, limit = 150_000).must_equal 150_000
87
+ @chunker.top(chunk = 2).must_equal 150_000
62
88
  end
63
89
  end
64
90
 
65
91
  describe "iterating" do
66
- it "should iterate" do
67
- @chunker = Lhm::Chunker.new(@migration, nil, nil, {
68
- :stride => 150,
69
- :throttle => 0
92
+ before do
93
+ @chunker = Lhm::Chunker.new(@migration, nil, {
94
+ :stride => 100, :start => 53, :limit => 121
70
95
  })
96
+ end
71
97
 
72
- @chunker.up_to(limit = 100) do |bottom, top|
73
- bottom.must_equal 1
74
- top.must_equal 100
98
+ it "should iterate" do
99
+ @chunker.up_to do |bottom, top|
100
+ bottom.must_equal 53
101
+ top.must_equal 121
75
102
  end
76
103
  end
77
104
  end
78
- end
79
105
 
106
+ describe "throttling" do
107
+ it "should default to 100 milliseconds" do
108
+ @chunker.throttle_seconds.must_equal 0.1
109
+ end
110
+ end
111
+ end
@@ -1,7 +1,5 @@
1
- #
2
- # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
3
- # Schmidt
4
- #
1
+ # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
2
+ # Schmidt
5
3
 
6
4
  require File.expand_path(File.dirname(__FILE__)) + '/unit_helper'
7
5
 
@@ -76,4 +74,3 @@ describe Lhm::Entangler do
76
74
  end
77
75
  end
78
76
  end
79
-
@@ -1,7 +1,5 @@
1
- #
2
- # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
3
- # Schmidt
4
- #
1
+ # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
2
+ # Schmidt
5
3
 
6
4
  require File.expand_path(File.dirname(__FILE__)) + '/unit_helper'
7
5
 
@@ -39,4 +37,3 @@ describe Lhm::Intersection do
39
37
  { :metadata => "VARCHAR(255)"}
40
38
  end
41
39
  end
42
-
@@ -1,7 +1,5 @@
1
- #
2
- # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
3
- # Schmidt
4
- #
1
+ # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
2
+ # Schmidt
5
3
 
6
4
  require File.expand_path(File.dirname(__FILE__)) + '/unit_helper'
7
5
 
@@ -51,4 +49,3 @@ describe Lhm::LockedSwitcher do
51
49
  end
52
50
  end
53
51
  end
54
-
@@ -1,7 +1,5 @@
1
- #
2
- # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
3
- # Schmidt
4
- #
1
+ # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
2
+ # Schmidt
5
3
 
6
4
  require File.expand_path(File.dirname(__FILE__)) + '/unit_helper'
7
5
 
@@ -23,4 +21,3 @@ describe Lhm::Migration do
23
21
  @migration.archive_name.must_equal "lhma_#{ @start.strftime(stamp) }_origin"
24
22
  end
25
23
  end
26
-
@@ -1,7 +1,5 @@
1
- #
2
- # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
3
- # Schmidt
4
- #
1
+ # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
2
+ # Schmidt
5
3
 
6
4
  require File.expand_path(File.dirname(__FILE__)) + '/unit_helper'
7
5
 
@@ -21,7 +19,7 @@ describe Lhm::Migrator do
21
19
  @creator.add_index(["a", "b"])
22
20
 
23
21
  @creator.statements.must_equal([
24
- "create index `index_alt_on_a_and_b` on `lhmn_alt` (a, b)"
22
+ "create index `index_alt_on_a_and_b` on `lhmn_alt` (`a`, `b`)"
25
23
  ])
26
24
  end
27
25
 
@@ -29,15 +27,15 @@ describe Lhm::Migrator do
29
27
  @creator.add_index(["a(10)", "b"])
30
28
 
31
29
  @creator.statements.must_equal([
32
- "create index `index_alt_on_a_and_b` on `lhmn_alt` (a(10), b)"
30
+ "create index `index_alt_on_a_and_b` on `lhmn_alt` (`a`(10), `b`)"
33
31
  ])
34
32
  end
35
33
 
36
34
  it "should add an unique index" do
37
- @creator.add_unique_index(["a(10)", :b])
35
+ @creator.add_unique_index(["a(5)", :b])
38
36
 
39
37
  @creator.statements.must_equal([
40
- "create unique index `index_alt_on_a_and_b` on `lhmn_alt` (a(10), b)"
38
+ "create unique index `index_alt_on_a_and_b` on `lhmn_alt` (`a`(5), `b`)"
41
39
  ])
42
40
  end
43
41
 
@@ -94,4 +92,3 @@ describe Lhm::Migrator do
94
92
  end
95
93
  end
96
94
  end
97
-
@@ -0,0 +1,32 @@
1
+ # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
2
+ # Schmidt
3
+
4
+ require File.expand_path(File.dirname(__FILE__)) + '/unit_helper'
5
+
6
+ require 'lhm/sql_helper'
7
+
8
+ describe Lhm::SqlHelper do
9
+ it "should name index with a single column" do
10
+ Lhm::SqlHelper.
11
+ idx_name(:users, :name).
12
+ must_equal("index_users_on_name")
13
+ end
14
+
15
+ it "should name index with multiple columns" do
16
+ Lhm::SqlHelper.
17
+ idx_name(:users, [:name, :firstname]).
18
+ must_equal("index_users_on_name_and_firstname")
19
+ end
20
+
21
+ it "should name index with prefixed column" do
22
+ Lhm::SqlHelper.
23
+ idx_name(:tracks, ["title(10)", "album"]).
24
+ must_equal("index_tracks_on_title_and_album")
25
+ end
26
+
27
+ it "should quote column names in index specification" do
28
+ Lhm::SqlHelper.
29
+ idx_spec(["title(10)", "album"]).
30
+ must_equal("`title`(10), `album`")
31
+ end
32
+ end
@@ -1,7 +1,5 @@
1
- #
2
- # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
3
- # Schmidt
4
- #
1
+ # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
2
+ # Schmidt
5
3
 
6
4
  require File.expand_path(File.dirname(__FILE__)) + '/unit_helper'
7
5
 
@@ -18,30 +16,6 @@ describe Lhm::Table do
18
16
  it "should name destination" do
19
17
  @table.destination_name.must_equal "lhmn_users"
20
18
  end
21
-
22
- it "should name index with a single column" do
23
- @table.
24
- idx_name(["name"]).
25
- must_equal("index_users_on_name")
26
- end
27
-
28
- it "should name index with multiple columns" do
29
- @table.
30
- idx_name(["name", "firstname"]).
31
- must_equal("index_users_on_name_and_firstname")
32
- end
33
-
34
- it "should name index with prefixed column" do
35
- @table.
36
- idx_name(["name(10)", "firstname"]).
37
- must_equal("index_users_on_name_and_firstname")
38
- end
39
-
40
- it "should name index with column names given as symbol" do
41
- @table.
42
- idx_name([:name, :firstname]).
43
- must_equal("index_users_on_name_and_firstname")
44
- end
45
19
  end
46
20
 
47
21
  describe "constraints" do
@@ -97,4 +71,3 @@ describe Lhm::Table do
97
71
  end
98
72
  end
99
73
  end
100
-
@@ -1,7 +1,5 @@
1
- #
2
- # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
3
- # Schmidt
4
- #
1
+ # Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
2
+ # Schmidt
5
3
 
6
4
  require File.expand_path(File.dirname(__FILE__)) + "/../bootstrap"
7
5
 
@@ -14,4 +12,3 @@ module UnitHelper
14
12
  sql.strip.gsub(/\n */, "\n")
15
13
  end
16
14
  end
17
-
metadata CHANGED
@@ -1,8 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhm
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 15424051
4
5
  prerelease: 6
5
- version: 1.0.0.rc2
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ - rc
11
+ - 3
12
+ version: 1.0.0.rc3
6
13
  platform: ruby
7
14
  authors:
8
15
  - SoundCloud
@@ -13,8 +20,7 @@ autorequire:
13
20
  bindir: bin
14
21
  cert_chain: []
15
22
 
16
- date: 2012-01-18 00:00:00 +01:00
17
- default_executable:
23
+ date: 2012-01-19 00:00:00 Z
18
24
  dependencies:
19
25
  - !ruby/object:Gem::Dependency
20
26
  name: mysql
@@ -24,6 +30,11 @@ dependencies:
24
30
  requirements:
25
31
  - - ~>
26
32
  - !ruby/object:Gem::Version
33
+ hash: 45
34
+ segments:
35
+ - 2
36
+ - 8
37
+ - 1
27
38
  version: 2.8.1
28
39
  type: :development
29
40
  version_requirements: *id001
@@ -35,6 +46,11 @@ dependencies:
35
46
  requirements:
36
47
  - - "="
37
48
  - !ruby/object:Gem::Version
49
+ hash: 39
50
+ segments:
51
+ - 2
52
+ - 10
53
+ - 0
38
54
  version: 2.10.0
39
55
  type: :development
40
56
  version_requirements: *id002
@@ -46,6 +62,9 @@ dependencies:
46
62
  requirements:
47
63
  - - ">="
48
64
  - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
49
68
  version: "0"
50
69
  type: :development
51
70
  version_requirements: *id003
@@ -57,6 +76,9 @@ dependencies:
57
76
  requirements:
58
77
  - - ">="
59
78
  - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
60
82
  version: "0"
61
83
  type: :runtime
62
84
  version_requirements: *id004
@@ -69,14 +91,15 @@ extensions: []
69
91
  extra_rdoc_files: []
70
92
 
71
93
  files:
94
+ - .config
72
95
  - .gitignore
73
96
  - .travis.yml
74
97
  - CHANGELOG.md
75
- - Gemfile
76
- - Gemfile.lock
77
98
  - LICENSE
78
99
  - README.md
79
100
  - Rakefile
101
+ - gemfiles/ar-2.3.gemfile
102
+ - gemfiles/ar-3.1.gemfile
80
103
  - lhm.gemspec
81
104
  - lib/lhm.rb
82
105
  - lib/lhm/chunker.rb
@@ -87,8 +110,15 @@ files:
87
110
  - lib/lhm/locked_switcher.rb
88
111
  - lib/lhm/migration.rb
89
112
  - lib/lhm/migrator.rb
113
+ - lib/lhm/sql_helper.rb
90
114
  - lib/lhm/table.rb
115
+ - lib/lhm/version.rb
116
+ - spec/README.md
91
117
  - spec/bootstrap.rb
118
+ - spec/config/.config
119
+ - spec/config/clobber
120
+ - spec/config/grants
121
+ - spec/config/setup-cluster
92
122
  - spec/fixtures/destination.ddl
93
123
  - spec/fixtures/origin.ddl
94
124
  - spec/fixtures/users.ddl
@@ -103,9 +133,9 @@ files:
103
133
  - spec/unit/locked_switcher_spec.rb
104
134
  - spec/unit/migration_spec.rb
105
135
  - spec/unit/migrator_spec.rb
136
+ - spec/unit/sql_helper_spec.rb
106
137
  - spec/unit/table_spec.rb
107
138
  - spec/unit/unit_helper.rb
108
- has_rdoc: true
109
139
  homepage: http://github.com/soundcloud/large-hadron-migrator
110
140
  licenses: []
111
141
 
@@ -119,22 +149,35 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
149
  requirements:
120
150
  - - ">="
121
151
  - !ruby/object:Gem::Version
152
+ hash: 3
153
+ segments:
154
+ - 0
122
155
  version: "0"
123
156
  required_rubygems_version: !ruby/object:Gem::Requirement
124
157
  none: false
125
158
  requirements:
126
159
  - - ">"
127
160
  - !ruby/object:Gem::Version
161
+ hash: 25
162
+ segments:
163
+ - 1
164
+ - 3
165
+ - 1
128
166
  version: 1.3.1
129
167
  requirements: []
130
168
 
131
169
  rubyforge_project:
132
- rubygems_version: 1.5.0
170
+ rubygems_version: 1.8.10
133
171
  signing_key:
134
172
  specification_version: 3
135
173
  summary: online schema changer for mysql
136
174
  test_files:
175
+ - spec/README.md
137
176
  - spec/bootstrap.rb
177
+ - spec/config/.config
178
+ - spec/config/clobber
179
+ - spec/config/grants
180
+ - spec/config/setup-cluster
138
181
  - spec/fixtures/destination.ddl
139
182
  - spec/fixtures/origin.ddl
140
183
  - spec/fixtures/users.ddl
@@ -149,5 +192,7 @@ test_files:
149
192
  - spec/unit/locked_switcher_spec.rb
150
193
  - spec/unit/migration_spec.rb
151
194
  - spec/unit/migrator_spec.rb
195
+ - spec/unit/sql_helper_spec.rb
152
196
  - spec/unit/table_spec.rb
153
197
  - spec/unit/unit_helper.rb
198
+ has_rdoc: