Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
1293f1e9
提交
1293f1e9
authored
6 年前
作者:
Andrei Tokar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make append mode of MVMap more transparent
上级
d7c0e317
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
70 行增加
和
88 行删除
+70
-88
MVMap.java
h2/src/main/org/h2/mvstore/MVMap.java
+68
-81
MVSecondaryIndex.java
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
+0
-1
TransactionMap.java
h2/src/main/org/h2/mvstore/tx/TransactionMap.java
+1
-1
TransactionStore.java
h2/src/main/org/h2/mvstore/tx/TransactionStore.java
+1
-5
没有找到文件。
h2/src/main/org/h2/mvstore/MVMap.java
浏览文件 @
1293f1e9
...
...
@@ -779,6 +779,11 @@ public class MVMap<K, V> extends AbstractMap<K, V>
}
public
final
RootReference
getRoot
()
{
RootReference
rootReference
=
getRootInternal
();
return
singleWriter
?
flushAppendBuffer
(
rootReference
)
:
rootReference
;
}
private
RootReference
getRootInternal
()
{
return
root
.
get
();
}
...
...
@@ -1112,7 +1117,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
}
return
rootReference
;
}
rootReference
=
flushAppendBuffer
(
rootReference
);
RootReference
updatedRootReference
=
new
RootReference
(
rootReference
,
writeVersion
,
++
attempt
);
if
(
root
.
compareAndSet
(
rootReference
,
updatedRootReference
))
{
removeUnusedOldVersions
(
updatedRootReference
);
...
...
@@ -1173,99 +1177,82 @@ public class MVMap<K, V> extends AbstractMap<K, V>
/**
* If map was used in append mode, this method will ensure that append buffer
* is flushed - emptied with all entries inserted into map as a new leaf.
* @param rootReference current RootReference
* @return potentially updated RootReference
*/
public
RootReference
flushAppendBuffer
()
{
return
flushAppendBuffer
(
null
);
}
private
RootReference
flushAppendBuffer
(
RootReference
rootReference
)
{
int
attempt
=
0
;
while
(
true
)
{
if
(
rootReference
==
null
)
{
rootReference
=
getRoot
();
}
int
keyCount
=
rootReference
.
getAppendCounter
();
if
(
keyCount
==
0
)
{
break
;
}
int
keyCount
;
while
((
keyCount
=
rootReference
.
getAppendCounter
())
>
0
)
{
Page
page
=
Page
.
create
(
this
,
Arrays
.
copyOf
(
keysBuffer
,
keyCount
),
Arrays
.
copyOf
(
valuesBuffer
,
keyCount
),
null
,
keyCount
,
0
);
rootReference
=
appendLeafPage
(
rootReference
,
page
,
++
attempt
);
if
(
rootReference
!=
null
)
{
break
;
}
}
assert
rootReference
.
getAppendCounter
()
==
0
;
return
rootReference
;
}
private
RootReference
appendLeafPage
(
RootReference
rootReference
,
Page
split
,
int
attempt
)
{
CursorPos
pos
=
rootReference
.
root
.
getAppendCursorPos
(
null
);
assert
split
.
map
==
this
;
assert
pos
!=
null
;
assert
split
.
getKeyCount
()
>
0
;
Object
key
=
split
.
getKey
(
0
);
assert
pos
.
index
<
0
:
pos
.
index
;
int
index
=
-
pos
.
index
-
1
;
assert
index
==
pos
.
page
.
getKeyCount
()
:
index
+
" != "
+
pos
.
page
.
getKeyCount
();
Page
p
=
pos
.
page
;
pos
=
pos
.
parent
;
CursorPos
tip
=
pos
;
int
unsavedMemory
=
0
;
while
(
true
)
{
if
(
pos
==
null
)
{
if
(
p
.
getKeyCount
()
==
0
)
{
p
=
split
;
}
else
{
Object
keys
[]
=
new
Object
[]
{
key
};
Page
.
PageReference
children
[]
=
new
Page
.
PageReference
[]
{
new
Page
.
PageReference
(
p
),
new
Page
.
PageReference
(
split
)};
p
=
Page
.
create
(
this
,
keys
,
null
,
children
,
p
.
getTotalCount
()
+
split
.
getTotalCount
(),
0
);
}
break
;
}
Page
c
=
p
;
p
=
pos
.
page
;
index
=
pos
.
index
;
CursorPos
pos
=
rootReference
.
root
.
getAppendCursorPos
(
null
);
assert
page
.
map
==
this
;
assert
pos
!=
null
;
assert
page
.
getKeyCount
()
>
0
;
Object
key
=
page
.
getKey
(
0
);
assert
pos
.
index
<
0
:
pos
.
index
;
int
index
=
-
pos
.
index
-
1
;
assert
index
==
pos
.
page
.
getKeyCount
()
:
index
+
" != "
+
pos
.
page
.
getKeyCount
();
Page
p
=
pos
.
page
;
pos
=
pos
.
parent
;
p
=
p
.
copy
();
p
.
setChild
(
index
,
split
);
p
.
insertNode
(
index
,
key
,
c
);
int
keyCount
;
if
((
keyCount
=
p
.
getKeyCount
())
<=
store
.
getKeysPerPage
()
&&
(
p
.
getMemory
()
<
store
.
getMaxPageSize
()
||
keyCount
<=
(
p
.
isLeaf
()
?
1
:
2
)))
{
break
;
CursorPos
tip
=
pos
;
int
unsavedMemory
=
0
;
while
(
true
)
{
if
(
pos
==
null
)
{
if
(
p
.
getKeyCount
()
==
0
)
{
p
=
page
;
}
else
{
Object
keys
[]
=
new
Object
[]
{
key
};
Page
.
PageReference
children
[]
=
new
Page
.
PageReference
[]
{
new
Page
.
PageReference
(
p
),
new
Page
.
PageReference
(
page
)};
p
=
Page
.
create
(
this
,
keys
,
null
,
children
,
p
.
getTotalCount
()
+
page
.
getTotalCount
(),
0
);
}
break
;
}
Page
c
=
p
;
p
=
pos
.
page
;
index
=
pos
.
index
;
pos
=
pos
.
parent
;
p
=
p
.
copy
();
p
.
setChild
(
index
,
page
);
p
.
insertNode
(
index
,
key
,
c
);
if
((
keyCount
=
p
.
getKeyCount
())
<=
store
.
getKeysPerPage
()
&&
(
p
.
getMemory
()
<
store
.
getMaxPageSize
()
||
keyCount
<=
(
p
.
isLeaf
()
?
1
:
2
)))
{
break
;
}
int
at
=
keyCount
-
2
;
key
=
p
.
getKey
(
at
);
page
=
p
.
split
(
at
);
unsavedMemory
+=
p
.
getMemory
()
+
page
.
getMemory
();
}
int
at
=
keyCount
-
2
;
key
=
p
.
getKey
(
at
);
split
=
p
.
split
(
at
);
unsavedMemory
+=
p
.
getMemory
()
+
split
.
getMemory
();
}
unsavedMemory
+=
p
.
getMemory
();
while
(
pos
!=
null
)
{
Page
c
=
p
;
p
=
pos
.
page
;
p
=
p
.
copy
();
p
.
setChild
(
pos
.
index
,
c
);
unsavedMemory
+=
p
.
getMemory
();
pos
=
pos
.
parent
;
}
RootReference
updatedRootReference
=
new
RootReference
(
rootReference
,
p
,
++
attempt
)
;
if
(
root
.
compareAndSet
(
rootReference
,
updatedRootReference
))
{
while
(
tip
!=
null
)
{
tip
.
page
.
removePage
();
tip
=
tip
.
parent
;
while
(
pos
!=
null
)
{
Page
c
=
p
;
p
=
pos
.
page
;
p
=
p
.
copy
();
p
.
setChild
(
pos
.
index
,
c
);
unsavedMemory
+=
p
.
getMemory
();
pos
=
pos
.
parent
;
}
if
(
store
.
getFileStore
()
!=
null
)
{
store
.
registerUnsavedPage
(
unsavedMemory
);
RootReference
updatedRootReference
=
new
RootReference
(
rootReference
,
p
,
++
attempt
);
if
(
root
.
compareAndSet
(
rootReference
,
updatedRootReference
))
{
while
(
tip
!=
null
)
{
tip
.
page
.
removePage
();
tip
=
tip
.
parent
;
}
if
(
store
.
getFileStore
()
!=
null
)
{
store
.
registerUnsavedPage
(
unsavedMemory
);
}
assert
updatedRootReference
.
getAppendCounter
()
==
0
;
return
updatedRootReference
;
}
r
eturn
updatedRootReference
;
r
ootReference
=
getRootInternal
()
;
}
return
null
;
return
rootReference
;
}
/**
...
...
@@ -1280,7 +1267,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
int
attempt
=
0
;
boolean
success
=
false
;
while
(!
success
)
{
RootReference
rootReference
=
getRoot
();
RootReference
rootReference
=
getRoot
Internal
();
int
appendCounter
=
rootReference
.
getAppendCounter
();
if
(
appendCounter
>=
keysPerPage
)
{
rootReference
=
flushAppendBuffer
(
rootReference
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
浏览文件 @
1293f1e9
...
...
@@ -83,7 +83,6 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
ValueArray
key
=
convertToKey
(
row
);
map
.
append
(
key
,
ValueNull
.
INSTANCE
);
}
map
.
flushAppendBuffer
();
}
private
static
final
class
Source
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/tx/TransactionMap.java
浏览文件 @
1293f1e9
...
...
@@ -88,7 +88,7 @@ public class TransactionMap<K, V> {
for
(
int
i
=
opentransactions
.
nextSetBit
(
0
);
i
>=
0
;
i
=
opentransactions
.
nextSetBit
(
i
+
1
))
{
MVMap
<
Long
,
Object
[]>
undoLog
=
store
.
undoLogs
[
i
];
if
(
undoLog
!=
null
)
{
MVMap
.
RootReference
rootReference
=
undoLog
.
flushAppendBuffer
();
MVMap
.
RootReference
rootReference
=
undoLog
.
getRoot
();
undoLogRootReferences
[
i
]
=
rootReference
;
undoLogSize
+=
rootReference
.
root
.
getTotalCount
()
+
rootReference
.
getAppendCounter
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/tx/TransactionStore.java
浏览文件 @
1293f1e9
...
...
@@ -439,9 +439,7 @@ public class TransactionStore {
store
.
renameMap
(
undoLog
,
getUndoLogName
(
true
,
transactionId
));
}
try
{
MVMap
.
RootReference
rootReference
=
undoLog
.
flushAppendBuffer
();
Page
rootPage
=
rootReference
.
root
;
Cursor
<
Long
,
Object
[]>
cursor
=
new
Cursor
<>(
rootPage
,
null
);
Cursor
<
Long
,
Object
[]>
cursor
=
undoLog
.
cursor
(
null
);
while
(
cursor
.
hasNext
())
{
Long
undoKey
=
cursor
.
next
();
Object
[]
op
=
cursor
.
getValue
();
...
...
@@ -592,7 +590,6 @@ public class TransactionStore {
void
rollbackTo
(
Transaction
t
,
long
maxLogId
,
long
toLogId
)
{
int
transactionId
=
t
.
getId
();
MVMap
<
Long
,
Object
[]>
undoLog
=
undoLogs
[
transactionId
];
undoLog
.
flushAppendBuffer
();
RollbackDecisionMaker
decisionMaker
=
new
RollbackDecisionMaker
(
this
,
transactionId
,
toLogId
,
t
.
listener
);
for
(
long
logId
=
maxLogId
-
1
;
logId
>=
toLogId
;
logId
--)
{
Long
undoKey
=
getOperationId
(
transactionId
,
logId
);
...
...
@@ -614,7 +611,6 @@ public class TransactionStore {
final
long
toLogId
)
{
final
MVMap
<
Long
,
Object
[]>
undoLog
=
undoLogs
[
t
.
getId
()];
undoLog
.
flushAppendBuffer
();
return
new
Iterator
<
Change
>()
{
private
long
logId
=
maxLogId
-
1
;
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论