Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
2bd33848
提交
2bd33848
authored
9月 13, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Page store: respect cache size at startup
上级
13dcb511
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
68 行增加
和
16 行删除
+68
-16
ConnectionInfo.java
h2/src/main/org/h2/engine/ConnectionInfo.java
+15
-0
Database.java
h2/src/main/org/h2/engine/Database.java
+7
-2
PageDataLeaf.java
h2/src/main/org/h2/index/PageDataLeaf.java
+5
-2
PageStore.java
h2/src/main/org/h2/store/PageStore.java
+7
-4
Recover.java
h2/src/main/org/h2/tools/Recover.java
+9
-8
TestPageStore.java
h2/src/test/org/h2/test/unit/TestPageStore.java
+25
-0
没有找到文件。
h2/src/main/org/h2/engine/ConnectionInfo.java
浏览文件 @
2bd33848
...
@@ -396,6 +396,21 @@ public class ConnectionInfo implements Cloneable {
...
@@ -396,6 +396,21 @@ public class ConnectionInfo implements Cloneable {
return
value
.
toString
();
return
value
.
toString
();
}
}
/**
* Get the value of the given property.
*
* @param key the property key
* @param defaultValue the default value
* @return the value as a String
*/
public
int
getProperty
(
String
key
,
int
defaultValue
)
{
if
(
SysProperties
.
CHECK
&&
!
isKnownSetting
(
key
))
{
Message
.
throwInternalError
(
key
);
}
String
s
=
getProperty
(
key
);
return
s
==
null
?
defaultValue
:
Integer
.
parseInt
(
s
);
}
/**
/**
* Get the value of the given property.
* Get the value of the given property.
*
*
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
2bd33848
...
@@ -169,6 +169,7 @@ public class Database implements DataHandler {
...
@@ -169,6 +169,7 @@ public class Database implements DataHandler {
private
Properties
reconnectLastLock
;
private
Properties
reconnectLastLock
;
private
volatile
long
reconnectCheckNext
;
private
volatile
long
reconnectCheckNext
;
private
volatile
boolean
reconnectChangePending
;
private
volatile
boolean
reconnectChangePending
;
private
int
cacheSize
;
public
Database
(
String
name
,
ConnectionInfo
ci
,
String
cipher
)
throws
SQLException
{
public
Database
(
String
name
,
ConnectionInfo
ci
,
String
cipher
)
throws
SQLException
{
this
.
compareMode
=
CompareMode
.
getInstance
(
null
,
0
);
this
.
compareMode
=
CompareMode
.
getInstance
(
null
,
0
);
...
@@ -182,6 +183,7 @@ public class Database implements DataHandler {
...
@@ -182,6 +183,7 @@ public class Database implements DataHandler {
this
.
accessModeData
=
ci
.
getProperty
(
"ACCESS_MODE_DATA"
,
"rw"
).
toLowerCase
();
this
.
accessModeData
=
ci
.
getProperty
(
"ACCESS_MODE_DATA"
,
"rw"
).
toLowerCase
();
this
.
autoServerMode
=
ci
.
getProperty
(
"AUTO_SERVER"
,
false
);
this
.
autoServerMode
=
ci
.
getProperty
(
"AUTO_SERVER"
,
false
);
this
.
usePageStore
=
ci
.
getProperty
(
"PAGE_STORE"
,
SysProperties
.
getPageStore
());
this
.
usePageStore
=
ci
.
getProperty
(
"PAGE_STORE"
,
SysProperties
.
getPageStore
());
this
.
cacheSize
=
ci
.
getProperty
(
"CACHE_SIZE"
,
SysProperties
.
CACHE_SIZE_DEFAULT
);
if
(
"r"
.
equals
(
accessModeData
))
{
if
(
"r"
.
equals
(
accessModeData
))
{
readOnly
=
true
;
readOnly
=
true
;
accessModeLog
=
"r"
;
accessModeLog
=
"r"
;
...
@@ -1767,11 +1769,15 @@ public class Database implements DataHandler {
...
@@ -1767,11 +1769,15 @@ public class Database implements DataHandler {
}
}
public
synchronized
void
setCacheSize
(
int
kb
)
throws
SQLException
{
public
synchronized
void
setCacheSize
(
int
kb
)
throws
SQLException
{
cacheSize
=
kb
;
if
(
fileData
!=
null
)
{
if
(
fileData
!=
null
)
{
fileData
.
getCache
().
setMaxSize
(
kb
);
fileData
.
getCache
().
setMaxSize
(
kb
);
int
valueIndex
=
kb
<=
32
?
kb
:
(
kb
>>>
SysProperties
.
CACHE_SIZE_INDEX_SHIFT
);
int
valueIndex
=
kb
<=
32
?
kb
:
(
kb
>>>
SysProperties
.
CACHE_SIZE_INDEX_SHIFT
);
fileIndex
.
getCache
().
setMaxSize
(
valueIndex
);
fileIndex
.
getCache
().
setMaxSize
(
valueIndex
);
}
}
if
(
pageStore
!=
null
)
{
pageStore
.
getCache
().
setMaxSize
(
kb
);
}
}
}
public
synchronized
void
setMasterUser
(
User
user
)
throws
SQLException
{
public
synchronized
void
setMasterUser
(
User
user
)
throws
SQLException
{
...
@@ -2250,8 +2256,7 @@ public class Database implements DataHandler {
...
@@ -2250,8 +2256,7 @@ public class Database implements DataHandler {
public
PageStore
getPageStore
()
throws
SQLException
{
public
PageStore
getPageStore
()
throws
SQLException
{
if
(
pageStore
==
null
&&
usePageStore
)
{
if
(
pageStore
==
null
&&
usePageStore
)
{
pageStore
=
new
PageStore
(
this
,
databaseName
+
Constants
.
SUFFIX_PAGE_FILE
,
accessModeData
,
pageStore
=
new
PageStore
(
this
,
databaseName
+
Constants
.
SUFFIX_PAGE_FILE
,
accessModeData
,
cacheSize
);
SysProperties
.
CACHE_SIZE_DEFAULT
);
pageStore
.
open
();
pageStore
.
open
();
}
}
return
pageStore
;
return
pageStore
;
...
...
h2/src/main/org/h2/index/PageDataLeaf.java
浏览文件 @
2bd33848
...
@@ -208,6 +208,10 @@ public class PageDataLeaf extends PageData {
...
@@ -208,6 +208,10 @@ public class PageDataLeaf extends PageData {
// free up the space used by the row
// free up the space used by the row
rowRef
=
new
SoftReference
<
Row
>(
rows
[
0
]);
rowRef
=
new
SoftReference
<
Row
>(
rows
[
0
]);
rows
[
0
]
=
null
;
rows
[
0
]
=
null
;
Data
all
=
index
.
getPageStore
().
createData
();
all
.
checkCapacity
(
data
.
length
());
all
.
write
(
data
.
getBytes
(),
0
,
data
.
length
());
data
.
truncate
(
index
.
getPageStore
().
getPageSize
());
do
{
do
{
int
type
,
size
,
next
;
int
type
,
size
,
next
;
if
(
remaining
<=
pageSize
-
PageDataOverflow
.
START_LAST
)
{
if
(
remaining
<=
pageSize
-
PageDataOverflow
.
START_LAST
)
{
...
@@ -219,14 +223,13 @@ public class PageDataLeaf extends PageData {
...
@@ -219,14 +223,13 @@ public class PageDataLeaf extends PageData {
size
=
pageSize
-
PageDataOverflow
.
START_MORE
;
size
=
pageSize
-
PageDataOverflow
.
START_MORE
;
next
=
index
.
getPageStore
().
allocatePage
();
next
=
index
.
getPageStore
().
allocatePage
();
}
}
PageDataOverflow
overflow
=
new
PageDataOverflow
(
index
,
page
,
type
,
previous
,
next
,
data
,
dataOffset
,
size
);
PageDataOverflow
overflow
=
new
PageDataOverflow
(
index
,
page
,
type
,
previous
,
next
,
all
,
dataOffset
,
size
);
index
.
getPageStore
().
updateRecord
(
overflow
,
true
,
null
);
index
.
getPageStore
().
updateRecord
(
overflow
,
true
,
null
);
dataOffset
+=
size
;
dataOffset
+=
size
;
remaining
-=
size
;
remaining
-=
size
;
previous
=
page
;
previous
=
page
;
page
=
next
;
page
=
next
;
}
while
(
remaining
>
0
);
}
while
(
remaining
>
0
);
data
.
truncate
(
index
.
getPageStore
().
getPageSize
());
}
}
return
-
1
;
return
-
1
;
}
}
...
...
h2/src/main/org/h2/store/PageStore.java
浏览文件 @
2bd33848
...
@@ -167,7 +167,6 @@ public class PageStore implements CacheWriter {
...
@@ -167,7 +167,6 @@ public class PageStore implements CacheWriter {
private
long
writeCount
;
private
long
writeCount
;
private
int
logFirstTrunkPage
,
logFirstDataPage
;
private
int
logFirstTrunkPage
,
logFirstDataPage
;
private
int
cacheSize
;
private
Cache
cache
;
private
Cache
cache
;
private
int
freeListPagesPerList
;
private
int
freeListPagesPerList
;
...
@@ -218,9 +217,8 @@ public class PageStore implements CacheWriter {
...
@@ -218,9 +217,8 @@ public class PageStore implements CacheWriter {
trace
=
database
.
getTrace
(
Trace
.
PAGE_STORE
);
trace
=
database
.
getTrace
(
Trace
.
PAGE_STORE
);
// int test;
// int test;
// trace.setLevel(TraceSystem.DEBUG);
// trace.setLevel(TraceSystem.DEBUG);
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
Default
);
systemSession
=
new
Session
(
database
,
null
,
0
);
systemSession
=
new
Session
(
database
,
null
,
0
);
}
}
...
@@ -1130,7 +1128,7 @@ public class PageStore implements CacheWriter {
...
@@ -1130,7 +1128,7 @@ public class PageStore implements CacheWriter {
private
void
removeMeta
(
int
logPos
,
Row
row
)
throws
SQLException
{
private
void
removeMeta
(
int
logPos
,
Row
row
)
throws
SQLException
{
int
id
=
row
.
getValue
(
0
).
getInt
();
int
id
=
row
.
getValue
(
0
).
getInt
();
Index
index
=
metaObjects
.
remove
(
id
);
Index
index
=
metaObjects
.
get
(
id
);
int
headPos
=
index
.
getHeadPos
();
int
headPos
=
index
.
getHeadPos
();
index
.
getTable
().
removeIndex
(
index
);
index
.
getTable
().
removeIndex
(
index
);
if
(
index
instanceof
PageBtreeIndex
)
{
if
(
index
instanceof
PageBtreeIndex
)
{
...
@@ -1143,6 +1141,7 @@ public class PageStore implements CacheWriter {
...
@@ -1143,6 +1141,7 @@ public class PageStore implements CacheWriter {
index
.
getSchema
().
remove
(
index
);
index
.
getSchema
().
remove
(
index
);
}
}
index
.
remove
(
systemSession
);
index
.
remove
(
systemSession
);
metaObjects
.
remove
(
id
);
if
(
reservedPages
!=
null
&&
reservedPages
.
containsKey
(
headPos
))
{
if
(
reservedPages
!=
null
&&
reservedPages
.
containsKey
(
headPos
))
{
// re-allocate the page if it is used later on again
// re-allocate the page if it is used later on again
int
latestPos
=
reservedPages
.
get
(
headPos
);
int
latestPos
=
reservedPages
.
get
(
headPos
);
...
@@ -1398,6 +1397,10 @@ public class PageStore implements CacheWriter {
...
@@ -1398,6 +1397,10 @@ public class PageStore implements CacheWriter {
return
metaRootPageId
.
get
(
indexId
);
return
metaRootPageId
.
get
(
indexId
);
}
}
public
Cache
getCache
()
{
return
cache
;
}
// TODO implement checksum
// TODO implement checksum
// private void updateChecksum(byte[] d, int pos) {
// private void updateChecksum(byte[] d, int pos) {
// int ps = pageSize;
// int ps = pageSize;
...
...
h2/src/main/org/h2/tools/Recover.java
浏览文件 @
2bd33848
...
@@ -87,6 +87,8 @@ public class Recover extends Tool implements DataHandler {
...
@@ -87,6 +87,8 @@ public class Recover extends Tool implements DataHandler {
private
long
pageDataEmpty
;
private
long
pageDataEmpty
;
private
int
pageDataRows
;
private
int
pageDataRows
;
private
int
pageDataHead
;
private
int
pageDataHead
;
private
int
pageSize
;
private
FileStore
store
;
/**
/**
* Options are case sensitive. Supported options are:
* Options are case sensitive. Supported options are:
...
@@ -723,7 +725,6 @@ public class Recover extends Tool implements DataHandler {
...
@@ -723,7 +725,6 @@ public class Recover extends Tool implements DataHandler {
private
void
dumpPageStore
(
String
fileName
)
{
private
void
dumpPageStore
(
String
fileName
)
{
setDatabaseName
(
fileName
.
substring
(
0
,
fileName
.
length
()
-
Constants
.
SUFFIX_PAGE_FILE
.
length
()));
setDatabaseName
(
fileName
.
substring
(
0
,
fileName
.
length
()
-
Constants
.
SUFFIX_PAGE_FILE
.
length
()));
FileStore
store
=
null
;
PrintWriter
writer
=
null
;
PrintWriter
writer
=
null
;
int
[]
pageTypeCount
=
new
int
[
Page
.
TYPE_STREAM_DATA
+
2
];
int
[]
pageTypeCount
=
new
int
[
Page
.
TYPE_STREAM_DATA
+
2
];
int
emptyPages
=
0
;
int
emptyPages
=
0
;
...
@@ -746,7 +747,7 @@ public class Recover extends Tool implements DataHandler {
...
@@ -746,7 +747,7 @@ public class Recover extends Tool implements DataHandler {
store
.
seek
(
0
);
store
.
seek
(
0
);
store
.
readFully
(
s
.
getBytes
(),
0
,
128
);
store
.
readFully
(
s
.
getBytes
(),
0
,
128
);
s
.
setPos
(
48
);
s
.
setPos
(
48
);
int
pageSize
=
s
.
readInt
();
pageSize
=
s
.
readInt
();
int
writeVersion
=
s
.
readByte
();
int
writeVersion
=
s
.
readByte
();
int
readVersion
=
s
.
readByte
();
int
readVersion
=
s
.
readByte
();
writer
.
println
(
"-- pageSize: "
+
pageSize
+
writer
.
println
(
"-- pageSize: "
+
pageSize
+
...
@@ -815,7 +816,7 @@ public class Recover extends Tool implements DataHandler {
...
@@ -815,7 +816,7 @@ public class Recover extends Tool implements DataHandler {
int
columnCount
=
s
.
readVarInt
();
int
columnCount
=
s
.
readVarInt
();
int
entries
=
s
.
readShortInt
();
int
entries
=
s
.
readShortInt
();
writer
.
println
(
"-- page "
+
page
+
": data leaf "
+
(
last
?
"(last)"
:
""
)
+
" table: "
+
storageId
+
" entries: "
+
entries
+
" columns: "
+
columnCount
);
writer
.
println
(
"-- page "
+
page
+
": data leaf "
+
(
last
?
"(last)"
:
""
)
+
" table: "
+
storageId
+
" entries: "
+
entries
+
" columns: "
+
columnCount
);
dumpPageDataLeaf
(
store
,
pageSize
,
writer
,
s
,
last
,
page
,
columnCount
,
entries
);
dumpPageDataLeaf
(
writer
,
s
,
last
,
page
,
columnCount
,
entries
);
break
;
break
;
}
}
// type 2
// type 2
...
@@ -856,7 +857,7 @@ public class Recover extends Tool implements DataHandler {
...
@@ -856,7 +857,7 @@ public class Recover extends Tool implements DataHandler {
case
Page
.
TYPE_FREE_LIST
:
case
Page
.
TYPE_FREE_LIST
:
pageTypeCount
[
type
]++;
pageTypeCount
[
type
]++;
writer
.
println
(
"-- page "
+
page
+
": free list "
+
(
last
?
"(last)"
:
""
));
writer
.
println
(
"-- page "
+
page
+
": free list "
+
(
last
?
"(last)"
:
""
));
free
+=
dumpPageFreeList
(
writer
,
s
,
page
Size
,
page
,
pageCount
);
free
+=
dumpPageFreeList
(
writer
,
s
,
page
,
pageCount
);
break
;
break
;
// type 7
// type 7
case
Page
.
TYPE_STREAM_TRUNK
:
case
Page
.
TYPE_STREAM_TRUNK
:
...
@@ -875,7 +876,7 @@ public class Recover extends Tool implements DataHandler {
...
@@ -875,7 +876,7 @@ public class Recover extends Tool implements DataHandler {
}
}
writeSchema
(
writer
);
writeSchema
(
writer
);
try
{
try
{
dumpPageLogStream
(
writer
,
store
,
logFirstTrunkPage
,
logFirstDataPage
,
pageSiz
e
);
dumpPageLogStream
(
writer
,
logFirstTrunkPage
,
logFirstDataPag
e
);
}
catch
(
EOFException
e
)
{
}
catch
(
EOFException
e
)
{
// ignore
// ignore
}
}
...
@@ -896,7 +897,7 @@ public class Recover extends Tool implements DataHandler {
...
@@ -896,7 +897,7 @@ public class Recover extends Tool implements DataHandler {
}
}
}
}
private
void
dumpPageLogStream
(
PrintWriter
writer
,
FileStore
store
,
int
logFirstTrunkPage
,
int
logFirstDataPage
,
int
pageSiz
e
)
throws
IOException
,
SQLException
{
private
void
dumpPageLogStream
(
PrintWriter
writer
,
int
logFirstTrunkPage
,
int
logFirstDataPag
e
)
throws
IOException
,
SQLException
{
Data
s
=
Data
.
create
(
this
,
pageSize
);
Data
s
=
Data
.
create
(
this
,
pageSize
);
DataInputStream
in
=
new
DataInputStream
(
DataInputStream
in
=
new
DataInputStream
(
new
PageInputStream
(
writer
,
this
,
store
,
logFirstTrunkPage
,
logFirstDataPage
,
pageSize
)
new
PageInputStream
(
writer
,
this
,
store
,
logFirstTrunkPage
,
logFirstDataPage
,
pageSize
)
...
@@ -1115,7 +1116,7 @@ public class Recover extends Tool implements DataHandler {
...
@@ -1115,7 +1116,7 @@ public class Recover extends Tool implements DataHandler {
writer
.
println
(
"-- ["
+
entryCount
+
"] child: "
+
children
[
entryCount
]
+
" rowCount: "
+
rowCount
);
writer
.
println
(
"-- ["
+
entryCount
+
"] child: "
+
children
[
entryCount
]
+
" rowCount: "
+
rowCount
);
}
}
private
int
dumpPageFreeList
(
PrintWriter
writer
,
Data
s
,
int
pageSize
,
long
pageId
,
long
pageCount
)
{
private
int
dumpPageFreeList
(
PrintWriter
writer
,
Data
s
,
long
pageId
,
long
pageCount
)
{
int
pagesAddressed
=
PageFreeList
.
getPagesAddressed
(
pageSize
);
int
pagesAddressed
=
PageFreeList
.
getPagesAddressed
(
pageSize
);
BitField
used
=
new
BitField
();
BitField
used
=
new
BitField
();
for
(
int
i
=
0
;
i
<
pagesAddressed
;
i
+=
8
)
{
for
(
int
i
=
0
;
i
<
pagesAddressed
;
i
+=
8
)
{
...
@@ -1171,7 +1172,7 @@ public class Recover extends Tool implements DataHandler {
...
@@ -1171,7 +1172,7 @@ public class Recover extends Tool implements DataHandler {
}
}
}
}
private
void
dumpPageDataLeaf
(
FileStore
store
,
int
pageSize
,
PrintWriter
writer
,
Data
s
,
boolean
last
,
long
pageId
,
int
columnCount
,
int
entryCount
)
throws
SQLException
{
private
void
dumpPageDataLeaf
(
PrintWriter
writer
,
Data
s
,
boolean
last
,
long
pageId
,
int
columnCount
,
int
entryCount
)
throws
SQLException
{
long
[]
keys
=
new
long
[
entryCount
];
long
[]
keys
=
new
long
[
entryCount
];
int
[]
offsets
=
new
int
[
entryCount
];
int
[]
offsets
=
new
int
[
entryCount
];
long
next
=
0
;
long
next
=
0
;
...
...
h2/src/test/org/h2/test/unit/TestPageStore.java
浏览文件 @
2bd33848
...
@@ -32,6 +32,7 @@ public class TestPageStore extends TestBase {
...
@@ -32,6 +32,7 @@ public class TestPageStore extends TestBase {
}
}
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testRecoverDropIndex
();
testDropPk
();
testDropPk
();
testCreatePkLater
();
testCreatePkLater
();
testTruncate
();
testTruncate
();
...
@@ -41,6 +42,30 @@ public class TestPageStore extends TestBase {
...
@@ -41,6 +42,30 @@ public class TestPageStore extends TestBase {
testFuzzOperations
();
testFuzzOperations
();
}
}
private
void
testRecoverDropIndex
()
throws
SQLException
{
if
(
config
.
memory
)
{
return
;
}
deleteDb
(
"pageStore"
);
Connection
conn
=
getConnection
(
"pageStore"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"set write_delay 0"
);
stat
.
execute
(
"create table test(id int, name varchar) as select x, x from system_range(1, 1400)"
);
stat
.
execute
(
"create index idx_name on test(name)"
);
conn
.
close
();
conn
=
getConnection
(
"pageStore"
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"drop index idx_name"
);
stat
.
execute
(
"shutdown immediately"
);
try
{
conn
.
close
();
}
catch
(
SQLException
e
)
{
// ignore
}
conn
=
getConnection
(
"pageStore;cache_size=1"
);
conn
.
close
();
}
private
void
testDropPk
()
throws
SQLException
{
private
void
testDropPk
()
throws
SQLException
{
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
return
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论