Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
18db1b22
提交
18db1b22
authored
15 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Page store: reserve index head pages while recovering.
上级
cc064d81
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
51 行增加
和
10 行删除
+51
-10
PageDataLeaf.java
h2/src/main/org/h2/index/PageDataLeaf.java
+0
-1
PageFreeList.java
h2/src/main/org/h2/store/PageFreeList.java
+4
-4
PageLog.java
h2/src/main/org/h2/store/PageLog.java
+4
-2
PageStore.java
h2/src/main/org/h2/store/PageStore.java
+43
-3
没有找到文件。
h2/src/main/org/h2/index/PageDataLeaf.java
浏览文件 @
18db1b22
...
...
@@ -100,7 +100,6 @@ class PageDataLeaf extends PageData {
if
(
entryCount
>
1
)
{
return
entryCount
/
2
;
}
int
todoIncorrect
;
if
(
find
(
row
.
getPos
())
!=
1
)
{
System
.
out
.
println
(
"todo "
+
find
(
row
.
getPos
()));
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/store/PageFreeList.java
浏览文件 @
18db1b22
...
...
@@ -60,16 +60,16 @@ public class PageFreeList extends Record {
/**
* Mark a page as used.
*
* @param p
os
the page id
* @param p
ageId
the page id
* @return the page id, or -1
*/
int
allocate
(
int
p
os
)
throws
SQLException
{
int
idx
=
p
os
-
getPos
();
int
allocate
(
int
p
ageId
)
throws
SQLException
{
int
idx
=
p
ageId
-
getPos
();
if
(
idx
>=
0
&&
!
used
.
get
(
idx
))
{
used
.
set
(
idx
);
store
.
updateRecord
(
this
,
true
,
data
);
}
return
p
os
;
return
p
ageId
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/store/PageLog.java
浏览文件 @
18db1b22
...
...
@@ -228,12 +228,14 @@ public class PageLog {
int
sessionId
=
in
.
readInt
();
int
tableId
=
in
.
readInt
();
Row
row
=
readRow
(
in
,
data
);
if
(
stage
==
RECOVERY_STAGE_REDO
)
{
if
(
stage
==
RECOVERY_STAGE_UNDO
&&
x
==
ADD
)
{
store
.
allocateIfHead
(
pos
,
tableId
,
row
);
}
else
if
(
stage
==
RECOVERY_STAGE_REDO
)
{
if
(
isSessionCommitted
(
sessionId
,
logId
,
pos
))
{
if
(
trace
.
isDebugEnabled
())
{
trace
.
debug
(
"log redo "
+
(
x
==
ADD
?
"+"
:
"-"
)
+
" table:"
+
tableId
+
" "
+
row
);
}
store
.
redo
(
tableId
,
row
,
x
==
ADD
);
store
.
redo
(
pos
,
tableId
,
row
,
x
==
ADD
);
}
else
{
if
(
trace
.
isDebugEnabled
())
{
trace
.
debug
(
"log ignore s:"
+
sessionId
+
" "
+
(
x
==
ADD
?
"+"
:
"-"
)
+
" table:"
+
tableId
+
" "
+
row
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/store/PageStore.java
浏览文件 @
18db1b22
...
...
@@ -184,6 +184,13 @@ public class PageStore implements CacheWriter {
private
TableData
metaTable
;
private
PageScanIndex
metaIndex
;
private
HashMap
<
Integer
,
Index
>
metaObjects
;
/**
* The map of reserved pages, to ensure index head pages
* are not used for regular data during recovery. The key is the page id,
* and the value the latest transaction position where this page is used.
*/
private
HashMap
<
Integer
,
Integer
>
reservedPages
;
private
int
systemTableHeadPos
;
// TODO reduce DEFAULT_MAX_LOG_SIZE, and don't divide here
private
long
maxLogSize
=
Constants
.
DEFAULT_MAX_LOG_SIZE
/
10
;
...
...
@@ -202,6 +209,7 @@ public class PageStore implements CacheWriter {
this
.
accessMode
=
accessMode
;
this
.
database
=
database
;
trace
=
database
.
getTrace
(
Trace
.
PAGE_STORE
);
// int test;
// trace.setLevel(TraceSystem.DEBUG);
this
.
cacheSize
=
cacheSizeDefault
;
String
cacheType
=
database
.
getCacheType
();
...
...
@@ -733,6 +741,11 @@ public class PageStore implements CacheWriter {
trace
.
debug
(
"log recover"
);
recoveryRunning
=
true
;
log
.
recover
(
PageLog
.
RECOVERY_STAGE_UNDO
);
if
(
reservedPages
!=
null
)
{
for
(
int
r
:
reservedPages
.
keySet
())
{
allocatePage
(
r
);
}
}
log
.
recover
(
PageLog
.
RECOVERY_STAGE_ALLOCATE
);
openMetaIndex
();
readMetaData
();
...
...
@@ -760,6 +773,7 @@ public class PageStore implements CacheWriter {
openIndex
.
close
(
systemSession
);
}
recoveryRunning
=
false
;
reservedPages
=
null
;
writeBack
();
// clear the cache because it contains pages with closed indexes
cache
.
clear
();
...
...
@@ -821,19 +835,37 @@ public class PageStore implements CacheWriter {
return
systemTableHeadPos
;
}
/**
* Reserve the page if this is a index head entry.
*
* @param logPos the redo log position
* @param tableId the table id
* @param row the row
*/
void
allocateIfHead
(
int
logPos
,
int
tableId
,
Row
row
)
throws
SQLException
{
if
(
tableId
==
META_TABLE_ID
)
{
int
headPos
=
row
.
getValue
(
3
).
getInt
();
if
(
reservedPages
==
null
)
{
reservedPages
=
New
.
hashMap
();
}
reservedPages
.
put
(
headPos
,
logPos
);
}
}
/**
* Redo a change in a table.
*
* @param logPos the redo log position
* @param tableId the object id of the table
* @param row the row
* @param add true if the record is added, false if deleted
*/
void
redo
(
int
tableId
,
Row
row
,
boolean
add
)
throws
SQLException
{
void
redo
(
int
logPos
,
int
tableId
,
Row
row
,
boolean
add
)
throws
SQLException
{
if
(
tableId
==
META_TABLE_ID
)
{
if
(
add
)
{
addMeta
(
row
,
systemSession
,
true
);
}
else
{
removeMeta
(
row
);
removeMeta
(
logPos
,
row
);
}
}
PageScanIndex
index
=
(
PageScanIndex
)
metaObjects
.
get
(
tableId
);
...
...
@@ -874,14 +906,22 @@ public class PageStore implements CacheWriter {
}
}
private
void
removeMeta
(
Row
row
)
throws
SQLException
{
private
void
removeMeta
(
int
logPos
,
Row
row
)
throws
SQLException
{
int
id
=
row
.
getValue
(
0
).
getInt
();
Index
index
=
metaObjects
.
remove
(
id
);
int
headPos
=
index
.
getHeadPos
();
index
.
getTable
().
removeIndex
(
index
);
if
(
index
instanceof
PageBtreeIndex
)
{
index
.
getSchema
().
remove
(
index
);
}
index
.
remove
(
systemSession
);
if
(
reservedPages
!=
null
&&
reservedPages
.
containsKey
(
headPos
))
{
// re-allocate the page if it is used later on again
int
latestPos
=
reservedPages
.
get
(
headPos
);
if
(
latestPos
>
logPos
)
{
allocatePage
(
headPos
);
}
}
}
private
void
addMeta
(
Row
row
,
Session
session
,
boolean
redo
)
throws
SQLException
{
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论