Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b55aaa2b
Unverified
提交
b55aaa2b
authored
1月 09, 2019
作者:
Evgenij Ryazanov
提交者:
GitHub
1月 09, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1649 from katzyn/close
Wait for MVStore close completion
上级
696b3512
39c616d1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
94 行增加
和
33 行删除
+94
-33
changelog.html
h2/src/docsrc/html/changelog.html
+12
-0
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+82
-33
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
b55aaa2b
...
...
@@ -21,8 +21,20 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<ul>
<li>
Issue #1212: TestDiskFull: The file is locked
</li>
<li>
PR #1648: Add functions ARRAY_CAT(), ARRAY_APPEND() and ARRAY_SLICE()
</li>
<li>
PR #1646: In preparation to a release
</li>
<li>
PR #1643: more javadoc update
</li>
<li>
PR #1642: update javadoc
</li>
<li>
PR #1641: Update copyright years
</li>
<li>
PR #1640: Suggest ANY(?) instead of variable IN() again
</li>
<li>
PR #1638: Add support for Java 11 to test suite
</li>
<li>
PR #1637: Remove explicit unboxing
...
...
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
b55aaa2b
...
...
@@ -147,6 +147,27 @@ public class MVStore implements AutoCloseable {
*/
private
static
final
int
MARKED_FREE
=
10_000_000
;
/**
* Storage is open.
*/
private
static
final
int
STATE_OPEN
=
0
;
/**
* Storage is stopping now. Background writer thread finishes its work
* during this process.
*/
private
static
final
int
STATE_STOPPING
=
1
;
/**
* Storage is closing now.
*/
private
static
final
int
STATE_CLOSING
=
2
;
/**
* Storage is closed.
*/
private
static
final
int
STATE_CLOSED
=
3
;
/**
* Lock which governs access to major store operations: store(), close(), ...
* It should used in a non-reentrant fashion.
...
...
@@ -162,7 +183,7 @@ public class MVStore implements AutoCloseable {
private
volatile
boolean
reuseSpace
=
true
;
private
volatile
boolean
closed
;
private
volatile
int
state
;
private
final
FileStore
fileStore
;
...
...
@@ -414,7 +435,7 @@ public class MVStore implements AutoCloseable {
}
private
void
panic
(
IllegalStateException
e
)
{
if
(
!
closed
)
{
if
(
state
==
STATE_OPEN
)
{
handleException
(
e
);
panicException
=
e
;
closeImmediately
();
...
...
@@ -918,7 +939,7 @@ public class MVStore implements AutoCloseable {
*/
@Override
public
void
close
()
{
if
(
closed
)
{
if
(
isClosed
()
)
{
return
;
}
FileStore
f
=
fileStore
;
...
...
@@ -949,37 +970,42 @@ public class MVStore implements AutoCloseable {
}
private
void
closeStore
(
boolean
shrinkIfPossible
)
{
if
(
closed
)
{
if
(
isClosed
()
)
{
return
;
}
stopBackgroundThread
();
closed
=
true
;
storeLock
.
lock
();
state
=
STATE_STOPPING
;
try
{
stopBackgroundThread
();
state
=
STATE_CLOSING
;
storeLock
.
lock
();
try
{
if
(
fileStore
!=
null
&&
shrinkIfPossible
)
{
shrinkFileIfPossible
(
0
);
}
// release memory early - this is important when called
// because of out of memory
if
(
cache
!=
null
)
{
cache
.
clear
();
}
if
(
cacheChunkRef
!=
null
)
{
cacheChunkRef
.
clear
();
}
for
(
MVMap
<?,
?>
m
:
new
ArrayList
<>(
maps
.
values
()))
{
m
.
close
();
try
{
if
(
fileStore
!=
null
&&
shrinkIfPossible
)
{
shrinkFileIfPossible
(
0
);
}
// release memory early - this is important when called
// because of out of memory
if
(
cache
!=
null
)
{
cache
.
clear
();
}
if
(
cacheChunkRef
!=
null
)
{
cacheChunkRef
.
clear
();
}
for
(
MVMap
<?,
?>
m
:
new
ArrayList
<>(
maps
.
values
()))
{
m
.
close
();
}
chunks
.
clear
();
maps
.
clear
();
}
finally
{
if
(
fileStore
!=
null
&&
!
fileStoreIsProvided
)
{
fileStore
.
close
();
}
}
chunks
.
clear
();
maps
.
clear
();
}
finally
{
if
(
fileStore
!=
null
&&
!
fileStoreIsProvided
)
{
fileStore
.
close
();
}
storeLock
.
unlock
();
}
}
finally
{
st
oreLock
.
unlock
()
;
st
ate
=
STATE_CLOSED
;
}
}
...
...
@@ -1142,7 +1168,7 @@ public class MVStore implements AutoCloseable {
private
void
store
()
{
try
{
if
(
!
closed
&&
hasUnsavedChangesInternal
())
{
if
(
isOpenOrStopping
()
&&
hasUnsavedChangesInternal
())
{
currentStoreVersion
=
currentVersion
;
if
(
fileStore
==
null
)
{
lastStoredVersion
=
currentVersion
;
...
...
@@ -1719,7 +1745,7 @@ public class MVStore implements AutoCloseable {
if
(
savedPercent
<
minPercent
)
{
return
;
}
if
(
!
closed
)
{
if
(
isOpenOrStopping
()
)
{
sync
();
}
fileStore
.
truncate
(
end
);
...
...
@@ -2392,7 +2418,7 @@ public class MVStore implements AutoCloseable {
* @param map the map
*/
void
beforeWrite
(
MVMap
<?,
?>
map
)
{
if
(
saveNeeded
&&
fileStore
!=
null
&&
!
closed
)
{
if
(
saveNeeded
&&
fileStore
!=
null
&&
isOpenOrStopping
()
)
{
saveNeeded
=
false
;
// check again, because it could have been written by now
if
(
unsavedMemory
>
autoCommitMemory
&&
autoCommitMemory
>
0
)
{
...
...
@@ -2599,7 +2625,7 @@ public class MVStore implements AutoCloseable {
}
private
void
checkOpen
()
{
if
(
closed
)
{
if
(
!
isOpenOrStopping
()
)
{
throw
DataUtils
.
newIllegalStateException
(
DataUtils
.
ERROR_CLOSED
,
"This store is closed"
,
panicException
);
}
...
...
@@ -2718,7 +2744,7 @@ public class MVStore implements AutoCloseable {
*/
void
writeInBackground
()
{
try
{
if
(
closed
)
{
if
(
!
isOpenOrStopping
()
)
{
return
;
}
...
...
@@ -2780,7 +2806,30 @@ public class MVStore implements AutoCloseable {
}
public
boolean
isClosed
()
{
return
closed
;
if
(
state
==
STATE_OPEN
)
{
return
false
;
}
int
millis
=
1
;
while
(
state
!=
STATE_CLOSED
)
{
/*
* We need to wait for completion of close procedure. This is
* required because otherwise database may be closed too early while
* underlying storage still has unreleased resources. The quickly
* following connection attempts fail with The file is locked
* exception.
*/
try
{
Thread
.
sleep
(
millis
++);
}
catch
(
InterruptedException
e
)
{
Thread
.
currentThread
().
interrupt
();
break
;
}
}
return
true
;
}
private
boolean
isOpenOrStopping
()
{
return
state
<=
STATE_STOPPING
;
}
private
void
stopBackgroundThread
()
{
...
...
@@ -2825,7 +2874,7 @@ public class MVStore implements AutoCloseable {
}
stopBackgroundThread
();
// start the background thread if needed
if
(
millis
>
0
)
{
if
(
millis
>
0
&&
state
==
STATE_OPEN
)
{
int
sleep
=
Math
.
max
(
1
,
millis
/
10
);
BackgroundWriterThread
t
=
new
BackgroundWriterThread
(
this
,
sleep
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论