Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
268b34a7
提交
268b34a7
authored
11 年前
作者:
noelgrandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix multi-threaded deadlock when using a View that includes a TableFunction.
上级
6257fb79
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
60 行增加
和
13 行删除
+60
-13
TableView.java
h2/src/main/org/h2/table/TableView.java
+60
-13
没有找到文件。
h2/src/main/org/h2/table/TableView.java
浏览文件 @
268b34a7
...
...
@@ -7,8 +7,8 @@
package
org
.
h2
.
table
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.Prepared
;
import
org.h2.command.dml.Query
;
...
...
@@ -30,13 +30,11 @@ import org.h2.result.ResultInterface;
import
org.h2.result.Row
;
import
org.h2.result.SortOrder
;
import
org.h2.schema.Schema
;
import
org.h2.util.IntArray
;
import
org.h2.util.New
;
import
org.h2.util.SmallLRUCache
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.util.SynchronizedVerifier
;
import
org.h2.util.Utils
;
import
org.h2.value.Value
;
/**
...
...
@@ -47,6 +45,41 @@ import org.h2.value.Value;
public
class
TableView
extends
Table
{
private
static
final
long
ROW_COUNT_APPROXIMATION
=
100
;
private
static
final
class
CacheKey
{
private
final
int
[]
masks
;
private
final
Session
session
;
public
CacheKey
(
int
[]
masks
,
Session
session
)
{
this
.
masks
=
masks
;
this
.
session
=
session
;
}
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
Arrays
.
hashCode
(
masks
);
result
=
prime
*
result
+
session
.
hashCode
();
return
result
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
CacheKey
other
=
(
CacheKey
)
obj
;
if
(!
Arrays
.
equals
(
masks
,
other
.
masks
))
return
false
;
if
(
session
!=
other
.
session
)
return
false
;
return
true
;
}
}
private
String
querySQL
;
private
ArrayList
<
Table
>
tables
;
...
...
@@ -55,7 +88,7 @@ public class TableView extends Table {
private
ViewIndex
index
;
private
boolean
recursive
;
private
DbException
createException
;
private
final
SmallLRUCache
<
IntArra
y
,
ViewIndex
>
indexCache
=
private
final
SmallLRUCache
<
CacheKe
y
,
ViewIndex
>
indexCache
=
SmallLRUCache
.
newInstance
(
Constants
.
VIEW_INDEX_CACHE_SIZE
);
private
long
lastModificationCheck
;
private
long
maxDataModificationId
;
...
...
@@ -228,19 +261,33 @@ public class TableView extends Table {
}
@Override
public
synchronized
PlanItem
getBestPlanItem
(
Session
session
,
int
[]
masks
,
public
PlanItem
getBestPlanItem
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
PlanItem
item
=
new
PlanItem
();
item
.
cost
=
index
.
getCost
(
session
,
masks
,
filter
,
sortOrder
);
IntArray
masksArray
=
new
IntArray
(
masks
==
null
?
Utils
.
EMPTY_INT_ARRAY
:
masks
);
SynchronizedVerifier
.
check
(
indexCache
);
ViewIndex
i2
=
indexCache
.
get
(
masksArray
);
if
(
i2
==
null
||
i2
.
getSession
()
!=
session
)
{
i2
=
new
ViewIndex
(
this
,
index
,
session
,
masks
);
indexCache
.
put
(
masksArray
,
i2
);
final
CacheKey
cacheKey
=
new
CacheKey
(
masks
,
session
);
synchronized
(
this
)
{
SynchronizedVerifier
.
check
(
indexCache
);
ViewIndex
i2
=
indexCache
.
get
(
cacheKey
);
if
(
i2
!=
null
)
{
item
.
setIndex
(
i2
);
return
item
;
}
}
// We cannot hold the lock during the ViewIndex creation or we risk ABBA deadlocks
// if the view creation calls back into H2 via something like a FunctionTable.
ViewIndex
i2
=
new
ViewIndex
(
this
,
index
,
session
,
masks
);
synchronized
(
this
)
{
// have to check again in case another session has beat us to it
ViewIndex
i3
=
indexCache
.
get
(
cacheKey
);
if
(
i3
!=
null
)
{
item
.
setIndex
(
i3
);
return
item
;
}
indexCache
.
put
(
cacheKey
,
i2
);
item
.
setIndex
(
i2
);
}
item
.
setIndex
(
i2
);
return
item
;
}
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论