jetpants 0.8.0 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/README.rdoc +4 -9
  3. data/bin/jetpants +7 -6
  4. data/doc/capacity_plan.rdoc +77 -0
  5. data/doc/commands.rdoc +1 -1
  6. data/doc/jetpants_collins.rdoc +2 -1
  7. data/doc/online_schema_change.rdoc +45 -0
  8. data/doc/plugins.rdoc +7 -1
  9. data/doc/requirements.rdoc +1 -1
  10. data/doc/upgrade_helper.rdoc +68 -0
  11. data/lib/jetpants/db/client.rb +2 -1
  12. data/lib/jetpants/db/import_export.rb +12 -3
  13. data/lib/jetpants/db/replication.rb +6 -2
  14. data/lib/jetpants/db/schema.rb +40 -0
  15. data/lib/jetpants/db/server.rb +2 -2
  16. data/lib/jetpants/host.rb +12 -1
  17. data/lib/jetpants/pool.rb +41 -0
  18. data/lib/jetpants/shard.rb +201 -124
  19. data/lib/jetpants/table.rb +80 -10
  20. data/plugins/capacity_plan/capacity_plan.rb +353 -0
  21. data/plugins/capacity_plan/commandsuite.rb +19 -0
  22. data/plugins/capacity_plan/monkeypatch.rb +20 -0
  23. data/plugins/jetpants_collins/db.rb +45 -6
  24. data/plugins/jetpants_collins/jetpants_collins.rb +32 -21
  25. data/plugins/jetpants_collins/pool.rb +22 -1
  26. data/plugins/jetpants_collins/shard.rb +9 -2
  27. data/plugins/jetpants_collins/topology.rb +8 -9
  28. data/plugins/online_schema_change/commandsuite.rb +56 -0
  29. data/plugins/online_schema_change/db.rb +33 -0
  30. data/plugins/online_schema_change/online_schema_change.rb +5 -0
  31. data/plugins/online_schema_change/pool.rb +105 -0
  32. data/plugins/online_schema_change/topology.rb +56 -0
  33. data/plugins/simple_tracker/shard.rb +1 -1
  34. data/plugins/upgrade_helper/commandsuite.rb +212 -0
  35. data/plugins/upgrade_helper/db.rb +78 -0
  36. data/plugins/upgrade_helper/host.rb +22 -0
  37. data/plugins/upgrade_helper/pool.rb +259 -0
  38. data/plugins/upgrade_helper/shard.rb +61 -0
  39. data/plugins/upgrade_helper/upgrade_helper.rb +21 -0
  40. data/scripts/global_rowcount.rb +75 -0
  41. metadata +28 -15
