Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b3bd3a5b
提交
b3bd3a5b
authored
1月 15, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Page store: adding data to new database is now faster.
上级
7a0eb586
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
64 行增加
和
22 行删除
+64
-22
PageLog.java
h2/src/main/org/h2/store/PageLog.java
+46
-15
PageStore.java
h2/src/main/org/h2/store/PageStore.java
+16
-7
Recover.java
h2/src/main/org/h2/tools/Recover.java
+2
-0
没有找到文件。
h2/src/main/org/h2/store/PageLog.java
浏览文件 @
b3bd3a5b
...
...
@@ -9,6 +9,7 @@ package org.h2.store;
import
java.io.EOFException
;
import
java.io.IOException
;
import
java.sql.SQLException
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
org.h2.compress.CompressLZF
;
import
org.h2.constant.ErrorCode
;
...
...
@@ -26,6 +27,7 @@ import org.h2.util.IntIntHashMap;
import
org.h2.util.New
;
import
org.h2.util.ObjectArray
;
import
org.h2.value.Value
;
import
org.h2.value.ValueNull
;
/**
* Transaction log mechanism. The stream contains a list of records. The data
...
...
@@ -45,8 +47,9 @@ public class PageLog {
public
static
final
int
NOOP
=
0
;
/**
* An undo log entry.
* Format: page id: varInt, page.
* An undo log entry. Format: page id: varInt, size, page. Size 0 means
* uncompressed, size 1 means empty page, otherwise the size is the number
* of compressed bytes.
*/
public
static
final
int
UNDO
=
1
;
...
...
@@ -255,6 +258,9 @@ public class PageLog {
int
size
=
in
.
readVarInt
();
if
(
size
==
0
)
{
in
.
readFully
(
data
.
getBytes
(),
0
,
store
.
getPageSize
());
}
else
if
(
size
==
1
)
{
// empty
Arrays
.
fill
(
data
.
getBytes
(),
0
,
store
.
getPageSize
(),
(
byte
)
0
);
}
else
{
in
.
readFully
(
compressBuffer
,
0
,
size
);
compress
.
expand
(
compressBuffer
,
0
,
size
,
data
.
getBytes
(),
0
,
store
.
getPageSize
());
...
...
@@ -423,6 +429,16 @@ public class PageLog {
return
row
;
}
/**
* Check if the undo entry was already written for the given page.
*
* @param pageId the page
* @return true if it was written
*/
boolean
getUndo
(
int
pageId
)
{
return
undo
.
get
(
pageId
);
}
/**
* Add an undo entry to the log. The page data is only written once until
* the next checkpoint.
...
...
@@ -446,6 +462,9 @@ public class PageLog {
Data
buffer
=
getBuffer
();
buffer
.
writeByte
((
byte
)
UNDO
);
buffer
.
writeVarInt
(
pageId
);
if
(
page
.
getBytes
()[
0
]
==
0
)
{
buffer
.
writeVarInt
(
1
);
}
else
{
int
pageSize
=
store
.
getPageSize
();
if
(
COMPRESS_UNDO
)
{
int
size
=
compress
.
compress
(
page
.
getBytes
(),
pageSize
,
compressBuffer
,
0
);
...
...
@@ -463,6 +482,7 @@ public class PageLog {
buffer
.
checkCapacity
(
pageSize
);
buffer
.
write
(
page
.
getBytes
(),
0
,
pageSize
);
}
}
write
(
buffer
);
}
catch
(
IOException
e
)
{
throw
Message
.
convertIOException
(
e
,
null
);
...
...
@@ -579,9 +599,20 @@ public class PageLog {
int
columns
=
row
.
getColumnCount
();
data
.
writeVarInt
(
columns
);
data
.
checkCapacity
(
row
.
getByteCount
(
data
));
if
(
session
.
isRedoLogBinaryEnabled
())
{
for
(
int
i
=
0
;
i
<
columns
;
i
++)
{
data
.
writeValue
(
row
.
getValue
(
i
));
}
}
else
{
for
(
int
i
=
0
;
i
<
columns
;
i
++)
{
Value
v
=
row
.
getValue
(
i
);
if
(
v
.
getType
()
==
Value
.
BYTES
)
{
data
.
writeValue
(
ValueNull
.
INSTANCE
);
}
else
{
data
.
writeValue
(
v
);
}
}
}
Data
buffer
=
getBuffer
();
buffer
.
writeByte
((
byte
)
(
add
?
ADD
:
REMOVE
));
buffer
.
writeVarInt
(
session
.
getId
());
...
...
h2/src/main/org/h2/store/PageStore.java
浏览文件 @
b3bd3a5b
...
...
@@ -137,8 +137,8 @@ public class PageStore implements CacheWriter {
private
static
final
int
INCREMENT_PAGES
=
128
;
private
static
final
int
READ_VERSION
=
2
;
private
static
final
int
WRITE_VERSION
=
2
;
private
static
final
int
READ_VERSION
=
3
;
private
static
final
int
WRITE_VERSION
=
3
;
private
static
final
int
META_TYPE_SCAN_INDEX
=
0
;
private
static
final
int
META_TYPE_BTREE_INDEX
=
1
;
...
...
@@ -203,6 +203,8 @@ public class PageStore implements CacheWriter {
*/
private
int
changeCount
=
1
;
private
Data
emptyPage
;
/**
* Create a new page store object.
*
...
...
@@ -632,6 +634,7 @@ public class PageStore implements CacheWriter {
throw
Message
.
getSQLException
(
ErrorCode
.
FILE_CORRUPTED_1
,
fileName
);
}
pageSize
=
size
;
emptyPage
=
createData
();
pageSizeShift
=
shift
;
}
...
...
@@ -665,7 +668,7 @@ public class PageStore implements CacheWriter {
private
void
writeVariableHeader
()
throws
SQLException
{
Data
page
=
createData
();
page
.
writeInt
(
0
);
page
.
writeLong
(
writeCount
);
page
.
writeLong
(
getWriteCountTotal
()
);
page
.
writeInt
(
logKey
);
page
.
writeInt
(
logFirstTrunkPage
);
page
.
writeInt
(
logFirstDataPage
);
...
...
@@ -739,6 +742,7 @@ public class PageStore implements CacheWriter {
database
.
checkWritingAllowed
();
if
(!
recoveryRunning
)
{
int
pos
=
record
.
getPos
();
if
(!
log
.
getUndo
(
pos
))
{
if
(
old
==
null
)
{
old
=
readPage
(
pos
);
}
...
...
@@ -746,6 +750,7 @@ public class PageStore implements CacheWriter {
}
}
}
}
/**
* Update a page.
...
...
@@ -847,7 +852,11 @@ public class PageStore implements CacheWriter {
* @return the page id
*/
public
int
allocatePage
()
throws
SQLException
{
return
allocatePage
(
null
,
0
);
int
pos
=
allocatePage
(
null
,
0
);
if
(!
recoveryRunning
)
{
log
.
addUndo
(
pos
,
emptyPage
);
}
return
pos
;
}
private
int
allocatePage
(
BitField
exclude
,
int
first
)
throws
SQLException
{
...
...
h2/src/main/org/h2/tools/Recover.java
浏览文件 @
b3bd3a5b
...
...
@@ -1015,6 +1015,8 @@ public class Recover extends Tool implements DataHandler {
byte
[]
data
=
new
byte
[
pageSize
];
if
(
size
==
0
)
{
in
.
readFully
(
data
,
0
,
pageSize
);
}
else
if
(
size
==
1
)
{
// empty
}
else
{
byte
[]
compressBuffer
=
new
byte
[
size
];
in
.
readFully
(
compressBuffer
,
0
,
size
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论