Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
68ef8e9c
提交
68ef8e9c
authored
4月 07, 2018
作者:
andrei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tryCommit inroduced, some class finals removed, based on code review
上级
7384fd28
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
59 行增加
和
40 行删除
+59
-40
Cursor.java
h2/src/main/org/h2/mvstore/Cursor.java
+1
-1
CursorPos.java
h2/src/main/org/h2/mvstore/CursorPos.java
+1
-1
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+55
-36
TransactionStore.java
h2/src/main/org/h2/mvstore/db/TransactionStore.java
+2
-2
没有找到文件。
h2/src/main/org/h2/mvstore/Cursor.java
浏览文件 @
68ef8e9c
...
@@ -13,7 +13,7 @@ import java.util.Iterator;
...
@@ -13,7 +13,7 @@ import java.util.Iterator;
* @param <K> the key type
* @param <K> the key type
* @param <V> the value type
* @param <V> the value type
*/
*/
public
final
class
Cursor
<
K
,
V
>
implements
Iterator
<
K
>
{
public
class
Cursor
<
K
,
V
>
implements
Iterator
<
K
>
{
private
final
K
to
;
private
final
K
to
;
private
CursorPos
cursorPos
;
private
CursorPos
cursorPos
;
private
CursorPos
keeper
;
private
CursorPos
keeper
;
...
...
h2/src/main/org/h2/mvstore/CursorPos.java
浏览文件 @
68ef8e9c
...
@@ -8,7 +8,7 @@ package org.h2.mvstore;
...
@@ -8,7 +8,7 @@ package org.h2.mvstore;
/**
/**
* A position in a cursor
* A position in a cursor
*/
*/
public
final
class
CursorPos
{
public
class
CursorPos
{
/**
/**
* The current page.
* The current page.
...
...
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
68ef8e9c
...
@@ -127,7 +127,7 @@ MVStore:
...
@@ -127,7 +127,7 @@ MVStore:
/**
/**
* A persistent storage for maps.
* A persistent storage for maps.
*/
*/
public
final
class
MVStore
{
public
class
MVStore
{
/**
/**
* Whether assertions are enabled.
* Whether assertions are enabled.
...
@@ -1037,6 +1037,25 @@ public final class MVStore {
...
@@ -1037,6 +1037,25 @@ public final class MVStore {
onVersionChange
(
version
);
onVersionChange
(
version
);
}
}
/**
* Unlike regular commit this method returns immediately if there is commit
* in progress on another thread, otherwise it acts as regular commit.
*
* This method may return BEFORE this thread changes are actually persisted!
*
* @return the new version (incremented if there were changes)
*/
public
long
tryCommit
()
{
// unlike synchronization, this will also prevent re-entrance,
// which may be possible, if the meta map have changed
if
(
currentStoreThread
.
compareAndSet
(
null
,
Thread
.
currentThread
()))
{
synchronized
(
this
)
{
store
();
}
}
return
currentVersion
;
}
/**
/**
* Commit the changes.
* Commit the changes.
* <p>
* <p>
...
@@ -1053,16 +1072,19 @@ public final class MVStore {
...
@@ -1053,16 +1072,19 @@ public final class MVStore {
*
*
* @return the new version (incremented if there were changes)
* @return the new version (incremented if there were changes)
*/
*/
public
long
commit
()
{
public
synchronized
long
commit
()
{
// unlike synchronization, this will also prevent re-entrance,
currentStoreThread
.
set
(
Thread
.
currentThread
());
// which may be possible, if the meta map have changed
store
();
if
(
currentStoreThread
.
compareAndSet
(
null
,
Thread
.
currentThread
()))
{
return
currentVersion
;
synchronized
(
this
)
{
}
private
void
store
()
{
try
{
try
{
currentStoreVersion
=
currentVersion
;
if
(!
closed
&&
hasUnsavedChangesInternal
())
{
if
(!
closed
&&
hasUnsavedChangesInternal
())
{
currentStoreVersion
=
currentVersion
;
if
(
fileStore
==
null
)
{
if
(
fileStore
==
null
)
{
lastStoredVersion
=
currentVersion
;
lastStoredVersion
=
currentVersion
;
//noinspection NonAtomicOperationOnVolatileField
++
currentVersion
;
++
currentVersion
;
setWriteVersion
(
currentVersion
);
setWriteVersion
(
currentVersion
);
metaChanged
=
false
;
metaChanged
=
false
;
...
@@ -1087,9 +1109,6 @@ public final class MVStore {
...
@@ -1087,9 +1109,6 @@ public final class MVStore {
currentStoreThread
.
set
(
null
);
currentStoreThread
.
set
(
null
);
}
}
}
}
}
return
currentVersion
;
}
private
void
storeNow
()
{
private
void
storeNow
()
{
assert
Thread
.
holdsLock
(
this
);
assert
Thread
.
holdsLock
(
this
);
...
@@ -2283,7 +2302,7 @@ public final class MVStore {
...
@@ -2283,7 +2302,7 @@ public final class MVStore {
saveNeeded
=
false
;
saveNeeded
=
false
;
// check again, because it could have been written by now
// check again, because it could have been written by now
if
(
unsavedMemory
>
autoCommitMemory
&&
autoCommitMemory
>
0
)
{
if
(
unsavedMemory
>
autoCommitMemory
&&
autoCommitMemory
>
0
)
{
c
ommit
();
tryC
ommit
();
}
}
}
}
}
}
...
@@ -2578,7 +2597,7 @@ public final class MVStore {
...
@@ -2578,7 +2597,7 @@ public final class MVStore {
if
(
time
<=
lastCommitTime
+
autoCommitDelay
)
{
if
(
time
<=
lastCommitTime
+
autoCommitDelay
)
{
return
;
return
;
}
}
c
ommit
();
tryC
ommit
();
if
(
autoCompactFillRate
>
0
)
{
if
(
autoCompactFillRate
>
0
)
{
// whether there were file read or write operations since
// whether there were file read or write operations since
// the last time
// the last time
...
...
h2/src/main/org/h2/mvstore/db/TransactionStore.java
浏览文件 @
68ef8e9c
...
@@ -475,7 +475,7 @@ public class TransactionStore {
...
@@ -475,7 +475,7 @@ public class TransactionStore {
t
.
setStatus
(
Transaction
.
STATUS_CLOSED
);
t
.
setStatus
(
Transaction
.
STATUS_CLOSED
);
openTransactions
.
clear
(
t
.
transactionId
);
openTransactions
.
clear
(
t
.
transactionId
);
if
(
oldStatus
==
Transaction
.
STATUS_PREPARED
||
store
.
getAutoCommitDelay
()
==
0
)
{
if
(
oldStatus
==
Transaction
.
STATUS_PREPARED
||
store
.
getAutoCommitDelay
()
==
0
)
{
store
.
c
ommit
();
store
.
tryC
ommit
();
return
;
return
;
}
}
// to avoid having to store the transaction log,
// to avoid having to store the transaction log,
...
@@ -486,7 +486,7 @@ public class TransactionStore {
...
@@ -486,7 +486,7 @@ public class TransactionStore {
int
max
=
store
.
getAutoCommitMemory
();
int
max
=
store
.
getAutoCommitMemory
();
// save at 3/4 capacity
// save at 3/4 capacity
if
(
unsaved
*
4
>
max
*
3
)
{
if
(
unsaved
*
4
>
max
*
3
)
{
store
.
c
ommit
();
store
.
tryC
ommit
();
}
}
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论