Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
2a04110f
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2a04110f
编写于
9月 30, 2010
作者:
H
Hemant Kumar
提交者:
Aaron Patterson
10月 06, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix ruby 1.9 deadlock problem, fixes #5736 add connection pool tests
上级
a0552d65
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
8 deletion
+35
-8
activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
...ve_record/connection_adapters/abstract/connection_pool.rb
+6
-8
activerecord/test/cases/connection_pool_test.rb
activerecord/test/cases/connection_pool_test.rb
+29
-0
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
浏览文件 @
2a04110f
...
...
@@ -75,10 +75,7 @@ def initialize(spec)
@queue
=
@connection_mutex
.
new_cond
# default 5 second timeout unless on ruby 1.9
@timeout
=
if
RUBY_VERSION
<
'1.9'
spec
.
config
[
:wait_timeout
]
||
5
end
@timeout
=
spec
.
config
[
:wait_timeout
]
||
5
# default max pool size to 5
@size
=
(
spec
.
config
[
:pool
]
&&
spec
.
config
[
:pool
].
to_i
)
||
5
...
...
@@ -161,7 +158,6 @@ def clear_stale_cached_connections!
keys
=
@reserved_connections
.
keys
-
Thread
.
list
.
find_all
{
|
t
|
t
.
alive?
}.
map
{
|
thread
|
thread
.
object_id
}
keys
.
each
do
|
key
|
checkin
@reserved_connections
[
key
]
@reserved_connections
.
delete
(
key
)
...
...
@@ -194,16 +190,18 @@ def checkout
checkout_new_connection
end
return
conn
if
conn
# No connections available; wait for one
if
@queue
.
wait
(
@timeout
)
@queue
.
wait
(
@timeout
)
if
(
@checked_out
.
size
<
@connections
.
size
)
next
else
# try looting dead threads
clear_stale_cached_connections!
if
@size
==
@checked_out
.
size
raise
ConnectionTimeoutError
,
"could not obtain a database connection
#{
" within
#{
@timeout
}
seconds"
if
@timeout
}
. The max pool size is currently
#{
@size
}
; consider increasing it."
end
end
end
end
end
...
...
activerecord/test/cases/connection_pool_test.rb
浏览文件 @
2a04110f
...
...
@@ -26,6 +26,35 @@ def checkin conn
"threads should have been removed"
)
assert_equal
pool
.
checkins
.
length
,
threads
.
length
end
def
test_checkout_behaviour
pool
=
ConnectionPool
.
new
ActiveRecord
::
Base
.
connection_pool
.
spec
connection
=
pool
.
connection
assert_not_nil
connection
threads
=
[]
4
.
times
do
|
i
|
threads
<<
Thread
.
new
(
i
)
do
|
pool_count
|
connection
=
pool
.
connection
assert_not_nil
connection
end
end
threads
.
each
{
|
t
|
t
.
join
}
Thread
.
new
do
threads
.
each
do
|
t
|
thread_ids
=
pool
.
instance_variable_get
(
:@reserved_connections
).
keys
assert
thread_ids
.
include?
(
t
.
object_id
)
end
pool
.
connection
threads
.
each
do
|
t
|
thread_ids
=
pool
.
instance_variable_get
(
:@reserved_connections
).
keys
assert
!
thread_ids
.
include?
(
t
.
object_id
)
end
end
.
join
()
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录