@@ -0,0 +1,61 @@
1
+ module Jetpants
2
+ class Shard
3
+ # Builds a set of upgraded slaves, and then makes one of the new slaves become the
4
+ # master for the other new slaves
5
+ def branched_upgrade_prep
6
+ raise "Shard #{self} in wrong state to perform this action! expected :ready, found #{@state}" unless @state == :ready
7
+ raise "Not enough standby slaves of this shard!" unless standby_slaves.size >= Jetpants.standby_slaves_per_pool
8
+ source = standby_slaves.last
9
+ spares_available = Jetpants.topology.count_spares(role: :standby_slave, like: source, version: Plugin::UpgradeHelper.new_version)
10
+ raise "Not enough spares available!" unless spares_available >= 1 + Jetpants.standby_slaves_per_pool
11
+
12
+ targets = Jetpants.topology.claim_spares(1 + Jetpants.standby_slaves_per_pool, role: :standby_slave, like: source, version: Plugin::UpgradeHelper.new_version)
13
+
14
+ # Disable fast shutdown on the source
15
+ source.mysql_root_cmd 'SET GLOBAL innodb_fast_shutdown = 0'
16
+
17
+ # Flag the nodes as needing upgrade, which will get triggered when
18
+ # enslave_siblings restarts them
19
+ targets.each {|t| t.needs_upgrade = true}
20
+
21
+ # Remove ib_lru_dump if present on targets
22
+ targets.concurrent_each {|t| t.ssh_cmd "rm -rf #{t.mysql_directory}/ib_lru_dump"}
23
+
24
+ source.enslave_siblings!(targets)
25
+ targets.concurrent_each {|t| t.resume_replication; t.catch_up_to_master}
26
+ source.pool.sync_configuration
27
+
28
+ # Make the 1st new slave be the "future master" which the other new
29
+ # slaves will replicate from
30
+ future_master = targets.shift
31
+ targets.each do |t|
32
+ future_master.pause_replication_with t
33
+ t.change_master_to future_master
34
+ [future_master, t].each {|db| db.resume_replication; db.catch_up_to_master}
35
+ end
36
+ end
37
+
38
+ # Hack the pool configuration to send reads to the new master, but still send
39
+ # writes to the old master (they'll replicate over)
40
+ def branched_upgrade_move_reads
41
+ raise "Shard #{self} in wrong state to perform this action! expected :ready, found #{@state}" unless @state == :ready
42
+ future_master = nil
43
+ slaves.each do |s|
44
+ future_master = s if s.version_cmp(@master) == 1 && s.slaves.size == Jetpants.standby_slaves_per_pool
45
+ end
46
+ raise "Shard #{self} does not have correct hierarchical replication setup to proceed" unless future_master
47
+ @master = future_master
48
+ @state = :child
49
+ sync_configuration
50
+ end
51
+
52
+ # Move writes over to the new master
53
+ def branched_upgrade_move_writes
54
+ raise "Shard #{self} in wrong state to perform this action! expected :child, found #{@state}" unless @state == :child
55
+ @master.disable_read_only!
56
+ @state = :needs_cleanup
57
+ sync_configuration
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,21 @@
1
+ # Entrypoint for upgrade_helper plugin
2
+
3
+ module Jetpants
4
+ module Plugin
5
+ module UpgradeHelper
6
+ class << self
7
+ # Shortcut for returning the configured new_version value
8
+ def new_version
9
+ Jetpants.plugins['upgrade_helper']['new_version']
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+
17
+ # Verify mandatory config options
18
+ raise "No new_version specified in plugin config!" unless Jetpants::Plugin::UpgradeHelper.new_version
19
+
20
+ # load all the monkeypatches for other Jetpants classes
21
+ %w(pool shard host db commandsuite).each {|mod| require "upgrade_helper/#{mod}"}
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This is a script to count all rows in your database topology. It
4
+ # performs concurrent chunked counts on standby slaves, and can serve
5
+ # as an example of writing scripts using Jetpants as a library.
6
+
7
+ require 'jetpants'
8
+
9
+ # Count on shards first
10
+ sharded_tables = Jetpants::Table.from_config 'sharded_tables'
11
+ sharded_counts = Jetpants.shards.limited_concurrent_map(8) do |p|
12
+ node = p.standby_slaves.last
13
+ node.stop_query_killer
14
+ node.output "Starting counts for #{p}"
15
+ my_max = p.max_id
16
+ if my_max == 'INFINITY'
17
+ maxes = sharded_tables.map do |t|
18
+ node.query_return_first_value "SELECT MAX(#{t.sharding_keys.first}) FROM #{t.name}"
19
+ end
20
+ my_max = maxes.map(&:to_i).max
21
+ end
22
+ counts = node.row_counts(sharded_tables, p.min_id, my_max)
23
+ p.output "Found counts for #{p}: #{counts}"
24
+ node.start_query_killer
25
+ counts
26
+ end
27
+
28
+ total_counts = {'rollup' => 0}
29
+ sharded_counts.each do |cnt|
30
+ cnt.each do |table_name, row_count|
31
+ total_counts[table_name] ||= 0
32
+ total_counts[table_name] += row_count
33
+ total_counts['rollup'] += row_count
34
+ end
35
+ end
36
+
37
+ # Count on functional partitions next
38
+ global_counts = Jetpants.functional_partitions.limited_concurrent_map(8) do |p|
39
+ begin
40
+ node = p.standby_slaves.last
41
+ node.stop_query_killer
42
+ node.output "Starting counts for #{p}"
43
+ counts = {}
44
+ p.tables.each do |t|
45
+ min, max = false, false
46
+ if t.first_pk_col
47
+ vals = node.query_return_first "SELECT MIN(#{t.first_pk_col}) AS minval, MAX(#{t.first_pk_col}) AS maxval FROM #{t.name}"
48
+ min, max = vals[:minval], vals[:maxval]
49
+ if max.to_i - min.to_i > 100
50
+ t.chunks = 100
51
+ else
52
+ min, max = false, false
53
+ end
54
+ end
55
+ counts.merge! node.row_counts(t, min, max)
56
+ end
57
+ p.output "Found counts for #{p}: #{counts}"
58
+ node.start_query_killer
59
+ counts
60
+ rescue => ex
61
+ p.output "Unable to obtain counts for #{p} -- #{ex.message}"
62
+ node.start_query_killer
63
+ {}
64
+ end
65
+ end
66
+
67
+ global_counts.each do |cnt|
68
+ cnt.each do |table_name, row_count|
69
+ total_counts[table_name] ||= 0
70
+ total_counts[table_name] += row_count
71
+ total_counts['rollup'] += row_count
72
+ end
73
+ end
74
+
75
+ puts total_counts
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jetpants
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.8.0
4
+ version: 0.8.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Evan Elias
@@ -13,13 +12,12 @@ autorequire:
13
12
  bindir: bin
