bricolage 5.9.1 → 5.9.2

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: bf741a3e8446d11bfb5e9b0f6dcc891f1cae8495
4
- data.tar.gz: c17962a361321f6b19d976f62aace9e7b63544da
3
+ metadata.gz: d90b31340ca5e8f083b1398ea38ec9ad8e5f48b7
4
+ data.tar.gz: e24c75f6c80dba6d318ee7c23c81167c69790ba8
5
5
  SHA512:
6
- metadata.gz: c81b950eef56f09a3a1dc7e682a45eabb6c0d25a610d1925ec7409de54f6f11643ddd1153d9d78a25c338160c23c83084293ac7960e1a0634b97bd835cb164d5
7
- data.tar.gz: 3068f48c6134aab0c219f826d74b57bc43e077bd486b39140c23925631fd97c9debff45422be35034a82aaa80822c26d14edc4a69249707c38e87f40656e8e1a
6
+ metadata.gz: 25c123224e59677fb1515b4be8000744d09850571190e5d32a31193f122e838cfe5f60ab4efb847cbd2d87de457f8c99889dea924bc74d94f4b018ed29c8f251
7
+ data.tar.gz: bfb3624f71f581cdbf37a1cc05c71be6007ee5c585406b7dc87e5c022d1cd14a7c062b26aa9687083bee568e653abcff961e105033ea23f0c61232a2ea5324d6
@@ -1,5 +1,6 @@
1
1
  require 'bricolage/sqlstatement'
2
2
  require 'bricolage/resource'
3
+ require 'bricolage/embeddedcodeapi'
3
4
  require 'bricolage/exception'
4
5
  require 'pathname'
5
6
  require 'yaml'
@@ -58,6 +59,8 @@ module Bricolage
58
59
 
59
60
  private
60
61
 
62
+ include EmbeddedCodeAPI
63
+
61
64
  def app_home
62
65
  @app_home or raise ParameterError, "app_home is not given in this file"
63
66
  end
@@ -76,51 +79,4 @@ module Bricolage
76
79
  end
77
80
  end
78
81
 
79
- module EmbeddedCodeAPI
80
- private
81
-
82
- def user_home
83
- Pathname(ENV['HOME'])
84
- end
85
-
86
- def user_home_relative_path(rel)
87
- user_home + rel
88
- end
89
-
90
- def app_home_relative_path(rel)
91
- app_home + rel
92
- end
93
-
94
- def relative_path(rel)
95
- base_dir + rel
96
- end
97
-
98
- def read_file_if_exist(path)
99
- return nil unless File.exist?(path)
100
- File.read(path)
101
- end
102
-
103
- def date(str)
104
- Date.parse(str)
105
- end
106
-
107
- def ymd(date)
108
- date.strftime('%Y-%m-%d')
109
- end
110
-
111
- def attribute_tables(attr)
112
- all_tables.select {|table| table.attributes.include?(attr) }
113
- end
114
-
115
- def all_tables
116
- Dir.glob("#{app_home}/*/*.ct").map {|path|
117
- SQLStatement.new(FileResource.new(path))
118
- }
119
- end
120
- end
121
-
122
- class ConfigLoader
123
- include EmbeddedCodeAPI
124
- end
125
-
126
82
  end
@@ -0,0 +1,50 @@
1
+ require 'bricolage/vacuumlock'
2
+
3
+ module Bricolage
4
+
5
+ module EmbeddedCodeAPI
6
+ private
7
+
8
+ def user_home
9
+ Pathname(ENV['HOME'])
10
+ end
11
+
12
+ def user_home_relative_path(rel)
13
+ user_home + rel
14
+ end
15
+
16
+ def app_home_relative_path(rel)
17
+ app_home + rel
18
+ end
19
+
20
+ def relative_path(rel)
21
+ base_dir + rel
22
+ end
23
+
24
+ def read_file_if_exist(path)
25
+ return nil unless File.exist?(path)
26
+ File.read(path)
27
+ end
28
+
29
+ def date(str)
30
+ Date.parse(str)
31
+ end
32
+
33
+ def ymd(date)
34
+ date.strftime('%Y-%m-%d')
35
+ end
36
+
37
+ def attribute_tables(attr)
38
+ all_tables.select {|table| table.attributes.include?(attr) }
39
+ end
40
+
41
+ def all_tables
42
+ Dir.glob("#{app_home}/*/*.ct").map {|path|
43
+ SQLStatement.new(FileResource.new(path))
44
+ }
45
+ end
46
+
47
+ include VacuumLock
48
+ end
49
+
50
+ end
@@ -25,6 +25,10 @@ module Bricolage
25
25
  attr_reader :original
