bricolage 5.12.0 → 5.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bricolage/job.rb +1 -0
- data/lib/bricolage/psqldatasource.rb +3 -1
- data/lib/bricolage/vacuumlock.rb +35 -3
- data/lib/bricolage/version.rb +1 -1
- data/libexec/create-lockfile +4 -4
- data/test/home/Gemfile.lock +1 -1
- data/test/home/subsys/raw-vacuum.jobnet +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36dc167e62bd2d0e54548baf3f47317e629a3f83
|
4
|
+
data.tar.gz: f8cd8afc4e7334bf75040001b792759c6b85dfec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f44c628c83e96e476bcfb6b90ab0d96fb49a2d4495966e9ec4c2dfeecefc9b6d3960bd2663c942f0e1eaa3ccf13f57e340a7512f41269f57f36675045149e27b
|
7
|
+
data.tar.gz: 6b41d615ad5ec2a1cdb5d3d54ee99097301302fddd2106427224aacf0f43adca302e292006977792711141fb45827454a99bec8b2691905b65eee8856491a44e
|
data/lib/bricolage/job.rb
CHANGED
data/lib/bricolage/vacuumlock.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'bricolage/exception'
|
2
|
+
require 'fileutils'
|
2
3
|
|
3
4
|
module Bricolage
|
4
5
|
|
@@ -6,6 +7,7 @@ module Bricolage
|
|
6
7
|
def enable_vacuum_lock?
|
7
8
|
!!ENV['BRICOLAGE_VACUUM_LOCK']
|
8
9
|
end
|
10
|
+
module_function :enable_vacuum_lock?
|
9
11
|
|
10
12
|
DEFAULT_VACUUM_LOCK_FILE = '/tmp/bricolage.vacuum.lock'
|
11
13
|
DEFAULT_VACUUM_LOCK_TIMEOUT = 3600 # 60min
|
@@ -31,7 +33,7 @@ module Bricolage
|
|
31
33
|
def psql_serialize_vacuum_end
|
32
34
|
if enable_vacuum_lock?
|
33
35
|
path, timeout = vacuum_lock_parameters
|
34
|
-
"\\! rm #{path}"
|
36
|
+
"\\! rm -f #{path}"
|
35
37
|
else
|
36
38
|
';'
|
37
39
|
end
|
@@ -67,11 +69,41 @@ module Bricolage
|
|
67
69
|
end
|
68
70
|
sleep 1
|
69
71
|
retry
|
70
|
-
rescue
|
71
|
-
raise
|
72
72
|
end
|
73
73
|
end
|
74
74
|
module_function :create_vacuum_lock_file
|
75
|
+
|
76
|
+
def VacuumLock.using
|
77
|
+
return yield unless enable_vacuum_lock?
|
78
|
+
begin
|
79
|
+
yield
|
80
|
+
ensure
|
81
|
+
cleanup_vacuum_lock
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def using_vacuum_lock(&block)
|
86
|
+
VacuumLock.using(&block)
|
87
|
+
end
|
88
|
+
|
89
|
+
def VacuumLock.cleanup_vacuum_lock
|
90
|
+
return unless enable_vacuum_lock?
|
91
|
+
path, timeout = vacuum_lock_parameters
|
92
|
+
if locking?(path)
|
93
|
+
$stderr.puts "remove VACUUM lock by #{Process.pid}"
|
94
|
+
FileUtils.rm_f path
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def VacuumLock.locking?(path)
|
99
|
+
# do not check file existance, just read to avoid race condition
|
100
|
+
locker_pid = File.read(path).slice(/\[(\d+)\]/, 1).to_i
|
101
|
+
$stderr.puts "bricolage_pid: #{$$}, vacuum_locked_by: #{locker_pid}"
|
102
|
+
locker_pid == Process.pid
|
103
|
+
rescue
|
104
|
+
$stderr.puts "bricolage_pid: #{$$}, vacuum_locked_by: (none)"
|
105
|
+
false
|
106
|
+
end
|
75
107
|
end
|
76
108
|
|
77
109
|
end
|
data/lib/bricolage/version.rb
CHANGED
data/libexec/create-lockfile
CHANGED
@@ -11,6 +11,9 @@ def main
|
|
11
11
|
path, tm = ARGV
|
12
12
|
timeout = [tm.to_i, MINIMUM_TIMEOUT].max
|
13
13
|
create_lock_file path, timeout
|
14
|
+
rescue
|
15
|
+
emit_error_to_psql
|
16
|
+
raise
|
14
17
|
end
|
15
18
|
|
16
19
|
def create_lock_file(path, timeout)
|
@@ -18,7 +21,7 @@ def create_lock_file(path, timeout)
|
|
18
21
|
print_message "trying to create lock file: #{path} (psql #{parent_is_psql? ? 'detected' : 'NOT detected'})"
|
19
22
|
begin
|
20
23
|
File.open(path, File::WRONLY | File::CREAT | File::EXCL) {|f|
|
21
|
-
f.puts "#{Time.now}: created by
|
24
|
+
f.puts "#{Time.now}: created by create-lockfile (Bricolage pid [#{ENV['BRICOLAGE_PID']}])"
|
22
25
|
}
|
23
26
|
rescue Errno::EEXIST
|
24
27
|
if Time.now - start_time > timeout
|
@@ -27,9 +30,6 @@ def create_lock_file(path, timeout)
|
|
27
30
|
end
|
28
31
|
sleep 3
|
29
32
|
retry
|
30
|
-
rescue
|
31
|
-
emit_error_to_psql
|
32
|
-
raise
|
33
33
|
end
|
34
34
|
print_message "lock file created: #{path}"
|
35
35
|
end
|
data/test/home/Gemfile.lock
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
raw-vacuum
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bricolage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.12.
|
4
|
+
version: 5.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Minero Aoki
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- test/home/subsys/migrate.job
|
186
186
|
- test/home/subsys/net1.jobnet
|
187
187
|
- test/home/subsys/net2.jobnet
|
188
|
+
- test/home/subsys/raw-vacuum.jobnet
|
188
189
|
- test/home/subsys/raw-vacuum.sql.job
|
189
190
|
- test/home/subsys/rebuild.sql.job
|
190
191
|
- test/home/subsys/search_backends.ct
|