Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
4c28636c
提交
4c28636c
authored
7月 05, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MULTI_THREADED did not work correctly.
上级
822498a8
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
141 行增加
和
88 行删除
+141
-88
PageStore.java
h2/src/main/org/h2/store/PageStore.java
+93
-88
TestMultiThreadedKernel.java
h2/src/test/org/h2/test/db/TestMultiThreadedKernel.java
+48
-0
没有找到文件。
h2/src/main/org/h2/store/PageStore.java
浏览文件 @
4c28636c
...
@@ -434,7 +434,9 @@ public class PageStore implements CacheWriter {
...
@@ -434,7 +434,9 @@ public class PageStore implements CacheWriter {
maxMove
=
Integer
.
MAX_VALUE
;
maxMove
=
Integer
.
MAX_VALUE
;
}
}
for
(
int
x
=
lastUsed
,
j
=
0
;
x
>
MIN_PAGE_COUNT
&&
j
<
maxMove
;
x
--,
j
++)
{
for
(
int
x
=
lastUsed
,
j
=
0
;
x
>
MIN_PAGE_COUNT
&&
j
<
maxMove
;
x
--,
j
++)
{
compact
(
x
);
synchronized
(
database
)
{
compact
(
x
);
}
long
now
=
System
.
currentTimeMillis
();
long
now
=
System
.
currentTimeMillis
();
if
(
now
>
start
+
maxCompactTime
)
{
if
(
now
>
start
+
maxCompactTime
)
{
break
;
break
;
...
@@ -523,74 +525,73 @@ public class PageStore implements CacheWriter {
...
@@ -523,74 +525,73 @@ public class PageStore implements CacheWriter {
if
(
p
!=
null
)
{
if
(
p
!=
null
)
{
return
p
;
return
p
;
}
}
}
Data
data
=
createData
();
Data
data
=
createData
();
readPage
(
pageId
,
data
);
readPage
(
pageId
,
data
);
int
type
=
data
.
readByte
();
int
type
=
data
.
readByte
();
if
(
type
==
Page
.
TYPE_EMPTY
)
{
if
(
type
==
Page
.
TYPE_EMPTY
)
{
return
null
;
return
null
;
}
data
.
readShortInt
();
data
.
readInt
();
if
(!
checksumTest
(
data
.
getBytes
(),
pageId
,
pageSize
))
{
throw
DbException
.
get
(
ErrorCode
.
FILE_CORRUPTED_1
,
"wrong checksum"
);
}
Page
p
;
switch
(
type
&
~
Page
.
FLAG_LAST
)
{
case
Page
.
TYPE_FREE_LIST
:
p
=
PageFreeList
.
read
(
this
,
data
,
pageId
);
break
;
case
Page
.
TYPE_DATA_LEAF
:
{
int
indexId
=
data
.
readVarInt
();
PageDataIndex
index
=
(
PageDataIndex
)
metaObjects
.
get
(
indexId
);
if
(
index
==
null
)
{
throw
DbException
.
get
(
ErrorCode
.
FILE_CORRUPTED_1
,
"index not found "
+
indexId
);
}
}
p
=
PageDataLeaf
.
read
(
index
,
data
,
pageId
);
data
.
readShortInt
();
break
;
data
.
readInt
();
}
if
(!
checksumTest
(
data
.
getBytes
(),
pageId
,
pageSize
))
{
case
Page
.
TYPE_DATA_NODE
:
{
throw
DbException
.
get
(
ErrorCode
.
FILE_CORRUPTED_1
,
"wrong checksum"
);
int
indexId
=
data
.
readVarInt
();
PageDataIndex
index
=
(
PageDataIndex
)
metaObjects
.
get
(
indexId
);
if
(
index
==
null
)
{
throw
DbException
.
get
(
ErrorCode
.
FILE_CORRUPTED_1
,
"index not found "
+
indexId
);
}
}
p
=
PageDataNode
.
read
(
index
,
data
,
pageId
);
switch
(
type
&
~
Page
.
FLAG_LAST
)
{
break
;
case
Page
.
TYPE_FREE_LIST
:
}
p
=
PageFreeList
.
read
(
this
,
data
,
pageId
);
case
Page
.
TYPE_DATA_OVERFLOW
:
{
break
;
p
=
PageDataOverflow
.
read
(
this
,
data
,
pageId
);
case
Page
.
TYPE_DATA_LEAF
:
{
break
;
int
indexId
=
data
.
readVarInt
()
;
}
PageDataIndex
index
=
(
PageDataIndex
)
metaObjects
.
get
(
indexId
);
case
Page
.
TYPE_BTREE_LEAF
:
{
if
(
index
==
null
)
{
int
indexId
=
data
.
readVarInt
(
);
throw
DbException
.
get
(
ErrorCode
.
FILE_CORRUPTED_1
,
"index not found "
+
indexId
);
PageBtreeIndex
index
=
(
PageBtreeIndex
)
metaObjects
.
get
(
indexId
);
}
if
(
index
==
null
)
{
p
=
PageDataLeaf
.
read
(
index
,
data
,
pageId
);
throw
DbException
.
get
(
ErrorCode
.
FILE_CORRUPTED_1
,
"index not found "
+
indexId
)
;
break
;
}
}
p
=
PageBtreeLeaf
.
read
(
index
,
data
,
pageId
);
case
Page
.
TYPE_DATA_NODE
:
{
break
;
int
indexId
=
data
.
readVarInt
()
;
}
PageDataIndex
index
=
(
PageDataIndex
)
metaObjects
.
get
(
indexId
);
case
Page
.
TYPE_BTREE_NODE
:
{
if
(
index
==
null
)
{
int
indexId
=
data
.
readVarInt
(
);
throw
DbException
.
get
(
ErrorCode
.
FILE_CORRUPTED_1
,
"index not found "
+
indexId
);
PageBtreeIndex
index
=
(
PageBtreeIndex
)
metaObjects
.
get
(
indexId
);
}
if
(
index
==
null
)
{
p
=
PageDataNode
.
read
(
index
,
data
,
pageId
);
throw
DbException
.
get
(
ErrorCode
.
FILE_CORRUPTED_1
,
"index not found "
+
indexId
)
;
break
;
}
}
p
=
PageBtreeNode
.
read
(
index
,
data
,
pageId
);
case
Page
.
TYPE_DATA_OVERFLOW
:
{
break
;
p
=
PageDataOverflow
.
read
(
this
,
data
,
pageId
);
}
break
;
case
Page
.
TYPE_STREAM_TRUNK
:
}
p
=
PageStreamTrunk
.
read
(
this
,
data
,
pageId
);
case
Page
.
TYPE_BTREE_LEAF
:
{
break
;
int
indexId
=
data
.
readVarInt
();
case
Page
.
TYPE_STREAM_DATA
:
PageBtreeIndex
index
=
(
PageBtreeIndex
)
metaObjects
.
get
(
indexId
);
p
=
PageStreamData
.
read
(
this
,
data
,
pageId
);
if
(
index
==
null
)
{
break
;
throw
DbException
.
get
(
ErrorCode
.
FILE_CORRUPTED_1
,
"index not found "
+
indexId
);
default
:
}
throw
DbException
.
get
(
ErrorCode
.
FILE_CORRUPTED_1
,
"page="
+
pageId
+
" type="
+
type
);
p
=
PageBtreeLeaf
.
read
(
index
,
data
,
pageId
);
break
;
}
case
Page
.
TYPE_BTREE_NODE
:
{
int
indexId
=
data
.
readVarInt
();
PageBtreeIndex
index
=
(
PageBtreeIndex
)
metaObjects
.
get
(
indexId
);
if
(
index
==
null
)
{
throw
DbException
.
get
(
ErrorCode
.
FILE_CORRUPTED_1
,
"index not found "
+
indexId
);
}
p
=
PageBtreeNode
.
read
(
index
,
data
,
pageId
);
break
;
}
case
Page
.
TYPE_STREAM_TRUNK
:
p
=
PageStreamTrunk
.
read
(
this
,
data
,
pageId
);
break
;
case
Page
.
TYPE_STREAM_DATA
:
p
=
PageStreamData
.
read
(
this
,
data
,
pageId
);
break
;
default
:
throw
DbException
.
get
(
ErrorCode
.
FILE_CORRUPTED_1
,
"page="
+
pageId
+
" type="
+
type
);
}
cache
.
put
(
p
);
return
p
;
}
}
cache
.
put
(
p
);
return
p
;
}
}
private
int
getFirstUncommittedSection
()
{
private
int
getFirstUncommittedSection
()
{
...
@@ -729,15 +730,17 @@ public class PageStore implements CacheWriter {
...
@@ -729,15 +730,17 @@ public class PageStore implements CacheWriter {
*/
*/
public
void
close
()
{
public
void
close
()
{
trace
.
debug
(
"close"
);
trace
.
debug
(
"close"
);
if
(
log
!=
null
)
{
synchronized
(
database
)
{
log
.
close
();
if
(
log
!=
null
)
{
log
=
null
;
log
.
close
();
}
log
=
null
;
if
(
file
!=
null
)
{
}
try
{
if
(
file
!=
null
)
{
file
.
close
();
try
{
}
finally
{
file
.
close
();
file
=
null
;
}
finally
{
file
=
null
;
}
}
}
}
}
}
}
...
@@ -845,22 +848,24 @@ public class PageStore implements CacheWriter {
...
@@ -845,22 +848,24 @@ public class PageStore implements CacheWriter {
return
list
;
return
list
;
}
}
}
}
int
p
=
PAGE_ID_FREE_LIST_ROOT
+
i
*
freeListPagesPerList
;
synchronized
(
database
)
{
while
(
p
>=
pageCount
)
{
int
p
=
PAGE_ID_FREE_LIST_ROOT
+
i
*
freeListPagesPerList
;
increaseFileSize
(
INCREMENT_PAGES
);
while
(
p
>=
pageCount
)
{
}
increaseFileSize
(
INCREMENT_PAGES
);
if
(
p
<
pageCount
)
{
}
list
=
(
PageFreeList
)
getPage
(
p
);
if
(
p
<
pageCount
)
{
}
list
=
(
PageFreeList
)
getPage
(
p
);
if
(
list
==
null
)
{
}
list
=
PageFreeList
.
create
(
this
,
p
);
if
(
list
==
null
)
{
cache
.
put
(
list
);
list
=
PageFreeList
.
create
(
this
,
p
);
}
cache
.
put
(
list
);
while
(
freeLists
.
size
()
<=
i
)
{
}
freeLists
.
add
(
null
);
while
(
freeLists
.
size
()
<=
i
)
{
freeLists
.
add
(
null
);
}
freeLists
.
set
(
i
,
list
);
return
list
;
}
}
freeLists
.
set
(
i
,
list
);
return
list
;
}
}
private
void
freePage
(
int
pageId
)
{
private
void
freePage
(
int
pageId
)
{
...
...
h2/src/test/org/h2/test/db/TestMultiThreadedKernel.java
浏览文件 @
4c28636c
...
@@ -8,9 +8,13 @@ package org.h2.test.db;
...
@@ -8,9 +8,13 @@ package org.h2.test.db;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
java.util.ArrayList
;
import
java.util.Random
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.New
;
/**
/**
* A multi-threaded test case.
* A multi-threaded test case.
...
@@ -41,6 +45,8 @@ public class TestMultiThreadedKernel extends TestBase {
...
@@ -41,6 +45,8 @@ public class TestMultiThreadedKernel extends TestBase {
return
;
return
;
}
}
deleteDb
(
"multiThreadedKernel"
);
deleteDb
(
"multiThreadedKernel"
);
testCache
();
deleteDb
(
"multiThreadedKernel"
);
final
String
url
=
getURL
(
"multiThreadedKernel;DB_CLOSE_DELAY=-1;MULTI_THREADED=1"
,
true
);
final
String
url
=
getURL
(
"multiThreadedKernel;DB_CLOSE_DELAY=-1;MULTI_THREADED=1"
,
true
);
final
String
user
=
getUser
(),
password
=
getPassword
();
final
String
user
=
getUser
(),
password
=
getPassword
();
int
len
=
3
;
int
len
=
3
;
...
@@ -82,4 +88,46 @@ public class TestMultiThreadedKernel extends TestBase {
...
@@ -82,4 +88,46 @@ public class TestMultiThreadedKernel extends TestBase {
deleteDb
(
"multiThreadedKernel"
);
deleteDb
(
"multiThreadedKernel"
);
}
}
private
void
testCache
()
throws
Exception
{
ArrayList
<
Thread
>
list
=
New
.
arrayList
();
int
size
=
3
;
final
int
count
=
100
;
final
boolean
[]
stopped
=
{
false
};
String
url
=
getURL
(
"multiThreadedKernel;MULTI_THREADED=TRUE;CACHE_SIZE=1"
,
true
);
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
final
Connection
conn
=
DriverManager
.
getConnection
(
url
,
getUser
(),
getPassword
());
if
(
i
==
0
)
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, name varchar) "
+
"as select x, space(3000) from system_range(1, "
+
count
+
")"
);
}
final
Random
random
=
new
Random
(
i
);
final
int
x
=
i
;
Thread
t
=
new
Thread
()
{
public
void
run
()
{
try
{
PreparedStatement
prep
=
conn
.
prepareStatement
(
"select * from test where id = ?"
);
Statement
stat
=
conn
.
createStatement
();
while
(!
stopped
[
0
])
{
prep
.
setInt
(
1
,
random
.
nextInt
(
count
));
prep
.
execute
();
stat
.
execute
(
"create table test"
+
x
+
"(id int)"
);
stat
.
execute
(
"drop table test"
+
x
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
};
t
.
start
();
list
.
add
(
t
);
}
Thread
.
sleep
(
1000
);
stopped
[
0
]
=
true
;
for
(
Thread
t
:
list
)
{
t
.
join
();
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论