lhm 1.0.0.rc5 → 1.0.0.rc6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.0.0.rc6 (January 30, 2012)
2
+
3
+ * added --confirm to kill script; fixes to kill script
4
+
1
5
  # 1.0.0.rc5 (January 30, 2012)
2
6
 
3
7
  * moved scripts into bin, renamed, added to gem binaries
data/bin/lhm-kill-queue CHANGED
@@ -15,6 +15,7 @@ module Lhm
15
15
  opts.on("-p", "--password PASSWORD") { |v| @password = v }
16
16
  opts.on("-d", "--database DATABASE") { |v| @database = v }
17
17
  opts.on("-m", "--mode MODE") { |v| @mode = v.to_sym }
18
+ opts.on("-y", "--confirm") { |v| @confirm = true }
18
19
  end.parse!
19
20
 
20
21
  unless(@hostname && @username && @password && @database)
@@ -33,7 +34,7 @@ module Lhm
33
34
  kills queries on the given server after detecting 'lock table% -- lhm'.
34
35
  usage:
35
36
  lhm-kill-queue -h hostname -u username -p password -d database \\
36
- (--kill | --master | --slave)
37
+ (-m kill | -m master | -m slave) [--confirm]
37
38
 
38
39
  desc
39
40
  end
@@ -48,17 +49,15 @@ module Lhm
48
49
 
49
50
  def kill
50
51
  lock = trip
51
- puts "killing lock process #{ lock }."
52
52
  kill_process(lock)
53
53
  end
54
54
 
55
55
  def master
56
56
  lock = trip
57
57
  puts "starting to kill non lhm processes in 1 second"
58
- sleep(1)
58
+ sleep(1.05)
59
59
 
60
60
  [list_non_lhm].flatten.each do |process|
61
- puts "killing #{ select_statement(process) }"
62
61
  kill_process(process)
63
62
  sleep(0.05)
64
63
  end
@@ -71,7 +70,6 @@ module Lhm
71
70
 
72
71
  [list_non_lhm].flatten.each do |process|
73
72
  if(select?(process))
74
- puts "killing #{ select_statement(process) }"
75
73
  kill_process(process)
76
74
  sleep(0.05)
77
75
  end
@@ -96,11 +94,11 @@ module Lhm
96
94
  end
97
95
 
98
96
  def list_non_lhm
99
- select_process("info not like '% -- lhm' and time > 0 and command = 'Query'")
97
+ select_processes("info not like '% -- lhm' and time > 0 and command = 'Query'")
100
98
  end
101
99
 
102
100
  def trip
103
- until res = select_process("info like 'lock table% -- lhm'")
101
+ until res = select_processes("info like 'lock table% -- lhm'")
104
102
  sleep 0.2
105
103
  print '.'
106
104
  end
@@ -109,12 +107,23 @@ module Lhm
109
107
  end
110
108
 
111
109
  def kill_process(process_id)
110
+ puts "killing #{ select_statement(process_id) }"
111
+
112
+ if(@confirm)
113
+ print "confirm ('y' to confirm): "
114
+
115
+ if(gets.strip != 'y')
116
+ puts "skipped."
117
+ return
118
+ end
119
+ end
120
+
112
121
  connection.execute("kill #{ process_id }")
122
+ puts "killed #{ process_id }"
113
123
  end
114
124
 
115
125
  def select?(process)
116
126
  if statement = select_statement(process)
117
-
118
127
  case statement
119
128
  when /delete/i then false
120
129
  when /update/i then false
@@ -133,8 +142,8 @@ module Lhm
133
142
  end
134
143
  end
135
144
 
136
- def select_process(predicate)
137
- value %Q(
145
+ def select_processes(predicate)
146
+ values %Q(
138
147
  select id from information_schema.processlist
139
148
  where db = '#{ @database }'
140
149
  and user = '#{ @username }'
@@ -145,9 +154,13 @@ module Lhm
145
154
  def value(statement)
146
155
  connection.select_value(statement)
147
156
  end
157
+
158
+ def values(statement)
159
+ connection.select_values(statement)
160
+ end
148
161
  end
149
162
  end
150
163
 
151
164
  killer = Lhm::KillQueue.new
152
165
  killer.run
153
- .
166
+
data/lib/lhm/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Schmidt
3
3
 
4
4
  module Lhm
5
- VERSION = "1.0.0.rc5"
5
+ VERSION = "1.0.0.rc6"
6
6
  end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 1
7
7
  - 0
8
8
  - 0
9
- - rc5
10
- version: 1.0.0.rc5
9
+ - rc6
10
+ version: 1.0.0.rc6
11
11
  platform: ruby
12
12
  authors:
13
13
  - SoundCloud