bricolage 5.9.0 → 5.9.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: 5d8fe450bc754d0074c361ebdec9b3f0119cf440
4
- data.tar.gz: a12ba4bf06eb22f598e4d8e7df8b1028c84e0c52
3
+ metadata.gz: bf741a3e8446d11bfb5e9b0f6dcc891f1cae8495
4
+ data.tar.gz: c17962a361321f6b19d976f62aace9e7b63544da
5
5
  SHA512:
6
- metadata.gz: 801a0ba6a167068141d446e2d8e598ef6bcafcfec591c9011dcedf8aa126afdfb2dd6b830dfc9786f530e2608a48d5c69faee6b510c1b0e833feca6ae661df6a
7
- data.tar.gz: cbb2b228f85c74f5b1a4f83a9d55eddcccfbcf9d9ea91ab5b2e4564614a11ecb512222448bf2e71eebbb17237eb792368e780f5ca3104f63e3278543cf8bce28
6
+ metadata.gz: c81b950eef56f09a3a1dc7e682a45eabb6c0d25a610d1925ec7409de54f6f11643ddd1153d9d78a25c338160c23c83084293ac7960e1a0634b97bd835cb164d5
7
+ data.tar.gz: 3068f48c6134aab0c219f826d74b57bc43e077bd486b39140c23925631fd97c9debff45422be35034a82aaa80822c26d14edc4a69249707c38e87f40656e8e1a
@@ -10,7 +10,7 @@ module Bricolage
10
10
  sargs.unshift env if env
11
11
  system(*sargs)
12
12
  st = $?
13
- logger.info "status: #{st.exitstatus} (#{st})"
13
+ logger.info "status: #{st.exitstatus || 'nil'} (#{st})"
14
14
  st
15
15
  end
16
16
 
@@ -47,7 +47,8 @@ module Bricolage
47
47
 
48
48
  def status
49
49
  if @process_status
50
- @process_status.exitstatus
50
+ # Process::Status#exitstatus may be nil when the command did not exited normally
51
+ @process_status.exitstatus || EXIT_FAILURE
51
52
  else
52
53
  case @type
53
54
  when :success then EXIT_SUCCESS
@@ -4,6 +4,7 @@ require 'bricolage/sqlstatement'
4
4
  require 'bricolage/commandutils'
5
5
  require 'bricolage/postgresconnection'
6
6
  require 'bricolage/exception'
7
+ require 'pathname'
7
8
 
8
9
  module Bricolage
9
10
 
@@ -243,12 +244,33 @@ module Bricolage
243
244
 
244
245
  def vacuum_if(enable_vacuum, enable_vacuum_sort, target = '${dest_table}')
245
246
  if enable_vacuum
246
- exec SQLStatement.for_string("vacuum #{target};")
247
+ serialize_vacuum {
248
+ exec SQLStatement.for_string("vacuum #{target};")
249
+ }
247
250
  elsif enable_vacuum_sort
248
- exec SQLStatement.for_string("vacuum sort only #{target};")
251
+ serialize_vacuum {
252
+ exec SQLStatement.for_string("vacuum sort only #{target};")
253
+ }
249
254
  end
250
255
  end
251
256
 
257
+ DEFAULT_VACUUM_LOCK_FILE = '/tmp/bricolage.vacuum.lock'
258
+ DEFAULT_VACUUM_LOCK_TIMEOUT = 3600 # 60min
259
+
260
+ def serialize_vacuum
261
+ if ENV['BRICOLAGE_VACUUM_LOCK']
262
+ path, tm = ENV['BRICOLAGE_VACUUM_LOCK'].split(':', 2)
263
+ timeout = tm.to_i
264
+ else
265
+ path = DEFAULT_VACUUM_LOCK_FILE
266
+ timeout = DEFAULT_VACUUM_LOCK_TIMEOUT
267
+ end
268
+ lock_file_cmd = Pathname(__FILE__).parent.parent.parent + 'libexec/create-lockfile'
269
+ exec SQLStatement.for_string "\\! #{lock_file_cmd} #{path} #{timeout}"
270
+ yield
271
+ exec SQLStatement.for_string "\\! rm #{path}"
272
+ end
273
+
252
274
  def analyze_if(enabled, target = '${dest_table}')
253
275
  exec SQLStatement.for_string("analyze #{target};") if enabled
