lhm 1.0.0.rc6 → 1.0.0.rc7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ # 1.0.0.rc7 (January 31, 2012)
2
+
3
+ * added SqlHelper.annotation into the middle of trigger statements. this
4
+ is for the benefit of the killer script which should not kill trigger
5
+ statements.
6
+
1
7
  # 1.0.0.rc6 (January 30, 2012)
2
8
 
3
9
  * added --confirm to kill script; fixes to kill script
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'active_record'
4
+ require 'lhm/sql_helper'
4
5
  require 'optparse'
5
6
 
6
7
  module Lhm
@@ -8,6 +9,9 @@ module Lhm
8
9
 
9
10
  def initialize
10
11
  @port = 3306
12
+ @grace = 10
13
+ @tiny = 0.1
14
+ @marker = "%#{ SqlHelper.annotation }%"
11
15
 
12
16
  OptionParser.new do |opts|
13
17
  opts.on("-h", "--hostname HOSTNAME") { |v| @hostname = v }
@@ -31,7 +35,7 @@ module Lhm
31
35
 
32
36
  def usage
33
37
  <<-desc.gsub(/^ /, '')
34
- kills queries on the given server after detecting 'lock table% -- lhm'.
38
+ kills queries on the given server after detecting 'lock table#{ @marker }'.
35
39
  usage:
36
40
  lhm-kill-queue -h hostname -u username -p password -d database \\
37
41
  (-m kill | -m master | -m slave) [--confirm]
@@ -54,24 +58,24 @@ module Lhm
54
58
 
55
59
  def master
56
60
  lock = trip
57
- puts "starting to kill non lhm processes in 1 second"
58
- sleep(1.05)
61
+ puts "starting to kill non lhm processes in #{ @grace } seconds"
62
+ sleep(@grace + @tiny)
59
63
 
60
64
  [list_non_lhm].flatten.each do |process|
61
65
  kill_process(process)
62
- sleep(0.05)
66
+ sleep(@tiny)
63
67
  end
64
68
  end
65
69
 
66
70
  def slave
67
71
  lock = trip
68
- puts "starting to kill non lhm SELECT processes in 1 second"
69
- sleep(1)
72
+ puts "starting to kill non lhm SELECT processes in #{ @grace } seconds"
73
+ sleep(@grace + @tiny)
70
74
 
71
75
  [list_non_lhm].flatten.each do |process|
72
76
  if(select?(process))
73
77
  kill_process(process)
74
- sleep(0.05)
78
+ sleep(@tiny)
75
79
  end
76
80
  end
77
81
  end
@@ -94,12 +98,14 @@ module Lhm
94
98
  end
95
99
 
96
100
  def list_non_lhm
97
- select_processes("info not like '% -- lhm' and time > 0 and command = 'Query'")
101
+ select_processes %Q(
102
+ info not like '#{ @marker }' and time > #{ @grace } and command = 'Query'
103
+ )
98
104
  end
99
105
 
100
106
  def trip
101
- until res = select_processes("info like 'lock table% -- lhm'")
102
- sleep 0.2
107
+ until res = select_processes("info like 'lock table#{ @marker }'").first
108
+ sleep @tiny
103
109
  print '.'
104
110
  end
105
111
 
data/lib/lhm.rb CHANGED
@@ -17,7 +17,6 @@ require 'lhm/version'
17
17
  # end
18
18
  #
19
19
  module Lhm
20
- extend self
21
20
 
22
21
  # Alters a table with the changes described in the block
23
22
  #
@@ -28,9 +27,9 @@ module Lhm
28
27
  # @option chunk_options [Fixnum] :throttle
29
28
  # Time to wait between chunks in milliseconds (defaults to: 100)
30
29
  # @yield [Migrator] Yielded Migrator object records the changes
31
- # @return [Boolean] Returns true if the migration finishs
30
+ # @return [Boolean] Returns true if the migration finishes
32
31
  # @raise [Error] Raises Lhm::Error in case of a error and aborts the migration
33
- def change_table(table_name, chunk_options = {}, &block)
32
+ def self.change_table(table_name, chunk_options = {}, &block)
34
33
  connection = ActiveRecord::Base.connection
35
34
  origin = Table.parse(table_name, connection)
36
35
  invoker = Invoker.new(origin, connection)