14
13
  cert_chain: []
15
14
 
16
- date: 2013-03-12 00:00:00 Z
15
+ date: 2013-05-17 00:00:00 Z
17
16
  dependencies:
18
17
  - !ruby/object:Gem::Dependency
19
18
  name: mysql2
20
19
  prerelease: false
21
20
  requirement: &id001 !ruby/object:Gem::Requirement
22
- none: false
23
21
  requirements:
24
22
  - - ~>
25
23
  - !ruby/object:Gem::Version
@@ -30,7 +28,6 @@ dependencies:
30
28
  name: sequel
31
29
  prerelease: false
32
30
  requirement: &id002 !ruby/object:Gem::Requirement
33
- none: false
34
31
  requirements:
35
32
  - - ~>
36
33
  - !ruby/object:Gem::Version
@@ -41,7 +38,6 @@ dependencies:
41
38
  name: net-ssh
42
39
  prerelease: false
43
40
  requirement: &id003 !ruby/object:Gem::Requirement
44
- none: false
45
41
  requirements:
46
42
  - - ~>
47
43
  - !ruby/object:Gem::Version
@@ -52,7 +48,6 @@ dependencies:
52
48
  name: pry
53
49
  prerelease: false
54
50
  requirement: &id004 !ruby/object:Gem::Requirement
55
- none: false
56
51
  requirements:
57
52
  - - ~>
58
53
  - !ruby/object:Gem::Version
@@ -63,7 +58,6 @@ dependencies:
63
58
  name: thor
64
59
  prerelease: false
65
60
  requirement: &id005 !ruby/object:Gem::Requirement
66
- none: false
67
61
  requirements:
68
62
  - - ~>
69
63
  - !ruby/object:Gem::Version
@@ -74,7 +68,6 @@ dependencies:
74
68
  name: highline
75
69
  prerelease: false
76
70
  requirement: &id006 !ruby/object:Gem::Requirement
77
- none: false
78
71
  requirements:
79
72
  - - ~>
80
73
  - !ruby/object:Gem::Version
@@ -85,7 +78,6 @@ dependencies:
85
78
  name: colored
86
79
  prerelease: false
87
80
  requirement: &id007 !ruby/object:Gem::Requirement
88
- none: false
89
81
  requirements:
90
82
  - - ~>
91
83
  - !ruby/object:Gem::Version
@@ -96,7 +88,6 @@ dependencies:
96
88
  name: collins_client
97
89
  prerelease: false
98
90
  requirement: &id008 !ruby/object:Gem::Requirement
99
- none: false
100
91
  requirements:
101
92
  - - ~>
102
93
  - !ruby/object:Gem::Version
@@ -116,26 +107,33 @@ extensions: []
116
107
  extra_rdoc_files:
117
108
  - README.rdoc
118
109
  - doc/configuration.rdoc
110
+ - doc/upgrade_helper.rdoc
111
+ - doc/capacity_plan.rdoc
119
112
  - doc/faq.rdoc
120
113
  - doc/commands.rdoc
121
114
  - doc/requirements.rdoc
122
115
  - doc/jetpants_collins.rdoc
