tengine_core 0.5.28 → 0.5.30
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/tengine/core/kernel.rb +2 -1
- data/lib/tengine/core/mutex.rb +9 -10
- data/lib/tengine/core/optimistic_lock.rb +8 -7
- data/lib/tengine/core/safe_updatable.rb +35 -0
- data/lib/tengine/core/scheduler.rb +5 -1
- data/lib/tengine/core.rb +1 -0
- data/spec/tengine/core/dsls/uc52_never_commit_event_unless_all_handler_submit_spec.rb +1 -0
- data/tengine_core.gemspec +4 -3
- metadata +43 -44
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.30
|
data/lib/tengine/core/kernel.rb
CHANGED
@@ -196,8 +196,9 @@ class Tengine::Core::Kernel
|
|
196
196
|
handlers = find_handlers(event)
|
197
197
|
safty_handlers(handlers) do
|
198
198
|
delegate(event, handlers)
|
199
|
-
|
199
|
+
ack if all_submitted?
|
200
200
|
end
|
201
|
+
headers.reject(:requeue => true) unless ack?
|
201
202
|
end
|
202
203
|
close_if_shutting_down
|
203
204
|
true
|
data/lib/tengine/core/mutex.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require 'tengine/core'
|
3
3
|
|
4
|
+
require_relative 'safe_updatable'
|
5
|
+
|
4
6
|
# Tengine::Core::Mutexは(若干残念な実装の)分散ロック機構です。これを用
|
5
7
|
# いることで、とあるMutexをロックしているプロセスを同時にたかだか一つに
|
6
8
|
# 制限することが可能になります。
|
@@ -47,6 +49,7 @@ Tengine::Core::Mutex = Struct.new :mutex, :_id, :recursive
|
|
47
49
|
class Tengine::Core::Mutex::Mutex
|
48
50
|
|
49
51
|
include Mongoid::Document
|
52
|
+
include Tengine::Core::SafeUpdatable
|
50
53
|
|
51
54
|
field :ttl, :type => Float
|
52
55
|
field :waiters, :type => Array
|
@@ -64,16 +67,12 @@ class Tengine::Core::Mutex::Mutex
|
|
64
67
|
|
65
68
|
# 暫定対応[Bug]mongodbフェールオーバ中にtengine_resource_watchdが落ちてしまう
|
66
69
|
def _update q = {}, r
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
idx += 1
|
74
|
-
sleep 0.5
|
75
|
-
retry if retry_count > idx
|
76
|
-
end
|
70
|
+
update_in_safe_mode(
|
71
|
+
self.class.collection,
|
72
|
+
{ :_id => _id, }.update(q),
|
73
|
+
r
|
74
|
+
)
|
75
|
+
reload
|
77
76
|
end
|
78
77
|
|
79
78
|
public
|
@@ -5,6 +5,7 @@ require 'active_support/core_ext/array/extract_options'
|
|
5
5
|
|
6
6
|
module Tengine::Core::OptimisticLock
|
7
7
|
extend ActiveSupport::Concern
|
8
|
+
include Tengine::Core::SafeUpdatable
|
8
9
|
|
9
10
|
included do
|
10
11
|
cattr_accessor :lock_optimistically, :instance_writer => false
|
@@ -23,25 +24,25 @@ module Tengine::Core::OptimisticLock
|
|
23
24
|
idx = 1
|
24
25
|
while idx <= retry_count
|
25
26
|
yield
|
26
|
-
return if
|
27
|
+
return if __update_with_lock__
|
27
28
|
reload
|
28
29
|
idx += 1
|
29
30
|
end
|
30
31
|
raise RetryOverError, "retried #{retry_count} times but failed to update"
|
31
32
|
end
|
32
33
|
|
33
|
-
def
|
34
|
+
def __update_with_lock__
|
34
35
|
lock_field_name = self.class.locking_field
|
35
36
|
current_version = self.send(lock_field_name)
|
36
37
|
hash = as_document.dup
|
37
38
|
new_version = current_version + 1
|
38
39
|
hash[lock_field_name] = new_version
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
|
41
|
+
selector = { :_id => self.id, lock_field_name.to_sym => current_version }
|
42
|
+
result = update_in_safe_mode(self.class.collection, selector, hash)
|
43
|
+
|
43
44
|
send("#{lock_field_name}=", new_version)
|
44
|
-
result
|
45
|
+
result["updatedExisting"] && !result["err"]
|
45
46
|
end
|
46
47
|
|
47
48
|
# ActiveRecord::Locking::Optimistic::ClassMethods を参考に実装しています
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'tengine/core'
|
2
|
+
|
3
|
+
module Tengine::Core::SafeUpdatable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module InstanceMethods
|
7
|
+
def update_in_safe_mode(collection, selector, document, opts=nil)
|
8
|
+
options = { :upsert => false, :multiple => false }
|
9
|
+
options.update(opts) if opts
|
10
|
+
|
11
|
+
options = options.merge({ :safe => safemode(collection) })
|
12
|
+
|
13
|
+
max_retries = 100
|
14
|
+
retries = 0
|
15
|
+
begin
|
16
|
+
# Return a Hash containing the last error object if running safe mode.
|
17
|
+
# Otherwise, returns true
|
18
|
+
result = collection.driver.update(selector, document, options)
|
19
|
+
rescue Mongo::ConnectionFailure => ex
|
20
|
+
retries += 1
|
21
|
+
raise ex if retries > max_retries
|
22
|
+
sleep 0.5
|
23
|
+
retry
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def safemode(collection)
|
28
|
+
res = true
|
29
|
+
case collection.driver.db.connection when Mongo::ReplSetConnection then
|
30
|
+
res = { :w => "majority", :wtimeout => 1024, }
|
31
|
+
end
|
32
|
+
res
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -15,8 +15,10 @@ require_relative 'config/atd'
|
|
15
15
|
require_relative 'method_traceable'
|
16
16
|
require_relative 'schedule'
|
17
17
|
require_relative 'mongoid_fix'
|
18
|
+
require_relative 'safe_updatable'
|
18
19
|
|
19
20
|
class Tengine::Core::Scheduler
|
21
|
+
include Tengine::Core::SafeUpdatable
|
20
22
|
|
21
23
|
def initialize argv
|
22
24
|
@uuid = UUID.new.generate
|
@@ -62,7 +64,9 @@ class Tengine::Core::Scheduler
|
|
62
64
|
# 複数のマシンで複数のatdが複数動いている可能性があり、その場合には複数の
|
63
65
|
# atdが同時に同じエントリに更新をかける可能性はとても高い。そのような状況
|
64
66
|
# でもエラーになってはいけない。
|
65
|
-
Tengine::Core::Schedule.
|
67
|
+
Tengine::Core::Schedule.safely(
|
68
|
+
safemode(Tengine::Core::Schedule.collection)
|
69
|
+
).where(
|
66
70
|
:_id => sched.id,
|
67
71
|
:status => Tengine::Core::Schedule::SCHEDULED
|
68
72
|
).update_all(
|
data/lib/tengine/core.rb
CHANGED
@@ -37,6 +37,7 @@ module Tengine::Core
|
|
37
37
|
autoload :EventExceptionReportable, 'tengine/core/event_exception_reportable'
|
38
38
|
autoload :FindByName , 'tengine/core/find_by_name'
|
39
39
|
autoload :Mutex , 'tengine/core/mutex'
|
40
|
+
autoload :SafeUpdatable , 'tengine/core/safe_updatable'
|
40
41
|
|
41
42
|
class << self
|
42
43
|
# Tengine::Coreの正常時の動きをアプリケーション運用者が確認できる内容を出力するロガー
|
@@ -26,6 +26,7 @@ describe "uc52_commit_event_after_all_handler_submit" do
|
|
26
26
|
STDOUT.should_receive(:puts).with("handler52_alt1_3 unacknowledged")
|
27
27
|
mock_headers = mock(:headers)
|
28
28
|
mock_headers.should_not_receive(:ack)
|
29
|
+
mock_headers.should_receive(:reject).with(:requeue => true)
|
29
30
|
raw_event = Tengine::Event.new(:event_type_name => "event52_alt1")
|
30
31
|
@kernel.before_delegate = lambda do
|
31
32
|
@kernel.all_submitted?.should == false
|
data/tengine_core.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "tengine_core"
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.30"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["taigou", "totty", "g-morita", "shyouhei", "akm", "hiroshinakao"]
|
12
|
-
s.date = "2012-02-
|
12
|
+
s.date = "2012-02-14"
|
13
13
|
s.description = "tengine_core is a framework/engine to support distributed processing"
|
14
14
|
s.email = "tengine@nautilus-technologies.com"
|
15
15
|
s.executables = ["tengined", "tengine_heartbeat_watchd", "tengine_atd"]
|
@@ -89,6 +89,7 @@ Gem::Specification.new do |s|
|
|
89
89
|
"lib/tengine/core/mutex.rb",
|
90
90
|
"lib/tengine/core/optimistic_lock.rb",
|
91
91
|
"lib/tengine/core/plugins.rb",
|
92
|
+
"lib/tengine/core/safe_updatable.rb",
|
92
93
|
"lib/tengine/core/schedule.rb",
|
93
94
|
"lib/tengine/core/scheduler.rb",
|
94
95
|
"lib/tengine/core/selectable_attr.rb",
|
@@ -176,7 +177,7 @@ Gem::Specification.new do |s|
|
|
176
177
|
s.homepage = "http://github.com/tengine/tengine_core"
|
177
178
|
s.licenses = ["MPL2.0/LGPLv3"]
|
178
179
|
s.require_paths = ["lib"]
|
179
|
-
s.rubygems_version = "1.8.
|
180
|
+
s.rubygems_version = "1.8.10"
|
180
181
|
s.summary = "tengine_core is a framework/engine to support distributed processing"
|
181
182
|
|
182
183
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tengine_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.30
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,11 +14,11 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2012-02-
|
17
|
+
date: 2012-02-14 00:00:00.000000000Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: activesupport
|
21
|
-
requirement: &
|
21
|
+
requirement: &70145822864700 !ruby/object:Gem::Requirement
|
22
22
|
none: false
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
@@ -26,10 +26,10 @@ dependencies:
|
|
26
26
|
version: 3.1.0
|
27
27
|
type: :runtime
|
28
28
|
prerelease: false
|
29
|
-
version_requirements: *
|
29
|
+
version_requirements: *70145822864700
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: activemodel
|
32
|
-
requirement: &
|
32
|
+
requirement: &70145822864160 !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
@@ -37,10 +37,10 @@ dependencies:
|
|
37
37
|
version: 3.1.0
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
|
-
version_requirements: *
|
40
|
+
version_requirements: *70145822864160
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: selectable_attr
|
43
|
-
requirement: &
|
43
|
+
requirement: &70145822863660 !ruby/object:Gem::Requirement
|
44
44
|
none: false
|
45
45
|
requirements:
|
46
46
|
- - ~>
|
@@ -48,10 +48,10 @@ dependencies:
|
|
48
48
|
version: 0.3.15
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
|
-
version_requirements: *
|
51
|
+
version_requirements: *70145822863660
|
52
52
|
- !ruby/object:Gem::Dependency
|
53
53
|
name: bson
|
54
|
-
requirement: &
|
54
|
+
requirement: &70145822863140 !ruby/object:Gem::Requirement
|
55
55
|
none: false
|
56
56
|
requirements:
|
57
57
|
- - ~>
|
@@ -59,10 +59,10 @@ dependencies:
|
|
59
59
|
version: 1.5.2
|
60
60
|
type: :runtime
|
61
61
|
prerelease: false
|
62
|
-
version_requirements: *
|
62
|
+
version_requirements: *70145822863140
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
64
|
name: bson_ext
|
65
|
-
requirement: &
|
65
|
+
requirement: &70145822862640 !ruby/object:Gem::Requirement
|
66
66
|
none: false
|
67
67
|
requirements:
|
68
68
|
- - ~>
|
@@ -70,10 +70,10 @@ dependencies:
|
|
70
70
|
version: 1.5.2
|
71
71
|
type: :runtime
|
72
72
|
prerelease: false
|
73
|
-
version_requirements: *
|
73
|
+
version_requirements: *70145822862640
|
74
74
|
- !ruby/object:Gem::Dependency
|
75
75
|
name: mongo
|
76
|
-
requirement: &
|
76
|
+
requirement: &70145822862080 !ruby/object:Gem::Requirement
|
77
77
|
none: false
|
78
78
|
requirements:
|
79
79
|
- - ~>
|
@@ -81,10 +81,10 @@ dependencies:
|
|
81
81
|
version: 1.5.2
|
82
82
|
type: :runtime
|
83
83
|
prerelease: false
|
84
|
-
version_requirements: *
|
84
|
+
version_requirements: *70145822862080
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: mongoid
|
87
|
-
requirement: &
|
87
|
+
requirement: &70145822861580 !ruby/object:Gem::Requirement
|
88
88
|
none: false
|
89
89
|
requirements:
|
90
90
|
- - ~>
|
@@ -92,10 +92,10 @@ dependencies:
|
|
92
92
|
version: 2.3.3
|
93
93
|
type: :runtime
|
94
94
|
prerelease: false
|
95
|
-
version_requirements: *
|
95
|
+
version_requirements: *70145822861580
|
96
96
|
- !ruby/object:Gem::Dependency
|
97
97
|
name: tengine_support
|
98
|
-
requirement: &
|
98
|
+
requirement: &70145822861080 !ruby/object:Gem::Requirement
|
99
99
|
none: false
|
100
100
|
requirements:
|
101
101
|
- - ~>
|
@@ -103,10 +103,10 @@ dependencies:
|
|
103
103
|
version: 0.3.12
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
|
-
version_requirements: *
|
106
|
+
version_requirements: *70145822861080
|
107
107
|
- !ruby/object:Gem::Dependency
|
108
108
|
name: tengine_event
|
109
|
-
requirement: &
|
109
|
+
requirement: &70145822860580 !ruby/object:Gem::Requirement
|
110
110
|
none: false
|
111
111
|
requirements:
|
112
112
|
- - ~>
|
@@ -114,10 +114,10 @@ dependencies:
|
|
114
114
|
version: 0.4.0
|
115
115
|
type: :runtime
|
116
116
|
prerelease: false
|
117
|
-
version_requirements: *
|
117
|
+
version_requirements: *70145822860580
|
118
118
|
- !ruby/object:Gem::Dependency
|
119
119
|
name: daemons
|
120
|
-
requirement: &
|
120
|
+
requirement: &70145822860100 !ruby/object:Gem::Requirement
|
121
121
|
none: false
|
122
122
|
requirements:
|
123
123
|
- - ~>
|
@@ -125,10 +125,10 @@ dependencies:
|
|
125
125
|
version: 1.1.4
|
126
126
|
type: :runtime
|
127
127
|
prerelease: false
|
128
|
-
version_requirements: *
|
128
|
+
version_requirements: *70145822860100
|
129
129
|
- !ruby/object:Gem::Dependency
|
130
130
|
name: rspec
|
131
|
-
requirement: &
|
131
|
+
requirement: &70145822859580 !ruby/object:Gem::Requirement
|
132
132
|
none: false
|
133
133
|
requirements:
|
134
134
|
- - ~>
|
@@ -136,10 +136,10 @@ dependencies:
|
|
136
136
|
version: 2.6.0
|
137
137
|
type: :development
|
138
138
|
prerelease: false
|
139
|
-
version_requirements: *
|
139
|
+
version_requirements: *70145822859580
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
141
|
name: factory_girl
|
142
|
-
requirement: &
|
142
|
+
requirement: &70145822859080 !ruby/object:Gem::Requirement
|
143
143
|
none: false
|
144
144
|
requirements:
|
145
145
|
- - ~>
|
@@ -147,10 +147,10 @@ dependencies:
|
|
147
147
|
version: 2.1.2
|
148
148
|
type: :development
|
149
149
|
prerelease: false
|
150
|
-
version_requirements: *
|
150
|
+
version_requirements: *70145822859080
|
151
151
|
- !ruby/object:Gem::Dependency
|
152
152
|
name: yard
|
153
|
-
requirement: &
|
153
|
+
requirement: &70145822858600 !ruby/object:Gem::Requirement
|
154
154
|
none: false
|
155
155
|
requirements:
|
156
156
|
- - ~>
|
@@ -158,10 +158,10 @@ dependencies:
|
|
158
158
|
version: 0.7.2
|
159
159
|
type: :development
|
160
160
|
prerelease: false
|
161
|
-
version_requirements: *
|
161
|
+
version_requirements: *70145822858600
|
162
162
|
- !ruby/object:Gem::Dependency
|
163
163
|
name: bundler
|
164
|
-
requirement: &
|
164
|
+
requirement: &70145822858080 !ruby/object:Gem::Requirement
|
165
165
|
none: false
|
166
166
|
requirements:
|
167
167
|
- - ~>
|
@@ -169,10 +169,10 @@ dependencies:
|
|
169
169
|
version: 1.0.18
|
170
170
|
type: :development
|
171
171
|
prerelease: false
|
172
|
-
version_requirements: *
|
172
|
+
version_requirements: *70145822858080
|
173
173
|
- !ruby/object:Gem::Dependency
|
174
174
|
name: jeweler
|
175
|
-
requirement: &
|
175
|
+
requirement: &70145822857580 !ruby/object:Gem::Requirement
|
176
176
|
none: false
|
177
177
|
requirements:
|
178
178
|
- - ~>
|
@@ -180,10 +180,10 @@ dependencies:
|
|
180
180
|
version: 1.6.4
|
181
181
|
type: :development
|
182
182
|
prerelease: false
|
183
|
-
version_requirements: *
|
183
|
+
version_requirements: *70145822857580
|
184
184
|
- !ruby/object:Gem::Dependency
|
185
185
|
name: simplecov
|
186
|
-
requirement: &
|
186
|
+
requirement: &70145822857080 !ruby/object:Gem::Requirement
|
187
187
|
none: false
|
188
188
|
requirements:
|
189
189
|
- - ~>
|
@@ -191,10 +191,10 @@ dependencies:
|
|
191
191
|
version: 0.5.3
|
192
192
|
type: :development
|
193
193
|
prerelease: false
|
194
|
-
version_requirements: *
|
194
|
+
version_requirements: *70145822857080
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: ZenTest
|
197
|
-
requirement: &
|
197
|
+
requirement: &70145822856600 !ruby/object:Gem::Requirement
|
198
198
|
none: false
|
199
199
|
requirements:
|
200
200
|
- - ~>
|
@@ -202,10 +202,10 @@ dependencies:
|
|
202
202
|
version: 4.6.2
|
203
203
|
type: :development
|
204
204
|
prerelease: false
|
205
|
-
version_requirements: *
|
205
|
+
version_requirements: *70145822856600
|
206
206
|
- !ruby/object:Gem::Dependency
|
207
207
|
name: rdiscount
|
208
|
-
requirement: &
|
208
|
+
requirement: &70145822856120 !ruby/object:Gem::Requirement
|
209
209
|
none: false
|
210
210
|
requirements:
|
211
211
|
- - ! '>='
|
@@ -213,10 +213,10 @@ dependencies:
|
|
213
213
|
version: '0'
|
214
214
|
type: :development
|
215
215
|
prerelease: false
|
216
|
-
version_requirements: *
|
216
|
+
version_requirements: *70145822856120
|
217
217
|
- !ruby/object:Gem::Dependency
|
218
218
|
name: kramdown
|
219
|
-
requirement: &
|
219
|
+
requirement: &70145822855640 !ruby/object:Gem::Requirement
|
220
220
|
none: false
|
221
221
|
requirements:
|
222
222
|
- - ! '>='
|
@@ -224,7 +224,7 @@ dependencies:
|
|
224
224
|
version: '0'
|
225
225
|
type: :development
|
226
226
|
prerelease: false
|
227
|
-
version_requirements: *
|
227
|
+
version_requirements: *70145822855640
|
228
228
|
description: tengine_core is a framework/engine to support distributed processing
|
229
229
|
email: tengine@nautilus-technologies.com
|
230
230
|
executables:
|
@@ -307,6 +307,7 @@ files:
|
|
307
307
|
- lib/tengine/core/mutex.rb
|
308
308
|
- lib/tengine/core/optimistic_lock.rb
|
309
309
|
- lib/tengine/core/plugins.rb
|
310
|
+
- lib/tengine/core/safe_updatable.rb
|
310
311
|
- lib/tengine/core/schedule.rb
|
311
312
|
- lib/tengine/core/scheduler.rb
|
312
313
|
- lib/tengine/core/selectable_attr.rb
|
@@ -403,9 +404,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
403
404
|
- - ! '>='
|
404
405
|
- !ruby/object:Gem::Version
|
405
406
|
version: '0'
|
406
|
-
segments:
|
407
|
-
- 0
|
408
|
-
hash: -3873339066918298053
|
409
407
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
410
408
|
none: false
|
411
409
|
requirements:
|
@@ -414,8 +412,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
414
412
|
version: '0'
|
415
413
|
requirements: []
|
416
414
|
rubyforge_project:
|
417
|
-
rubygems_version: 1.8.
|
415
|
+
rubygems_version: 1.8.16
|
418
416
|
signing_key:
|
419
417
|
specification_version: 3
|
420
418
|
summary: tengine_core is a framework/engine to support distributed processing
|
421
419
|
test_files: []
|
420
|
+
has_rdoc:
|