Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f1b35267
提交
f1b35267
authored
10月 03, 2018
作者:
Andrei Tokar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MVTable.lastModificationId race condition
上级
e9b9edb6
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
30 行增加
和
18 行删除
+30
-18
Query.java
h2/src/main/org/h2/command/dml/Query.java
+6
-10
MVTable.java
h2/src/main/org/h2/mvstore/db/MVTable.java
+24
-8
没有找到文件。
h2/src/main/org/h2/command/dml/Query.java
浏览文件 @
f1b35267
...
@@ -344,6 +344,10 @@ public abstract class Query extends Prepared {
...
@@ -344,6 +344,10 @@ public abstract class Query extends Prepared {
if
(!
cacheableChecked
)
{
if
(!
cacheableChecked
)
{
long
max
=
getMaxDataModificationId
();
long
max
=
getMaxDataModificationId
();
noCache
=
max
==
Long
.
MAX_VALUE
;
noCache
=
max
==
Long
.
MAX_VALUE
;
if
(!
isEverything
(
ExpressionVisitor
.
DETERMINISTIC_VISITOR
)
||
!
isEverything
(
ExpressionVisitor
.
INDEPENDENT_VISITOR
))
{
noCache
=
true
;
}
cacheableChecked
=
true
;
cacheableChecked
=
true
;
}
}
if
(
noCache
)
{
if
(
noCache
)
{
...
@@ -356,18 +360,10 @@ public abstract class Query extends Prepared {
...
@@ -356,18 +360,10 @@ public abstract class Query extends Prepared {
return
false
;
return
false
;
}
}
}
}
if
(!
isEverything
(
ExpressionVisitor
.
DETERMINISTIC_VISITOR
)
||
return
getMaxDataModificationId
()
<=
lastEval
;
!
isEverything
(
ExpressionVisitor
.
INDEPENDENT_VISITOR
))
{
return
false
;
}
if
(
db
.
getModificationDataId
()
>
lastEval
&&
getMaxDataModificationId
()
>
lastEval
)
{
return
false
;
}
return
true
;
}
}
p
ublic
final
Value
[]
getParameterValues
()
{
p
rivate
Value
[]
getParameterValues
()
{
ArrayList
<
Parameter
>
list
=
getParameters
();
ArrayList
<
Parameter
>
list
=
getParameters
();
if
(
list
==
null
)
{
if
(
list
==
null
)
{
return
new
Value
[
0
];
return
new
Value
[
0
];
...
...
h2/src/main/org/h2/mvstore/db/MVTable.java
浏览文件 @
f1b35267
...
@@ -14,6 +14,7 @@ import java.util.Set;
...
@@ -14,6 +14,7 @@ import java.util.Set;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicLong
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
...
@@ -105,7 +106,7 @@ public class MVTable extends TableBase {
...
@@ -105,7 +106,7 @@ public class MVTable extends TableBase {
private
MVPrimaryIndex
primaryIndex
;
private
MVPrimaryIndex
primaryIndex
;
private
final
ArrayList
<
Index
>
indexes
=
Utils
.
newSmallArrayList
();
private
final
ArrayList
<
Index
>
indexes
=
Utils
.
newSmallArrayList
();
private
volatile
long
lastModificationId
;
private
final
AtomicLong
lastModificationId
=
new
AtomicLong
()
;
private
volatile
Session
lockExclusiveSession
;
private
volatile
Session
lockExclusiveSession
;
// using a ConcurrentHashMap as a set
// using a ConcurrentHashMap as a set
...
@@ -661,7 +662,7 @@ public class MVTable extends TableBase {
...
@@ -661,7 +662,7 @@ public class MVTable extends TableBase {
@Override
@Override
public
void
removeRow
(
Session
session
,
Row
row
)
{
public
void
removeRow
(
Session
session
,
Row
row
)
{
lastModificationId
=
database
.
getNextModificationDataId
();
syncLastModificationIdWithDatabase
();
Transaction
t
=
session
.
getTransaction
();
Transaction
t
=
session
.
getTransaction
();
long
savepoint
=
t
.
setSavepoint
();
long
savepoint
=
t
.
setSavepoint
();
try
{
try
{
...
@@ -682,7 +683,7 @@ public class MVTable extends TableBase {
...
@@ -682,7 +683,7 @@ public class MVTable extends TableBase {
@Override
@Override
public
void
truncate
(
Session
session
)
{
public
void
truncate
(
Session
session
)
{
lastModificationId
=
database
.
getNextModificationDataId
();
syncLastModificationIdWithDatabase
();
for
(
int
i
=
indexes
.
size
()
-
1
;
i
>=
0
;
i
--)
{
for
(
int
i
=
indexes
.
size
()
-
1
;
i
>=
0
;
i
--)
{
Index
index
=
indexes
.
get
(
i
);
Index
index
=
indexes
.
get
(
i
);
index
.
truncate
(
session
);
index
.
truncate
(
session
);
...
@@ -694,7 +695,7 @@ public class MVTable extends TableBase {
...
@@ -694,7 +695,7 @@ public class MVTable extends TableBase {
@Override
@Override
public
void
addRow
(
Session
session
,
Row
row
)
{
public
void
addRow
(
Session
session
,
Row
row
)
{
lastModificationId
=
database
.
getNextModificationDataId
();
syncLastModificationIdWithDatabase
();
Transaction
t
=
session
.
getTransaction
();
Transaction
t
=
session
.
getTransaction
();
long
savepoint
=
t
.
setSavepoint
();
long
savepoint
=
t
.
setSavepoint
();
try
{
try
{
...
@@ -715,7 +716,7 @@ public class MVTable extends TableBase {
...
@@ -715,7 +716,7 @@ public class MVTable extends TableBase {
@Override
@Override
public
void
updateRow
(
Session
session
,
Row
oldRow
,
Row
newRow
)
{
public
void
updateRow
(
Session
session
,
Row
oldRow
,
Row
newRow
)
{
newRow
.
setKey
(
oldRow
.
getKey
());
newRow
.
setKey
(
oldRow
.
getKey
());
lastModificationId
=
database
.
getNextModificationDataId
();
syncLastModificationIdWithDatabase
();
Transaction
t
=
session
.
getTransaction
();
Transaction
t
=
session
.
getTransaction
();
long
savepoint
=
t
.
setSavepoint
();
long
savepoint
=
t
.
setSavepoint
();
try
{
try
{
...
@@ -782,7 +783,7 @@ public class MVTable extends TableBase {
...
@@ -782,7 +783,7 @@ public class MVTable extends TableBase {
@Override
@Override
public
long
getMaxDataModificationId
()
{
public
long
getMaxDataModificationId
()
{
return
lastModificationId
;
return
lastModificationId
.
get
()
;
}
}
public
boolean
getContainsLargeObject
()
{
public
boolean
getContainsLargeObject
()
{
...
@@ -895,8 +896,23 @@ public class MVTable extends TableBase {
...
@@ -895,8 +896,23 @@ public class MVTable extends TableBase {
*/
*/
public
void
commit
()
{
public
void
commit
()
{
if
(
database
!=
null
)
{
if
(
database
!=
null
)
{
lastModificationId
=
database
.
getNextModificationDataId
();
syncLastModificationIdWithDatabase
();
}
}
}
// Field lastModificationId can not be just a volatile, because window of opportunity
// between reading database's modification id and storing this value in the field
// could be exploited by another thread.
// Second thread may do the same with possibly bigger (already advanced) modification id,
// and when first thread finally updates the field, it will result in lastModificationId jumping back.
// This is, of course, unacceptable.
private
void
syncLastModificationIdWithDatabase
()
{
long
nextModificationDataId
=
database
.
getNextModificationDataId
();
long
currentId
;
do
{
currentId
=
lastModificationId
.
get
();
}
while
(
nextModificationDataId
>
currentId
&&
!
lastModificationId
.
compareAndSet
(
currentId
,
nextModificationDataId
));
}
}
/**
/**
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论