26
26
  end
27
27
 
28
+ ##
29
+ # Aquiring lock takes too long (e.g. VACUUM lock)
30
+ class LockTimeout < JobFailure; end
31
+
28
32
  ##
29
33
  # Job error.
30
34
  # This exception should NOT be thrown in production environment.
@@ -3,6 +3,7 @@ require 'bricolage/s3datasource'
3
3
  require 'bricolage/sqlstatement'
4
4
  require 'bricolage/commandutils'
5
5
  require 'bricolage/postgresconnection'
6
+ require 'bricolage/vacuumlock'
6
7
  require 'bricolage/exception'
7
8
  require 'pathname'
8
9
 
@@ -116,12 +117,18 @@ module Bricolage
116
117
  open {|conn| conn.select(table, &block) }
117
118
  end
118
119
 
120
+ include VacuumLock
121
+
119
122
  def vacuum(table)
120
- open {|conn| conn.vacuum(table) }
123
+ serialize_vacuum {
124
+ open {|conn| conn.vacuum(table) }
125
+ }
121
126
  end
122
127
 
123
128
  def vacuum_sort_only(table)
124
- open {|conn| conn.vacuum_sort_only(table) }
129
+ serialize_vacuum {
130
+ open {|conn| conn.vacuum_sort_only(table) }
131
+ }
125
132
  end
126
133
 
127
134
  def analyze(table)
@@ -254,21 +261,12 @@ module Bricolage
254
261
  end
255
262
  end
256
263
 
257
- DEFAULT_VACUUM_LOCK_FILE = '/tmp/bricolage.vacuum.lock'
258
- DEFAULT_VACUUM_LOCK_TIMEOUT = 3600 # 60min
264
+ include VacuumLock
259
265
 
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}"
266
+ def serialize_vacuum # override
267
+ exec SQLStatement.for_string psql_serialize_vacuum_begin
270
268
  yield
271
- exec SQLStatement.for_string "\\! rm #{path}"
269
+ exec SQLStatement.for_string psql_serialize_vacuum_end
272
270
  end
273
271
 
274
272
  def analyze_if(enabled, target = '${dest_table}')
@@ -467,5 +465,4 @@ module Bricolage
467
465
  end
468
466
  end
469
467
 
470
-
471
468
  end
