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 +4 -0
- data/bin/lhm-kill-queue +24 -11
- data/lib/lhm/version.rb +1 -1
- metadata +2 -2
data/CHANGELOG.md
CHANGED
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
|
-
(
|
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
|
-
|
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 =
|
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
|
137
|
-
|
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