@@ -40,3 +39,4 @@ module Lhm
40
39
  true
41
40
  end
42
41
  end
42
+
@@ -40,7 +40,7 @@ module Lhm
40
40
  strip %Q{
41
41
  create trigger `#{ trigger(:ins) }`
42
42
  after insert on `#{ @origin.name }` for each row
43
- replace into `#{ @destination.name }` (#{ @common.joined })
43
+ replace into `#{ @destination.name }` (#{ @common.joined }) #{ SqlHelper.annotation }
44
44
  values (#{ @common.typed("NEW") })
45
45
  }
46
46
  end
@@ -49,7 +49,7 @@ module Lhm
49
49
  strip %Q{
50
50
  create trigger `#{ trigger(:upd) }`
51
51
  after update on `#{ @origin.name }` for each row
52
- replace into `#{ @destination.name }` (#{ @common.joined })
52
+ replace into `#{ @destination.name }` (#{ @common.joined }) #{ SqlHelper.annotation }
53
53
  values (#{ @common.typed("NEW") })
54
54
  }
55
55
  end
@@ -58,7 +58,7 @@ module Lhm
58
58
  strip %Q{
59
59
  create trigger `#{ trigger(:del) }`
60
60
  after delete on `#{ @origin.name }` for each row
61
- delete ignore from `#{ @destination.name }`
61
+ delete ignore from `#{ @destination.name }` #{ SqlHelper.annotation }
62
62
  where `#{ @destination.name }`.`id` = OLD.`id`
63
63
  }
64
64
  end
@@ -5,6 +5,10 @@ module Lhm
5
5
  module SqlHelper
6
6
  extend self
7
7
 
8
+ def annotation
9
+ "/* large hadron migration */"
10
+ end
11
+
8
12
  def idx_name(table_name, cols)
9
13
  column_names = column_definition(cols).map(&:first)
10
14
  "index_#{ table_name }_on_#{ column_names.join("_and_") }"
@@ -12,7 +16,7 @@ module Lhm
12
16
 
13
17
  def idx_spec(cols)
14
18
  column_definition(cols).map do |name, length|
15
- "`#{name}`#{length}"
19
+ "`#{ name }`#{ length }"
16
20
  end.join(', ')
17
21
  end
18
22
 
@@ -39,7 +43,7 @@ module Lhm
39
43
  private
40
44
 
41
45
  def tagged(statement)
42
- statement + " -- lhm"
46
+ "#{ statement } #{ SqlHelper.annotation }"
43
47
  end
44
48
 
45
49
  def column_definition(cols)
@@ -2,5 +2,5 @@
2
2
  # Schmidt
3
3
 
4
4
  module Lhm
5
- VERSION = "1.0.0.rc6"
5
+ VERSION = "1.0.0.rc7"
6
6
  end
@@ -30,7 +30,7 @@ describe Lhm::Entangler do
30
30
  ddl = %Q{
31
31
  create trigger `lhmt_ins_origin`
32
32
  after insert on `origin` for each row
33
- replace into `destination` (`info`, `tags`)
33
+ replace into `destination` (`info`, `tags`) /* large hadron migration */
34
34
  values (NEW.`info`, NEW.`tags`)
35
35
  }
36
36
 
@@ -41,7 +41,7 @@ describe Lhm::Entangler do
41
41
  ddl = %Q{
42
42
  create trigger `lhmt_upd_origin`
43
43
  after update on `origin` for each row
44
- replace into `destination` (`info`, `tags`)
44
+ replace into `destination` (`info`, `tags`) /* large hadron migration */
45
45
  values (NEW.`info`, NEW.`tags`)
46
46
  }
47
47
 
@@ -52,7 +52,7 @@ describe Lhm::Entangler do
52
52
  ddl = %Q{
53
53
  create trigger `lhmt_del_origin`
54
54
  after delete on `origin` for each row
55
- delete ignore from `destination`
55
+ delete ignore from `destination` /* large hadron migration */
56
56
  where `destination`.`id` = OLD.`id`
57
57
  }
58
58
 
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 1
7
7
  - 0
8
8
  - 0
9
- - rc6
10
- version: 1.0.0.rc6
9
+ - rc7
10
+ version: 1.0.0.rc7
11
11
  platform: ruby
12
12
  authors:
13
13
  - SoundCloud