@@ -0,0 +1,77 @@
1
+ require 'bricolage/exception'
2
+
3
+ module Bricolage
4
+
5
+ module VacuumLock
6
+ def enable_vacuum_lock?
7
+ !!ENV['BRICOLAGE_VACUUM_LOCK']
8
+ end
9
+
10
+ DEFAULT_VACUUM_LOCK_FILE = '/tmp/bricolage.vacuum.lock'
11
+ DEFAULT_VACUUM_LOCK_TIMEOUT = 3600 # 60min
12
+
13
+ def vacuum_lock_parameters
14
+ return nil unless enable_vacuum_lock?
15
+ path, tm = ENV['BRICOLAGE_VACUUM_LOCK'].split(':', 2)
16
+ timeout = tm ? [tm.to_i, 1].max : DEFAULT_VACUUM_LOCK_TIMEOUT
17
+ return path, timeout
18
+ end
19
+ module_function :vacuum_lock_parameters
20
+
21
+ def psql_serialize_vacuum_begin
22
+ if enable_vacuum_lock?
23
+ path, timeout = vacuum_lock_parameters
24
+ "\\! #{create_lockfile_cmd} #{path} #{timeout}"
25
+ else
26
+ ';'
27
+ end
28
+ end
29
+ module_function :psql_serialize_vacuum_begin
30
+
31
+ def psql_serialize_vacuum_end
32
+ if enable_vacuum_lock?
33
+ path, timeout = vacuum_lock_parameters
34
+ "\\! rm #{path}"
35
+ else
36
+ ';'
37
+ end
38
+ end
39
+ module_function :psql_serialize_vacuum_end
40
+
41
+ def create_lockfile_cmd
42
+ Pathname(__FILE__).parent.parent.parent + 'libexec/create-lockfile'
43
+ end
44
+ module_function :create_lockfile_cmd
45
+
46
+ def serialize_vacuum
47
+ return yield unless enable_vacuum_lock?
48
+ path, timeout = vacuum_lock_parameters
49
+ create_vacuum_lock_file path, timeout
50
+ begin
51
+ yield
52
+ ensure
53
+ FileUtils.rm_f path
54
+ end
55
+ end
56
+ module_function :serialize_vacuum
57
+
58
+ def create_vacuum_lock_file(path, timeout)
59
+ start_time = Time.now
60
+ begin
61
+ File.open(path, File::WRONLY | File::CREAT | File::EXCL) {|f|
62
+ f.puts "#{Time.now}: created by bricolage [#{Process.pid}]"
63
+ }
64
+ rescue Errno::EEXIST
65
+ if Time.now - start_time > timeout
66
+ raise LockTimeout, "could not create lock file: #{path} (timeout #{timeout} seconds)"
67
+ end
68
+ sleep 1
69
+ retry
70
+ rescue
71
+ raise
72
+ end
73
+ end
74
+ module_function :create_vacuum_lock_file
75
+ end
76
+
77
+ end
@@ -1,4 +1,4 @@
1
1
  module Bricolage
2
2
  APPLICATION_NAME = 'Bricolage'
3
- VERSION = '5.9.1'
3
+ VERSION = '5.9.2'
4
4
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- bricolage (5.9.0)
4
+ bricolage (5.9.2)
5
5
  aws-sdk (< 2)
6
6
  mysql2
7
7
  pg
@@ -0,0 +1,7 @@
1
+ /*
2
+ class: sql
3
+ */
4
+
5
+ <%= psql_serialize_vacuum_begin %>
6
+ vacuum s;
7
+ <%= psql_serialize_vacuum_end %>
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift '../../lib'
2
+ require 'bricolage/psqldatasource'
3
+
4
+ ds = Bricolage::PSQLDataSource.new(port: 5444, database: 'production', username: 'aamine', pgpass: "#{ENV['HOME']}/.pgpass")
5
+ ds.__send__ :initialize_base, 'tmp', nil, Logger.new($stderr)
6
+ p ds
7
+ ds.vacuum 's'
8
+ puts 'OK'
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.9.1
4
+ version: 5.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minero Aoki
@@ -128,6 +128,7 @@ files:
128
128
  - lib/bricolage/configloader.rb
129
129
  - lib/bricolage/context.rb
130
130
  - lib/bricolage/datasource.rb
131
+ - lib/bricolage/embeddedcodeapi.rb
131
132
  - lib/bricolage/eventhandlers.rb
132
133
  - lib/bricolage/exception.rb
133
134
  - lib/bricolage/filedatasource.rb
@@ -151,6 +152,7 @@ files:
151
152
  - lib/bricolage/sqlstatement.rb
152
153
  - lib/bricolage/taskqueue.rb
153
154
  - lib/bricolage/tddatasource.rb
155
+ - lib/bricolage/vacuumlock.rb
154
156
  - lib/bricolage/variables.rb
155
157
  - lib/bricolage/version.rb
156
158
  - libexec/create-lockfile
@@ -170,6 +172,7 @@ files:
170
172
  - test/home/subsys/d.ct
171
173
  - test/home/subsys/load_test.ct
172
174
  - test/home/subsys/load_test.job
175
+ - test/home/subsys/raw-vacuum.sql.job
173
176
  - test/home/subsys/rebuild.sql.job
174
177
  - test/home/subsys/separated.job
175
178
  - test/home/subsys/separated.sql
@@ -178,6 +181,7 @@ files:
178
181
  - test/test_filesystem.rb
179
182
  - test/test_parameters.rb
180
183
  - test/test_variables.rb
184
+ - test/vacuum-test.rb
181
185
  homepage: https://github.com/aamine/bricolage
182
186
  licenses:
183
187
  - MIT