ey_snaplock 0.0.12.pre.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -9
- data/lib/ey_snaplock.rb +2 -33
- data/lib/ey_snaplock/database/mysql.rb +2 -18
- data/lib/ey_snaplock/database/postgresql9.rb +1 -1
- data/lib/ey_snaplock/timer.rb +15 -0
- data/lib/ey_snaplock/version.rb +1 -1
- metadata +9 -8
data/README.md
CHANGED
@@ -1,24 +1,29 @@
|
|
1
1
|
EY Snaplock
|
2
2
|
===========
|
3
3
|
|
4
|
-
|
4
|
+
![EY Snaplock](http://img825.imageshack.us/img825/4323/snaplock.jpg "EY Snaplock")
|
5
|
+
|
6
|
+
Lock the filesystem and execute database specific 'backup' commands before
|
7
|
+
calling the provided URI to initiate the snapshot.
|
5
8
|
|
6
|
-
|
9
|
+
Unlocks as necessary when the URI returns (when the snapshot is done).
|
7
10
|
|
8
|
-
Postgres testing notes
|
11
|
+
Postgres testing notes
|
12
|
+
----------------------
|
9
13
|
|
10
14
|
wal_level = hot_standby
|
11
15
|
archive_mode = on
|
12
16
|
archive_command = '/usr/bin/true'
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
Release process:
|
18
|
+
Release process
|
19
|
+
---------------
|
17
20
|
|
18
|
-
```
|
19
|
-
edit version file
|
21
|
+
```
|
22
|
+
edit version file and commit
|
20
23
|
gem build ey_snaplock.gemspec
|
21
24
|
gem push ey_snaplock-0.0.5.gem
|
25
|
+
git tag v0.0.5
|
26
|
+
git push origin v0.0.5
|
22
27
|
edit version file again
|
23
28
|
commit
|
24
|
-
```
|
29
|
+
```
|
data/lib/ey_snaplock.rb
CHANGED
@@ -1,20 +1,12 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'net/https'
|
3
3
|
require 'ey_snaplock/database'
|
4
|
-
|
5
|
-
begin
|
6
|
-
require 'system_timer'
|
7
|
-
SnaplockTimer = SystemTimer
|
8
|
-
rescue LoadError => e
|
9
|
-
require 'timeout'
|
10
|
-
SnaplockTimer = Timeout
|
11
|
-
end
|
4
|
+
require 'ey_snaplock/timer'
|
12
5
|
|
13
6
|
module EY
|
14
7
|
class Snaplock
|
15
8
|
REQUEST_TIMEOUT = 15
|
16
9
|
PER_DATABASE_TIMEOUT = 5
|
17
|
-
LONG_RUNNING_QUERY_RETRIES = 3
|
18
10
|
|
19
11
|
def self.call(*argv)
|
20
12
|
new(*argv).call
|
@@ -60,7 +52,7 @@ module EY
|
|
60
52
|
def timeout
|
61
53
|
lambda do
|
62
54
|
begin
|
63
|
-
|
55
|
+
EY::Snaplock::Timer.timeout(REQUEST_TIMEOUT) { yield }
|
64
56
|
rescue Timeout::Error
|
65
57
|
$stderr.puts "Timeout Exceeded: Callback request took longer than #{REQUEST_TIMEOUT} seconds."
|
66
58
|
raise
|
@@ -78,24 +70,6 @@ module EY
|
|
78
70
|
def database_lock(database_uri, timeout, &block)
|
79
71
|
database = Database.for(database_uri)
|
80
72
|
with_locked_db = block
|
81
|
-
|
82
|
-
if database.respond_to?(:has_long_running_queries?)
|
83
|
-
log_file = '/var/log/ey-snaplock.' + Time.now.strftime("%Y-%m-%dT%H-%M-%S") + '.log'
|
84
|
-
remaining_retries = LONG_RUNNING_QUERY_RETRIES
|
85
|
-
|
86
|
-
while database.has_long_running_queries?(PER_DATABASE_TIMEOUT) && remaining_retries >= 0
|
87
|
-
if remaining_retries == 0
|
88
|
-
database.dump_process_list(log_file)
|
89
|
-
clean_up_old_log_files
|
90
|
-
$stderr.puts "Aborting Snaplock due to long running queries. Process list dumped to #{log_file}."
|
91
|
-
exit 1
|
92
|
-
else
|
93
|
-
sleep PER_DATABASE_TIMEOUT
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
73
|
lambda do
|
100
74
|
lock_filename = database.lock_filename
|
101
75
|
file = File.open(lock_filename, File::RDWR|File::EXCL|File::CREAT) rescue nil
|
@@ -116,11 +90,6 @@ module EY
|
|
116
90
|
end
|
117
91
|
end
|
118
92
|
|
119
|
-
def clean_up_old_log_files(logs_to_keep = 10)
|
120
|
-
ordinal = logs_to_keep.succ.to_s
|
121
|
-
"ls -r /var/log/ey-snaplock.*.log | tail -n +#{ordinal} | xargs -I@ rm @"
|
122
|
-
end
|
123
|
-
|
124
93
|
private
|
125
94
|
|
126
95
|
def post_path_for_uri(uri)
|
@@ -7,7 +7,7 @@ module EY
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def lock_filename
|
10
|
-
ENV["MYSQL_LOCK_FILENAME"] || "/
|
10
|
+
ENV["MYSQL_LOCK_FILENAME"] || "/var/run/ey_snaplock_mysql.pid"
|
11
11
|
end
|
12
12
|
|
13
13
|
def with_lock(timeout)
|
@@ -31,7 +31,7 @@ module EY
|
|
31
31
|
pipe = IO.popen(@mysql, 'w')
|
32
32
|
@read_lock_pid = pipe.pid
|
33
33
|
pipe.puts('flush tables with read lock;')
|
34
|
-
|
34
|
+
EY::Snaplock::Timer.timeout(timeout) do
|
35
35
|
until locked?
|
36
36
|
sleep 1
|
37
37
|
end
|
@@ -56,22 +56,6 @@ module EY
|
|
56
56
|
Process.kill('TERM', @read_lock_pid) # unlock tables
|
57
57
|
end
|
58
58
|
|
59
|
-
def has_long_running_queries?(cutoff_in_seconds)
|
60
|
-
%x<#{@mysql} -B -N -e 'show processlist;'>.split("\n").each do |process_entry|
|
61
|
-
id, user, host, db, command, time, state, info = process_entry.split("\t")
|
62
|
-
|
63
|
-
next if %w{root system}.include? user
|
64
|
-
next if ['Sleep', 'Binlog Dump'].include? command
|
65
|
-
|
66
|
-
return true if time.to_i > cutoff_in_seconds
|
67
|
-
end
|
68
|
-
false
|
69
|
-
end
|
70
|
-
|
71
|
-
def dump_process_list(logfile)
|
72
|
-
system("#{@mysql} -N -e 'show processlist;' >> #{logfile}")
|
73
|
-
end
|
74
|
-
|
75
59
|
def mysql_command(uri)
|
76
60
|
command = "mysql"
|
77
61
|
command << " -u" << (uri.user || 'root')
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module EY
|
2
|
+
class Snaplock
|
3
|
+
class Timer
|
4
|
+
def self.timeout(sec)
|
5
|
+
if RUBY_VERSION =~ /^1\.8/
|
6
|
+
require 'system_timer'
|
7
|
+
SystemTimer.timeout_after(sec) { yield }
|
8
|
+
else
|
9
|
+
require 'timeout'
|
10
|
+
Timeout.timeout(sec) { yield }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/ey_snaplock/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ey_snaplock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Engine Yard
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - '='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.
|
37
|
+
version: 0.9.2.2
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - '='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
45
|
+
version: 0.9.2.2
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: realweb
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/ey_snaplock/database/mysql.rb
|
119
119
|
- lib/ey_snaplock/database/postgresql9.rb
|
120
120
|
- lib/ey_snaplock/database.rb
|
121
|
+
- lib/ey_snaplock/timer.rb
|
121
122
|
- lib/ey_snaplock/version.rb
|
122
123
|
- lib/ey_snaplock.rb
|
123
124
|
- LICENSE
|
@@ -137,12 +138,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
137
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
139
|
none: false
|
139
140
|
requirements:
|
140
|
-
- - ! '
|
141
|
+
- - ! '>='
|
141
142
|
- !ruby/object:Gem::Version
|
142
|
-
version:
|
143
|
+
version: '0'
|
143
144
|
requirements: []
|
144
145
|
rubyforge_project:
|
145
|
-
rubygems_version: 1.8.
|
146
|
+
rubygems_version: 1.8.24
|
146
147
|
signing_key:
|
147
148
|
specification_version: 3
|
148
149
|
summary: Server side components for Engine Yard's snapshotting process
|