Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
6be4766c
提交
6be4766c
authored
7月 06, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New experimental page store.
上级
36ed8325
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
106 行增加
和
114 行删除
+106
-114
PageBtreeIndex.java
h2/src/main/org/h2/index/PageBtreeIndex.java
+4
-13
PageBtreeLeaf.java
h2/src/main/org/h2/index/PageBtreeLeaf.java
+0
-1
PageData.java
h2/src/main/org/h2/index/PageData.java
+0
-4
PageDataLeaf.java
h2/src/main/org/h2/index/PageDataLeaf.java
+8
-33
PageDataLeafOverflow.java
h2/src/main/org/h2/index/PageDataLeafOverflow.java
+32
-11
PageDataNode.java
h2/src/main/org/h2/index/PageDataNode.java
+4
-4
PageScanIndex.java
h2/src/main/org/h2/index/PageScanIndex.java
+28
-16
PageLog.java
h2/src/main/org/h2/store/PageLog.java
+3
-3
PageStore.java
h2/src/main/org/h2/store/PageStore.java
+27
-29
没有找到文件。
h2/src/main/org/h2/index/PageBtreeIndex.java
浏览文件 @
6be4766c
...
@@ -11,7 +11,6 @@ import org.h2.constant.ErrorCode;
...
@@ -11,7 +11,6 @@ import org.h2.constant.ErrorCode;
import
org.h2.constant.SysProperties
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.message.Message
;
import
org.h2.message.Message
;
import
org.h2.message.TraceSystem
;
import
org.h2.result.Row
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SearchRow
;
import
org.h2.store.DataPage
;
import
org.h2.store.DataPage
;
...
@@ -39,16 +38,11 @@ public class PageBtreeIndex extends BaseIndex {
...
@@ -39,16 +38,11 @@ public class PageBtreeIndex extends BaseIndex {
public
PageBtreeIndex
(
TableData
table
,
int
id
,
String
indexName
,
IndexColumn
[]
columns
,
public
PageBtreeIndex
(
TableData
table
,
int
id
,
String
indexName
,
IndexColumn
[]
columns
,
IndexType
indexType
,
int
headPos
,
Session
session
)
throws
SQLException
{
IndexType
indexType
,
int
headPos
,
Session
session
)
throws
SQLException
{
initBaseIndex
(
table
,
id
,
indexName
,
columns
,
indexType
);
initBaseIndex
(
table
,
id
,
indexName
,
columns
,
indexType
);
int
test
;
// trace.setLevel(TraceSystem.DEBUG);
// trace.setLevel(TraceSystem.DEBUG);
if
(
database
.
isMultiVersion
())
{
int
todoMvcc
;
}
tableData
=
table
;
tableData
=
table
;
if
(!
database
.
isPersistent
()
||
id
<
0
)
{
if
(!
database
.
isPersistent
()
||
id
<
0
)
{
int
todo
;
this
.
headPos
=
0
;
this
.
headPos
=
0
;
return
;
throw
Message
.
throwInternalError
(
""
+
indexName
)
;
}
}
this
.
store
=
database
.
getPageStore
();
this
.
store
=
database
.
getPageStore
();
if
(
headPos
==
Index
.
EMPTY_HEAD
)
{
if
(
headPos
==
Index
.
EMPTY_HEAD
)
{
...
@@ -73,7 +67,6 @@ public class PageBtreeIndex extends BaseIndex {
...
@@ -73,7 +67,6 @@ public class PageBtreeIndex extends BaseIndex {
// TODO test if really required
// TODO test if really required
store
.
updateRecord
(
root
,
false
,
null
);
store
.
updateRecord
(
root
,
false
,
null
);
}
}
int
reuseKeysIfManyDeleted
;
}
}
if
(
trace
.
isDebugEnabled
())
{
if
(
trace
.
isDebugEnabled
())
{
trace
.
debug
(
"opened "
+
getName
()
+
" rows:"
+
rowCount
);
trace
.
debug
(
"opened "
+
getName
()
+
" rows:"
+
rowCount
);
...
@@ -239,16 +232,14 @@ public class PageBtreeIndex extends BaseIndex {
...
@@ -239,16 +232,14 @@ public class PageBtreeIndex extends BaseIndex {
}
}
}
}
}
}
int
invalidateRowCount
;
// TODO invalidate row count
// setChanged(session);
// setChanged(session);
if
(
rowCount
==
1
)
{
if
(
rowCount
==
1
)
{
int
todoMaybeImprove
;
removeAllRows
();
removeAllRows
();
}
else
{
}
else
{
PageBtree
root
=
getPage
(
headPos
);
PageBtree
root
=
getPage
(
headPos
);
root
.
remove
(
row
);
root
.
remove
(
row
);
rowCount
--;
rowCount
--;
int
todoReuseKeys
;
}
}
}
}
...
@@ -322,7 +313,7 @@ public class PageBtreeIndex extends BaseIndex {
...
@@ -322,7 +313,7 @@ public class PageBtreeIndex extends BaseIndex {
if
(
trace
.
isDebugEnabled
())
{
if
(
trace
.
isDebugEnabled
())
{
trace
.
debug
(
"close"
);
trace
.
debug
(
"close"
);
}
}
int
writeRowCount
;
// TODO write the row count
}
}
/**
/**
...
...
h2/src/main/org/h2/index/PageBtreeLeaf.java
浏览文件 @
6be4766c
...
@@ -67,7 +67,6 @@ class PageBtreeLeaf extends PageBtree {
...
@@ -67,7 +67,6 @@ class PageBtreeLeaf extends PageBtree {
int
last
=
entryCount
==
0
?
pageSize
:
offsets
[
entryCount
-
1
];
int
last
=
entryCount
==
0
?
pageSize
:
offsets
[
entryCount
-
1
];
if
(
last
-
rowLength
<
start
+
OFFSET_LENGTH
)
{
if
(
last
-
rowLength
<
start
+
OFFSET_LENGTH
)
{
if
(
entryCount
>
1
)
{
if
(
entryCount
>
1
)
{
int
todoSplitAtLastInsertionPoint
;
return
(
entryCount
/
2
)
+
1
;
return
(
entryCount
/
2
)
+
1
;
}
}
onlyPosition
=
true
;
onlyPosition
=
true
;
...
...
h2/src/main/org/h2/index/PageData.java
浏览文件 @
6be4766c
...
@@ -148,10 +148,6 @@ abstract class PageData extends Record {
...
@@ -148,10 +148,6 @@ abstract class PageData extends Record {
remapChildren
();
remapChildren
();
}
}
int
getPageId
()
{
return
getPos
();
}
/**
/**
* Get the last key of a page.
* Get the last key of a page.
*
*
...
...
h2/src/main/org/h2/index/PageDataLeaf.java
浏览文件 @
6be4766c
...
@@ -13,7 +13,6 @@ import org.h2.message.Message;
...
@@ -13,7 +13,6 @@ import org.h2.message.Message;
import
org.h2.result.Row
;
import
org.h2.result.Row
;
import
org.h2.store.DataPage
;
import
org.h2.store.DataPage
;
import
org.h2.store.PageStore
;
import
org.h2.store.PageStore
;
import
org.h2.store.Record
;
/**
/**
* A leaf page that contains data of one or multiple rows.
* A leaf page that contains data of one or multiple rows.
...
@@ -63,7 +62,7 @@ class PageDataLeaf extends PageData {
...
@@ -63,7 +62,7 @@ class PageDataLeaf extends PageData {
int
tableId
=
data
.
readInt
();
int
tableId
=
data
.
readInt
();
if
(
tableId
!=
index
.
getId
())
{
if
(
tableId
!=
index
.
getId
())
{
throw
Message
.
getSQLException
(
ErrorCode
.
FILE_CORRUPTED_1
,
throw
Message
.
getSQLException
(
ErrorCode
.
FILE_CORRUPTED_1
,
"page:"
+
getP
ageId
()
+
" expected table:"
+
index
.
getId
()
+
"page:"
+
getP
os
()
+
" expected table:"
+
index
.
getId
()
+
" got:"
+
tableId
+
" type:"
+
type
);
" got:"
+
tableId
+
" type:"
+
type
);
}
}
entryCount
=
data
.
readShortInt
();
entryCount
=
data
.
readShortInt
();
...
@@ -212,17 +211,7 @@ class PageDataLeaf extends PageData {
...
@@ -212,17 +211,7 @@ class PageDataLeaf extends PageData {
int
offset
=
pageSize
;
int
offset
=
pageSize
;
data
.
setPos
(
pageSize
);
data
.
setPos
(
pageSize
);
do
{
do
{
Record
record
=
store
.
getRecord
(
next
);
PageDataLeafOverflow
page
=
index
.
getPageOverflow
(
next
,
this
,
offset
);
PageDataLeafOverflow
page
;
if
(
record
==
null
)
{
DataPage
data
=
store
.
readPage
(
next
);
page
=
new
PageDataLeafOverflow
(
this
,
next
,
data
,
offset
);
}
else
{
if
(!(
record
instanceof
PageDataLeafOverflow
))
{
throw
Message
.
getInternalError
(
"page:"
+
next
+
" "
+
record
,
null
);
}
page
=
(
PageDataLeafOverflow
)
record
;
}
next
=
page
.
readInto
(
data
);
next
=
page
.
readInto
(
data
);
}
while
(
next
!=
0
);
}
while
(
next
!=
0
);
}
}
...
@@ -249,7 +238,7 @@ class PageDataLeaf extends PageData {
...
@@ -249,7 +238,7 @@ class PageDataLeaf extends PageData {
}
}
int
getLastKey
()
throws
SQLException
{
int
getLastKey
()
throws
SQLException
{
int
todoRemove
;
// TODO re-use keys, but remove this mechanism
if
(
entryCount
==
0
)
{
if
(
entryCount
==
0
)
{
return
0
;
return
0
;
}
}
...
@@ -268,17 +257,13 @@ class PageDataLeaf extends PageData {
...
@@ -268,17 +257,13 @@ class PageDataLeaf extends PageData {
return
this
;
return
this
;
}
}
protected
void
remapChildren
()
{
protected
void
remapChildren
()
throws
SQLException
{
if
(
firstOverflowPageId
==
0
)
{
if
(
firstOverflowPageId
==
0
)
{
return
;
return
;
}
}
int
testIfReallyNotRequired
;
PageDataLeafOverflow
overflow
=
index
.
getPageOverflow
(
firstOverflowPageId
,
this
,
0
);
// PageStore store = index.getPageStore();
overflow
.
setParent
(
getPos
());
// store.updateRecord(firstOverflowPageId);
index
.
getPageStore
().
updateRecord
(
overflow
,
true
,
null
);
// DataPage overflow = store.readPage(firstOverflowPageId);
// overflow.reset();
// overflow.writeInt(getPos());
// store.writePage(firstOverflowPageId, overflow);
}
}
boolean
remove
(
int
key
)
throws
SQLException
{
boolean
remove
(
int
key
)
throws
SQLException
{
...
@@ -299,17 +284,7 @@ class PageDataLeaf extends PageData {
...
@@ -299,17 +284,7 @@ class PageDataLeaf extends PageData {
PageStore
store
=
index
.
getPageStore
();
PageStore
store
=
index
.
getPageStore
();
int
next
=
firstOverflowPageId
;
int
next
=
firstOverflowPageId
;
do
{
do
{
Record
record
=
store
.
getRecord
(
next
);
PageDataLeafOverflow
page
=
index
.
getPageOverflow
(
next
,
this
,
0
);
PageDataLeafOverflow
page
;
if
(
record
==
null
)
{
DataPage
data
=
store
.
readPage
(
next
);
page
=
new
PageDataLeafOverflow
(
this
,
next
,
data
,
0
);
}
else
{
if
(!(
record
instanceof
PageDataLeafOverflow
))
{
throw
Message
.
getInternalError
(
"page:"
+
next
+
" "
+
record
,
null
);
}
page
=
(
PageDataLeafOverflow
)
record
;
}
store
.
freePage
(
next
,
false
,
null
);
store
.
freePage
(
next
,
false
,
null
);
next
=
page
.
getNextOverflow
();
next
=
page
.
getNextOverflow
();
}
while
(
next
!=
0
);
}
while
(
next
!=
0
);
...
...
h2/src/main/org/h2/index/PageDataLeafOverflow.java
浏览文件 @
6be4766c
...
@@ -8,7 +8,6 @@ package org.h2.index;
...
@@ -8,7 +8,6 @@ package org.h2.index;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.ErrorCode
;
import
org.h2.jdbc.JdbcSQLException
;
import
org.h2.message.Message
;
import
org.h2.message.Message
;
import
org.h2.store.DataPage
;
import
org.h2.store.DataPage
;
import
org.h2.store.PageStore
;
import
org.h2.store.PageStore
;
...
@@ -41,22 +40,22 @@ public class PageDataLeafOverflow extends Record {
...
@@ -41,22 +40,22 @@ public class PageDataLeafOverflow extends Record {
/**
/**
* The page type.
* The page type.
*/
*/
private
final
int
type
;
private
int
type
;
/**
/**
* The p
revious
page (overflow or leaf).
* The p
arent
page (overflow or leaf).
*/
*/
private
final
int
previous
Page
;
private
int
parent
Page
;
/**
/**
* The next overflow page, or 0.
* The next overflow page, or 0.
*/
*/
private
final
int
nextPage
;
private
int
nextPage
;
/**
/**
* The number of content bytes.
* The number of content bytes.
*/
*/
private
final
int
size
;
private
int
size
;
/**
/**
* The first content byte starts at the given position
* The first content byte starts at the given position
...
@@ -70,18 +69,32 @@ public class PageDataLeafOverflow extends Record {
...
@@ -70,18 +69,32 @@ public class PageDataLeafOverflow extends Record {
this
.
leaf
=
leaf
;
this
.
leaf
=
leaf
;
setPos
(
pageId
);
setPos
(
pageId
);
this
.
type
=
type
;
this
.
type
=
type
;
this
.
p
revious
Page
=
previous
;
this
.
p
arent
Page
=
previous
;
this
.
nextPage
=
next
;
this
.
nextPage
=
next
;
this
.
offset
=
offset
;
this
.
offset
=
offset
;
this
.
size
=
size
;
this
.
size
=
size
;
}
}
public
PageDataLeafOverflow
(
PageDataLeaf
leaf
,
int
pageId
,
DataPage
data
,
int
offset
)
throws
JdbcSQLException
{
/**
* Create an object from the given data page.
*
* @param leaf the leaf page
* @param pageId the page id
* @param data the data page
* @param offset the offset
*/
public
PageDataLeafOverflow
(
PageDataLeaf
leaf
,
int
pageId
,
DataPage
data
,
int
offset
)
{
this
.
leaf
=
leaf
;
this
.
leaf
=
leaf
;
setPos
(
pageId
);
setPos
(
pageId
);
this
.
data
=
data
;
this
.
data
=
data
;
this
.
offset
=
offset
;
this
.
offset
=
offset
;
previousPage
=
data
.
readInt
();
}
/**
* Read the page.
*/
void
read
()
throws
SQLException
{
parentPage
=
data
.
readInt
();
type
=
data
.
readByte
();
type
=
data
.
readByte
();
if
(
type
==
(
Page
.
TYPE_DATA_OVERFLOW
|
Page
.
FLAG_LAST
))
{
if
(
type
==
(
Page
.
TYPE_DATA_OVERFLOW
|
Page
.
FLAG_LAST
))
{
size
=
data
.
readShortInt
();
size
=
data
.
readShortInt
();
...
@@ -121,7 +134,7 @@ public class PageDataLeafOverflow extends Record {
...
@@ -121,7 +134,7 @@ public class PageDataLeafOverflow extends Record {
PageStore
store
=
leaf
.
getPageStore
();
PageStore
store
=
leaf
.
getPageStore
();
DataPage
overflow
=
store
.
createDataPage
();
DataPage
overflow
=
store
.
createDataPage
();
DataPage
data
=
leaf
.
getDataPage
();
DataPage
data
=
leaf
.
getDataPage
();
overflow
.
writeInt
(
p
revious
Page
);
overflow
.
writeInt
(
p
arent
Page
);
overflow
.
writeByte
((
byte
)
type
);
overflow
.
writeByte
((
byte
)
type
);
if
(
type
==
Page
.
TYPE_DATA_OVERFLOW
)
{
if
(
type
==
Page
.
TYPE_DATA_OVERFLOW
)
{
overflow
.
writeInt
(
nextPage
);
overflow
.
writeInt
(
nextPage
);
...
@@ -133,7 +146,7 @@ public class PageDataLeafOverflow extends Record {
...
@@ -133,7 +146,7 @@ public class PageDataLeafOverflow extends Record {
}
}
public
String
toString
()
{
public
String
toString
()
{
return
"page["
+
getPos
()
+
"] data leaf overflow p
rev:"
+
previous
Page
+
" next:"
+
nextPage
;
return
"page["
+
getPos
()
+
"] data leaf overflow p
arent:"
+
parent
Page
+
" next:"
+
nextPage
;
}
}
/**
/**
...
@@ -145,4 +158,12 @@ public class PageDataLeafOverflow extends Record {
...
@@ -145,4 +158,12 @@ public class PageDataLeafOverflow extends Record {
return
leaf
.
getMemorySize
();
return
leaf
.
getMemorySize
();
}
}
int
getParent
()
{
return
parentPage
;
}
void
setParent
(
int
parent
)
{
this
.
parentPage
=
parent
;
}
}
}
h2/src/main/org/h2/index/PageDataNode.java
浏览文件 @
6be4766c
...
@@ -93,7 +93,7 @@ class PageDataNode extends PageData {
...
@@ -93,7 +93,7 @@ class PageDataNode extends PageData {
PageData
page2
=
page
.
split
(
splitPoint
);
PageData
page2
=
page
.
split
(
splitPoint
);
index
.
getPageStore
().
updateRecord
(
page
,
true
,
page
.
data
);
index
.
getPageStore
().
updateRecord
(
page
,
true
,
page
.
data
);
index
.
getPageStore
().
updateRecord
(
page2
,
true
,
page2
.
data
);
index
.
getPageStore
().
updateRecord
(
page2
,
true
,
page2
.
data
);
addChild
(
x
,
page2
.
getP
ageId
(),
pivot
);
addChild
(
x
,
page2
.
getP
os
(),
pivot
);
index
.
getPageStore
().
updateRecord
(
this
,
true
,
data
);
index
.
getPageStore
().
updateRecord
(
this
,
true
,
data
);
}
}
updateRowCount
(
1
);
updateRowCount
(
1
);
...
@@ -148,7 +148,7 @@ class PageDataNode extends PageData {
...
@@ -148,7 +148,7 @@ class PageDataNode extends PageData {
*/
*/
void
init
(
PageData
page1
,
int
pivot
,
PageData
page2
)
{
void
init
(
PageData
page1
,
int
pivot
,
PageData
page2
)
{
entryCount
=
1
;
entryCount
=
1
;
childPageIds
=
new
int
[]
{
page1
.
getP
ageId
(),
page2
.
getPageId
()
};
childPageIds
=
new
int
[]
{
page1
.
getP
os
(),
page2
.
getPos
()
};
keys
=
new
int
[]
{
pivot
};
keys
=
new
int
[]
{
pivot
};
check
();
check
();
}
}
...
@@ -193,7 +193,7 @@ class PageDataNode extends PageData {
...
@@ -193,7 +193,7 @@ class PageDataNode extends PageData {
return
false
;
return
false
;
}
}
// this child is now empty
// this child is now empty
index
.
getPageStore
().
freePage
(
page
.
getP
ageId
(),
true
,
page
.
data
);
index
.
getPageStore
().
freePage
(
page
.
getP
os
(),
true
,
page
.
data
);
if
(
entryCount
<
1
)
{
if
(
entryCount
<
1
)
{
// no more children - this page is empty as well
// no more children - this page is empty as well
return
true
;
return
true
;
...
@@ -224,7 +224,7 @@ class PageDataNode extends PageData {
...
@@ -224,7 +224,7 @@ class PageDataNode extends PageData {
for
(
int
child
:
childPageIds
)
{
for
(
int
child
:
childPageIds
)
{
PageData
page
=
index
.
getPage
(
child
,
getPos
());
PageData
page
=
index
.
getPage
(
child
,
getPos
());
if
(
getPos
()
==
page
.
getPos
())
{
if
(
getPos
()
==
page
.
getPos
())
{
throw
Message
.
throwInternalError
(
"Page it its own child: "
+
getP
ageId
());
throw
Message
.
throwInternalError
(
"Page it its own child: "
+
getP
os
());
}
}
count
+=
page
.
getRowCount
();
count
+=
page
.
getRowCount
();
}
}
...
...
h2/src/main/org/h2/index/PageScanIndex.java
浏览文件 @
6be4766c
...
@@ -19,7 +19,6 @@ import org.h2.engine.Constants;
...
@@ -19,7 +19,6 @@ import org.h2.engine.Constants;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.log.UndoLogRecord
;
import
org.h2.log.UndoLogRecord
;
import
org.h2.message.Message
;
import
org.h2.message.Message
;
import
org.h2.message.TraceSystem
;
import
org.h2.result.Row
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SearchRow
;
import
org.h2.store.DataPage
;
import
org.h2.store.DataPage
;
...
@@ -50,8 +49,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
...
@@ -50,8 +49,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
public
PageScanIndex
(
TableData
table
,
int
id
,
IndexColumn
[]
columns
,
IndexType
indexType
,
int
headPos
,
Session
session
)
throws
SQLException
{
public
PageScanIndex
(
TableData
table
,
int
id
,
IndexColumn
[]
columns
,
IndexType
indexType
,
int
headPos
,
Session
session
)
throws
SQLException
{
initBaseIndex
(
table
,
id
,
table
.
getName
()
+
"_TABLE_SCAN"
,
columns
,
indexType
);
initBaseIndex
(
table
,
id
,
table
.
getName
()
+
"_TABLE_SCAN"
,
columns
,
indexType
);
int
test
;
// trace.setLevel(TraceSystem.DEBUG);
// trace.setLevel(TraceSystem.DEBUG);
if
(
database
.
isMultiVersion
())
{
if
(
database
.
isMultiVersion
())
{
sessionRowCount
=
New
.
hashMap
();
sessionRowCount
=
New
.
hashMap
();
isMultiVersion
=
true
;
isMultiVersion
=
true
;
...
@@ -59,9 +57,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
...
@@ -59,9 +57,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
tableData
=
table
;
tableData
=
table
;
this
.
store
=
database
.
getPageStore
();
this
.
store
=
database
.
getPageStore
();
if
(!
database
.
isPersistent
())
{
if
(!
database
.
isPersistent
())
{
int
todo
;
this
.
headPos
=
0
;
this
.
headPos
=
0
;
return
;
throw
Message
.
throwInternalError
(
table
.
getName
())
;
}
}
if
(
headPos
==
Index
.
EMPTY_HEAD
)
{
if
(
headPos
==
Index
.
EMPTY_HEAD
)
{
// new table
// new table
...
@@ -82,7 +79,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
...
@@ -82,7 +79,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
// TODO check if really required
// TODO check if really required
store
.
updateRecord
(
root
,
false
,
null
);
store
.
updateRecord
(
root
,
false
,
null
);
}
}
int
reuseKeysIfManyDeleted
;
// TODO re-use keys after many rows are deleted
}
}
if
(
trace
.
isDebugEnabled
())
{
if
(
trace
.
isDebugEnabled
())
{
trace
.
debug
(
"opened "
+
getName
()
+
" rows:"
+
rowCount
);
trace
.
debug
(
"opened "
+
getName
()
+
" rows:"
+
rowCount
);
...
@@ -127,7 +124,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
...
@@ -127,7 +124,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
int
pivot
=
root
.
getKey
(
splitPoint
-
1
);
int
pivot
=
root
.
getKey
(
splitPoint
-
1
);
PageData
page1
=
root
;
PageData
page1
=
root
;
PageData
page2
=
root
.
split
(
splitPoint
);
PageData
page2
=
root
.
split
(
splitPoint
);
int
rootPageId
=
root
.
getP
ageId
();
int
rootPageId
=
root
.
getP
os
();
int
id
=
store
.
allocatePage
();
int
id
=
store
.
allocatePage
();
page1
.
setPageId
(
id
);
page1
.
setPageId
(
id
);
page1
.
setParentPageId
(
headPos
);
page1
.
setParentPageId
(
headPos
);
...
@@ -154,6 +151,25 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
...
@@ -154,6 +151,25 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
store
.
logAddOrRemoveRow
(
session
,
tableData
.
getId
(),
row
,
true
);
store
.
logAddOrRemoveRow
(
session
,
tableData
.
getId
(),
row
,
true
);
}
}
/**
* Read an overflow page page.
*
* @param id the page id
* @param leaf the leaf page
* @return the page
*/
PageDataLeafOverflow
getPageOverflow
(
int
id
,
PageDataLeaf
leaf
,
int
offset
)
throws
SQLException
{
Record
rec
=
store
.
getRecord
(
id
);
if
(
rec
!=
null
)
{
return
(
PageDataLeafOverflow
)
rec
;
}
DataPage
data
=
store
.
readPage
(
id
);
data
.
reset
();
PageDataLeafOverflow
result
=
new
PageDataLeafOverflow
(
leaf
,
id
,
data
,
offset
);
result
.
read
();
return
result
;
}
/**
/**
* Read the given page.
* Read the given page.
*
*
...
@@ -233,20 +249,16 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
...
@@ -233,20 +249,16 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
}
}
}
}
}
}
int
invalidateRowCount
;
// TODO invalidate the row count
// setChanged(session);
// setChanged(session);
if
(
rowCount
==
1
)
{
if
(
rowCount
==
1
)
{
int
todoMaybeImprove
;
removeAllRows
();
removeAllRows
();
}
else
{
}
else
{
int
key
=
row
.
getPos
();
int
key
=
row
.
getPos
();
PageData
root
=
getPage
(
headPos
,
0
);
PageData
root
=
getPage
(
headPos
,
0
);
root
.
remove
(
key
);
root
.
remove
(
key
);
rowCount
--;
rowCount
--;
int
todoReuseKeys
;
// TODO re-use keys
// if (key == lastKey - 1) {
// lastKey--;
// }
}
}
if
(
database
.
isMultiVersion
())
{
if
(
database
.
isMultiVersion
())
{
// if storage is null, the delete flag is not yet set
// if storage is null, the delete flag is not yet set
...
@@ -355,9 +367,9 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
...
@@ -355,9 +367,9 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
if
(
sessionRowCount
!=
null
)
{
if
(
sessionRowCount
!=
null
)
{
sessionRowCount
.
clear
();
sessionRowCount
.
clear
();
}
}
int
todoWhyNotClose
;
// can not close the index because it might get used afterwards,
//
store = null;
//
for example after running recovery
int
writeRowCount
;
// TODO write the row count
}
}
Iterator
<
Row
>
getDelta
()
{
Iterator
<
Row
>
getDelta
()
{
...
...
h2/src/main/org/h2/store/PageLog.java
浏览文件 @
6be4766c
...
@@ -149,8 +149,8 @@ public class PageLog {
...
@@ -149,8 +149,8 @@ public class PageLog {
if
(
store
.
getRecord
(
firstTrunkPage
)
!=
null
)
{
if
(
store
.
getRecord
(
firstTrunkPage
)
!=
null
)
{
// if the page is in use, don't free it
// if the page is in use, don't free it
// TODO cleanup - this is a hack
// TODO cleanup - this is a hack
int
todoCleanup
;
// break
;
break
;
throw
Message
.
throwInternalError
(
""
+
store
.
getRecord
(
firstTrunkPage
))
;
}
}
PageStreamTrunk
t
=
new
PageStreamTrunk
(
store
,
this
.
firstTrunkPage
);
PageStreamTrunk
t
=
new
PageStreamTrunk
(
store
,
this
.
firstTrunkPage
);
try
{
try
{
...
@@ -315,7 +315,7 @@ public class PageLog {
...
@@ -315,7 +315,7 @@ public class PageLog {
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
values
[
i
]
=
data
.
readValue
();
values
[
i
]
=
data
.
readValue
();
}
}
int
todoTableDataReadRowWithMemory
;
// TODO maybe calculate the memory usage
Row
row
=
new
Row
(
values
,
0
);
Row
row
=
new
Row
(
values
,
0
);
row
.
setPos
(
pos
);
row
.
setPos
(
pos
);
return
row
;
return
row
;
...
...
h2/src/main/org/h2/store/PageStore.java
浏览文件 @
6be4766c
...
@@ -24,7 +24,6 @@ import org.h2.log.InDoubtTransaction;
...
@@ -24,7 +24,6 @@ import org.h2.log.InDoubtTransaction;
import
org.h2.log.LogSystem
;
import
org.h2.log.LogSystem
;
import
org.h2.message.Message
;
import
org.h2.message.Message
;
import
org.h2.message.Trace
;
import
org.h2.message.Trace
;
import
org.h2.message.TraceSystem
;
import
org.h2.result.Row
;
import
org.h2.result.Row
;
import
org.h2.schema.Schema
;
import
org.h2.schema.Schema
;
import
org.h2.table.Column
;
import
org.h2.table.Column
;
...
@@ -201,8 +200,7 @@ public class PageStore implements CacheWriter {
...
@@ -201,8 +200,7 @@ public class PageStore implements CacheWriter {
this
.
accessMode
=
accessMode
;
this
.
accessMode
=
accessMode
;
this
.
database
=
database
;
this
.
database
=
database
;
trace
=
database
.
getTrace
(
Trace
.
PAGE_STORE
);
trace
=
database
.
getTrace
(
Trace
.
PAGE_STORE
);
int
test
;
// trace.setLevel(TraceSystem.DEBUG);
// trace.setLevel(TraceSystem.DEBUG);
this
.
cacheSize
=
cacheSizeDefault
;
this
.
cacheSize
=
cacheSizeDefault
;
String
cacheType
=
database
.
getCacheType
();
String
cacheType
=
database
.
getCacheType
();
this
.
cache
=
CacheLRU
.
getCache
(
this
,
cacheType
,
cacheSize
);
this
.
cache
=
CacheLRU
.
getCache
(
this
,
cacheType
,
cacheSize
);
...
@@ -975,32 +973,6 @@ public class PageStore implements CacheWriter {
...
@@ -975,32 +973,6 @@ public class PageStore implements CacheWriter {
}
}
}
}
private
void
updateChecksum
(
byte
[]
d
,
int
pos
)
{
int
ps
=
pageSize
;
int
s1
=
255
+
(
d
[
0
]
&
255
),
s2
=
255
+
s1
;
s2
+=
s1
+=
d
[
1
]
&
255
;
s2
+=
s1
+=
d
[(
ps
>>
1
)
-
1
]
&
255
;
s2
+=
s1
+=
d
[
ps
>>
1
]
&
255
;
s2
+=
s1
+=
d
[
ps
-
2
]
&
255
;
s2
+=
s1
+=
d
[
ps
-
1
]
&
255
;
d
[
5
]
=
(
byte
)
(((
s1
&
255
)
+
(
s1
>>
8
))
^
pos
);
d
[
6
]
=
(
byte
)
(((
s2
&
255
)
+
(
s2
>>
8
))
^
(
pos
>>
8
));
}
private
void
verifyChecksum
(
byte
[]
d
,
int
pos
)
throws
SQLException
{
int
ps
=
pageSize
;
int
s1
=
255
+
(
d
[
0
]
&
255
),
s2
=
255
+
s1
;
s2
+=
s1
+=
d
[
1
]
&
255
;
s2
+=
s1
+=
d
[(
ps
>>
1
)
-
1
]
&
255
;
s2
+=
s1
+=
d
[
ps
>>
1
]
&
255
;
s2
+=
s1
+=
d
[
ps
-
2
]
&
255
;
s2
+=
s1
+=
d
[
ps
-
1
]
&
255
;
if
(
d
[
5
]
!=
(
byte
)
(((
s1
&
255
)
+
(
s1
>>
8
))
^
pos
)
||
d
[
6
]
!=
(
byte
)
(((
s2
&
255
)
+
(
s2
>>
8
))
^
(
pos
>>
8
)))
{
throw
Message
.
getSQLException
(
ErrorCode
.
FILE_CORRUPTED_1
,
"wrong checksum"
);
}
}
/**
/**
* Set the maximum log file size in megabytes.
* Set the maximum log file size in megabytes.
*
*
...
@@ -1052,5 +1024,31 @@ public class PageStore implements CacheWriter {
...
@@ -1052,5 +1024,31 @@ public class PageStore implements CacheWriter {
}
}
}
}
// TODO implement checksum
// private void updateChecksum(byte[] d, int pos) {
// int ps = pageSize;
// int s1 = 255 + (d[0] & 255), s2 = 255 + s1;
// s2 += s1 += d[1] & 255;
// s2 += s1 += d[(ps >> 1) - 1] & 255;
// s2 += s1 += d[ps >> 1] & 255;
// s2 += s1 += d[ps - 2] & 255;
// s2 += s1 += d[ps - 1] & 255;
// d[5] = (byte) (((s1 & 255) + (s1 >> 8)) ^ pos);
// d[6] = (byte) (((s2 & 255) + (s2 >> 8)) ^ (pos >> 8));
// }
//
// private void verifyChecksum(byte[] d, int pos) throws SQLException {
// int ps = pageSize;
// int s1 = 255 + (d[0] & 255), s2 = 255 + s1;
// s2 += s1 += d[1] & 255;
// s2 += s1 += d[(ps >> 1) - 1] & 255;
// s2 += s1 += d[ps >> 1] & 255;
// s2 += s1 += d[ps - 2] & 255;
// s2 += s1 += d[ps - 1] & 255;
// if (d[5] != (byte) (((s1 & 255) + (s1 >> 8)) ^ pos)
// || d[6] != (byte) (((s2 & 255) + (s2 >> 8)) ^ (pos >> 8))) {
// throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1, "wrong checksum");
// }
// }
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论