254
276
  end
@@ -1,4 +1,4 @@
1
1
  module Bricolage
2
2
  APPLICATION_NAME = 'Bricolage'
3
- VERSION = '5.9.0'
3
+ VERSION = '5.9.1'
4
4
  end
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ DEFAULT_TIMEOUT = 900 # 15 minutes
4
+ MINIMUM_TIMEOUT = 1
5
+
6
+ def main
7
+ unless ARGV.size == 2
8
+ $stderr.puts "Usage: #{$0} PATH TIMEOUT_SEC"
9
+ exit 1
10
+ end
11
+ path, tm = ARGV
12
+ timeout = [tm.to_i, MINIMUM_TIMEOUT].max
13
+ create_lock_file path, timeout
14
+ end
15
+
16
+ def create_lock_file(path, timeout)
17
+ start_time = Time.now
18
+ print_message "trying to create lock file: #{path} (psql #{parent_is_psql? ? 'detected' : 'NOT detected'})"
19
+ begin
20
+ File.open(path, File::WRONLY | File::CREAT | File::EXCL) {|f|
21
+ f.puts "#{Time.now}: created by process \##{Process.ppid}"
22
+ }
23
+ rescue Errno::EEXIST
24
+ if Time.now - start_time > timeout
25
+ emit_error_to_psql
26
+ error_exit "could not create lock file: #{path} (timeout #{timeout} seconds)"
27
+ end
28
+ sleep 3
29
+ retry
30
+ rescue
31
+ emit_error_to_psql
32
+ raise
33
+ end
34
+ print_message "lock file created: #{path}"
35
+ end
36
+
37
+ def emit_error_to_psql
38
+ # psql does not stop on error of external command,
39
+ # we must explicitly stop that.
40
+ if parent_is_psql?
41
+ Process.kill 'TERM', Process.ppid
42
+ end
43
+ end
44
+
45
+ def parent_is_psql?
46
+ # psql set this environment variable
47
+ !!ENV['PGSYSCONFDIR']
48
+ end
49
+
50
+ def error_exit(msg)
51
+ $stderr.puts "#{$0}: error: #{msg}"
52
+ exit 1
53
+ end
54
+
55
+ def print_message(msg)
56
+ $stderr.puts "#{Time.now}: #{msg}"
57
+ end
58
+
59
+ main
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- bricolage (5.8.7)
4
+ bricolage (5.9.0)
5
5
  aws-sdk (< 2)
6
6
  mysql2
7
7
  pg
@@ -52,3 +52,6 @@ PLATFORMS
52
52
 
53
53
  DEPENDENCIES
54
54
  bricolage!
55
+
56
+ BUNDLED WITH
57
+ 1.10.2
@@ -0,0 +1,7 @@
1
+ --dest-table: d
2
+
3
+ create table $dest_table
4
+ ( x int
5
+ , y int
6
+ , z int
7
+ );
@@ -0,0 +1,13 @@
1
+ /*
2
+ class: rebuild-drop
3
+ table-def: d.ct
4
+ dest-table: d
5
+ src-tables:
6
+ s: s
7
+ analyze: true
8
+ vacuum-sort: true
9
+ */
10
+
11
+ insert into $dest_table
12
+ select * from $s
13
+ ;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bricolage
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.9.0
4
+ version: 5.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minero Aoki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-29 00:00:00.000000000 Z
11
+ date: 2015-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -153,6 +153,7 @@ files:
153
153
  - lib/bricolage/tddatasource.rb
154
154
  - lib/bricolage/variables.rb
155
155
  - lib/bricolage/version.rb
156
+ - libexec/create-lockfile
156
157
  - libexec/sqldump
157
158
  - libexec/sqldump.Darwin
158
159
  - libexec/sqldump.Linux
@@ -166,8 +167,10 @@ files:
166
167
  - test/home/data/20141002-1355_02.txt
167
168
  - test/home/put.sh
168
169
  - test/home/revert.sh
170
+ - test/home/subsys/d.ct
169
171
  - test/home/subsys/load_test.ct
170
172
  - test/home/subsys/load_test.job
173
+ - test/home/subsys/rebuild.sql.job
171
174
  - test/home/subsys/separated.job
172
175
  - test/home/subsys/separated.sql
173
176
  - test/home/subsys/unified.jobnet