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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2a7116f2a283155f91b6b272454abf1515850ef
4
- data.tar.gz: d6f816f16389853b0acb524deb11824bfb9ed366
3
+ metadata.gz: 36dc167e62bd2d0e54548baf3f47317e629a3f83
4
+ data.tar.gz: f8cd8afc4e7334bf75040001b792759c6b85dfec
5
5
  SHA512:
6
- metadata.gz: 3c165aea2e6e48000218965f89f57889d17677e13a1e1894a958f4c615e20aea8da4672c4718b12a4a7e0df4acdc6b70865bad77a3dd19cfae7ef34f46906be5
7
- data.tar.gz: 1c3845da421375c166485d502ca51172d877cfedefe6db8896fb65869a030dbb3e71d8a96ab20804e67d952920fbd6e89ae2efec2ee9bc2a559ede07fb52ac09
6
+ metadata.gz: f44c628c83e96e476bcfb6b90ab0d96fb49a2d4495966e9ec4c2dfeecefc9b6d3960bd2663c942f0e1eaa3ccf13f57e340a7512f41269f57f36675045149e27b
7
+ data.tar.gz: 6b41d615ad5ec2a1cdb5d3d54ee99097301302fddd2106427224aacf0f43adca302e292006977792711141fb45827454a99bec8b2691905b65eee8856491a44e
data/lib/bricolage/job.rb CHANGED
@@ -130,6 +130,7 @@ module Bricolage
130
130
  end
131
131
 
132
132
  def execute
133
+ ENV['BRICOLAGE_PID'] = Process.pid.to_s
133
134
  logger = @context.logger
134
135
  logger.info "#{@context.environment} environment"
135
136
  result = logger.with_elapsed_time {
@@ -186,7 +186,9 @@ module Bricolage
186
186
 
187
187
  # override
188
188
  def run
189
- @ds.execute source
189
+ VacuumLock.using {
190
+ @ds.execute source
191
+ }
190
192
  end
191
193
 
192
194
  def run_explain
@@ -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
@@ -1,4 +1,4 @@
1
1
  module Bricolage
2
2
  APPLICATION_NAME = 'Bricolage'
3
- VERSION = '5.12.0'
3
+ VERSION = '5.12.1'
4
4
  end
@@ -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 process \##{Process.ppid}"
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- bricolage (5.12.0)
4
+ bricolage (5.12.1)
5
5
  aws-sdk (< 2)
6
6
  mysql2
7
7
  pg
@@ -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.0
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