mysql-pause 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/mysql-pause +2 -0
- data/lib/mysql-pause/backend.rb +28 -7
- data/lib/mysql-pause/constants.rb +1 -1
- data/lib/mysql-pause/proxy.rb +38 -5
- data/lib/mysql-pause/server.rb +5 -3
- metadata +18 -2
data/bin/mysql-pause
CHANGED
@@ -29,6 +29,8 @@ ARGV.options do |parser|
|
|
29
29
|
parser.on('-n', '--threads=SIZE' ) {|v| options[:threads] = v.to_i }
|
30
30
|
parser.on('-W', '--working-dir=DIR' ) {|v| options[:working_dir] = v }
|
31
31
|
parser.on('-S', '--socket=SOCK_FILE' ) {|v| options[:socket] = v }
|
32
|
+
parser.on('', '--ping-user=USER' ) {|v| options[:ping_user] = v }
|
33
|
+
parser.on('', '--ping-pass=PASS' ) {|v| options[:ping_pass] = v }
|
32
34
|
parser.on('', '--debug' ) { options[:debug] = true }
|
33
35
|
|
34
36
|
help_and_exit = lambda do |v|
|
data/lib/mysql-pause/backend.rb
CHANGED
@@ -4,22 +4,43 @@ module MysqlPause
|
|
4
4
|
class Backend < EM::Connection
|
5
5
|
def initialize(proxy)
|
6
6
|
@proxy = proxy
|
7
|
+
@logger = proxy.logger
|
7
8
|
end
|
8
9
|
|
9
10
|
def post_init
|
10
|
-
if
|
11
|
-
@
|
11
|
+
if (peername = get_peername)
|
12
|
+
@connect_from = Socket.unpack_sockaddr_in(peername)
|
13
|
+
end
|
14
|
+
|
15
|
+
if @proxy and @proxy.options[:debug]
|
16
|
+
port, ip = @connect_from
|
17
|
+
@logger.debug("backend: connect from #{ip}:#{port}")
|
12
18
|
end
|
13
19
|
end
|
14
20
|
|
15
21
|
def unbind
|
16
|
-
if @proxy.options[:debug]
|
17
|
-
@
|
22
|
+
if @proxy and @proxy.options[:debug]
|
23
|
+
port, ip = @connect_from
|
24
|
+
@logger.debug("backend: unbind connection from #{ip}:#{port}")
|
18
25
|
end
|
19
26
|
end
|
20
27
|
|
21
28
|
def receive_data(data)
|
22
|
-
@proxy.
|
29
|
+
if not @proxy or @proxy.error?
|
30
|
+
@logger.info("backend: proxy connection error: #{data.inspect}")
|
31
|
+
close_proxy_connection
|
32
|
+
close_connection_after_writing
|
33
|
+
else
|
34
|
+
@proxy.send_data(data)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def close_proxy_connection
|
41
|
+
@proxy.close_connection if @proxy
|
42
|
+
rescue Exception => e
|
43
|
+
@logger.warn("#{e.class.name}: #{e.message}")
|
23
44
|
end
|
24
|
-
end
|
25
|
-
end
|
45
|
+
end # Backend
|
46
|
+
end # MysqlPause
|
@@ -1,2 +1,2 @@
|
|
1
1
|
APP_NAME = 'mysql-pause'
|
2
|
-
Version = '0.1.
|
2
|
+
Version = '0.1.8'
|
data/lib/mysql-pause/proxy.rb
CHANGED
@@ -3,6 +3,7 @@ require 'mysql-pause/backend'
|
|
3
3
|
require 'mysql-pause/error'
|
4
4
|
require 'logger'
|
5
5
|
require 'socket'
|
6
|
+
require 'mysql2/em'
|
6
7
|
|
7
8
|
module MysqlPause
|
8
9
|
RETRY_LIMIT = 100
|
@@ -39,14 +40,22 @@ module MysqlPause
|
|
39
40
|
end
|
40
41
|
|
41
42
|
def post_init
|
43
|
+
if (peername = get_peername)
|
44
|
+
@connect_from = Socket.unpack_sockaddr_in(peername)
|
45
|
+
end
|
46
|
+
|
42
47
|
if @options[:debug]
|
43
|
-
@
|
48
|
+
port, ip = @connect_from
|
49
|
+
@logger.debug("proxy: connect from #{ip}:#{port}")
|
44
50
|
end
|
45
51
|
end
|
46
52
|
|
47
53
|
def unbind
|
54
|
+
close_backend_connection
|
55
|
+
|
48
56
|
if @options[:debug]
|
49
|
-
@
|
57
|
+
port, ip = @connect_from
|
58
|
+
@logger.debug("proxy: unbind connection from #{ip}:#{port}")
|
50
59
|
end
|
51
60
|
end
|
52
61
|
|
@@ -59,7 +68,7 @@ module MysqlPause
|
|
59
68
|
end
|
60
69
|
|
61
70
|
if @backend.error?
|
62
|
-
@logger.info("backend error: #{data.inspect}")
|
71
|
+
@logger.info("proxy: backend connection error: #{data.inspect}")
|
63
72
|
close_backend_connection
|
64
73
|
|
65
74
|
payload_length, sequence_id = parse_mysql_packet(data)
|
@@ -89,9 +98,33 @@ module MysqlPause
|
|
89
98
|
end
|
90
99
|
|
91
100
|
def ping(addr, port)
|
92
|
-
|
93
|
-
|
101
|
+
mysqld_is_alive = false
|
102
|
+
client = nil
|
103
|
+
|
104
|
+
begin
|
105
|
+
client = Mysql2::EM::Client.new(:host => addr, :port => port, :username => @options[:ping_user], :password => @options[:ping_pass])
|
106
|
+
mysqld_is_alive = client.ping
|
107
|
+
rescue Exception => e
|
108
|
+
@logger.warn("#{e.class.name}: #{e.message}")
|
109
|
+
mysqld_is_alive = false
|
110
|
+
ensure
|
111
|
+
begin
|
112
|
+
client.close if client
|
113
|
+
rescue Exception => e
|
114
|
+
@logger.warn("#{e.class.name}: #{e.message}")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
return mysqld_is_alive
|
94
119
|
end
|
95
120
|
|
121
|
+
def connect_from
|
122
|
+
return @connect_from if @connect_from
|
123
|
+
|
124
|
+
peername = get_peername
|
125
|
+
return nil unless peername
|
126
|
+
|
127
|
+
@connect_from = Socket.unpack_sockaddr_in(peername)
|
128
|
+
end
|
96
129
|
end # Proxy
|
97
130
|
end # MysqlPause
|
data/lib/mysql-pause/server.rb
CHANGED
@@ -21,9 +21,11 @@ module MysqlPause
|
|
21
21
|
|
22
22
|
def run
|
23
23
|
@@control_options = {
|
24
|
-
:pause
|
25
|
-
:interval
|
26
|
-
:debug
|
24
|
+
:pause => false,
|
25
|
+
:interval => @@options[:interval],
|
26
|
+
:debug => @@options[:debug],
|
27
|
+
:ping_user => @@options[:ping_user],
|
28
|
+
:ping_pass => @@options[:ping_pass],
|
27
29
|
}
|
28
30
|
|
29
31
|
# start DRb
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysql-pause
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 1.5.1
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: mysql2
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
46
62
|
description:
|
47
63
|
email: sgwr_dts@yahoo.co.jp
|
48
64
|
executables:
|