123
116
  - doc/plugins.rdoc
117
+ - doc/online_schema_change.rdoc
124
118
  files:
125
119
  - Gemfile
126
120
  - README.rdoc
127
121
  - doc/configuration.rdoc
122
+ - doc/upgrade_helper.rdoc
123
+ - doc/capacity_plan.rdoc
128
124
  - doc/faq.rdoc
129
125
  - doc/commands.rdoc
130
126
  - doc/requirements.rdoc
131
127
  - doc/jetpants_collins.rdoc
132
128
  - doc/plugins.rdoc
129
+ - doc/online_schema_change.rdoc
133
130
  - lib/jetpants/shard.rb
134
131
  - lib/jetpants/table.rb
135
132
  - lib/jetpants/db.rb
136
133
  - lib/jetpants/pool.rb
137
134
  - lib/jetpants/db/privileges.rb
138
135
  - lib/jetpants/db/state.rb
136
+ - lib/jetpants/db/schema.rb
139
137
  - lib/jetpants/db/import_export.rb
140
138
  - lib/jetpants/db/server.rb
141
139
  - lib/jetpants/db/client.rb
@@ -146,6 +144,7 @@ files:
146
144
  - lib/jetpants/host.rb
147
145
  - lib/jetpants.rb
148
146
  - bin/jetpants
147
+ - scripts/global_rowcount.rb
149
148
  - plugins/jetpants_collins/jetpants_collins.rb
150
149
  - plugins/jetpants_collins/shard.rb
151
150
  - plugins/jetpants_collins/db.rb
@@ -153,16 +152,32 @@ files:
153
152
  - plugins/jetpants_collins/asset.rb
154
153
  - plugins/jetpants_collins/topology.rb
155
154
  - plugins/jetpants_collins/host.rb
155
+ - plugins/capacity_plan/commandsuite.rb
156
+ - plugins/capacity_plan/monkeypatch.rb
157
+ - plugins/capacity_plan/capacity_plan.rb
158
+ - plugins/upgrade_helper/commandsuite.rb
159
+ - plugins/upgrade_helper/shard.rb
160
+ - plugins/upgrade_helper/db.rb
161
+ - plugins/upgrade_helper/upgrade_helper.rb
162
+ - plugins/upgrade_helper/pool.rb
163
+ - plugins/upgrade_helper/host.rb
156
164
  - plugins/simple_tracker/simple_tracker.rb
157
165
  - plugins/simple_tracker/commandsuite.rb
158
166
  - plugins/simple_tracker/shard.rb
159
167
  - plugins/simple_tracker/db.rb
160
168
  - plugins/simple_tracker/pool.rb
161
169
  - plugins/simple_tracker/topology.rb
170
+ - plugins/online_schema_change/commandsuite.rb
171
+ - plugins/online_schema_change/db.rb
172
+ - plugins/online_schema_change/pool.rb
173
+ - plugins/online_schema_change/online_schema_change.rb
174
+ - plugins/online_schema_change/topology.rb
162
175
  - etc/jetpants.yaml.sample
163
176
  homepage: https://github.com/tumblr/jetpants/
164
177
  licenses: []
165
178
 
179
+ metadata: {}
180
+
166
181
  post_install_message:
167
182
  rdoc_options:
168
183
  - --line-numbers
@@ -173,13 +188,11 @@ rdoc_options:
173
188
  require_paths:
174
189
  - lib
175
190
  required_ruby_version: !ruby/object:Gem::Requirement
176
- none: false
177
191
  requirements:
178
192
  - - ">="
179
193
  - !ruby/object:Gem::Version
180
194
  version: 1.9.2
181
195
  required_rubygems_version: !ruby/object:Gem::Requirement
182
- none: false
183
196
  requirements:
184
197
  - - ">="
185
198
  - !ruby/object:Gem::Version
@@ -187,9 +200,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
200
  requirements: []
188
201
 
189
202
  rubyforge_project:
190
- rubygems_version: 1.8.10
203
+ rubygems_version: 2.0.3
191
204
  signing_key:
192
- specification_version: 3
205
+ specification_version: 4
193
206
  summary: "Jetpants: a MySQL automation toolkit by Tumblr"
194
207
  test_files: []
195
208