Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
587c4750
提交
587c4750
authored
14 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
The memory mapped file system (nioMapped: file prefix) couldn't seek past the file length.
上级
a710d997
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
30 行增加
和
12 行删除
+30
-12
FileObjectDiskMapped.java
h2/src/main/org/h2/store/fs/FileObjectDiskMapped.java
+23
-12
TestFileSystem.java
h2/src/test/org/h2/test/unit/TestFileSystem.java
+7
-0
没有找到文件。
h2/src/main/org/h2/store/fs/FileObjectDiskMapped.java
浏览文件 @
587c4750
...
@@ -29,6 +29,12 @@ public class FileObjectDiskMapped implements FileObject {
...
@@ -29,6 +29,12 @@ public class FileObjectDiskMapped implements FileObject {
private
RandomAccessFile
file
;
private
RandomAccessFile
file
;
private
MappedByteBuffer
mapped
;
private
MappedByteBuffer
mapped
;
/**
* The position within the file. Can't use the position of the mapped buffer
* because it doesn't support seeking past the end of the file.
*/
private
int
pos
;
FileObjectDiskMapped
(
String
fileName
,
String
mode
)
throws
IOException
{
FileObjectDiskMapped
(
String
fileName
,
String
mode
)
throws
IOException
{
if
(
"r"
.
equals
(
mode
))
{
if
(
"r"
.
equals
(
mode
))
{
this
.
mode
=
MapMode
.
READ_ONLY
;
this
.
mode
=
MapMode
.
READ_ONLY
;
...
@@ -88,12 +94,12 @@ public class FileObjectDiskMapped implements FileObject {
...
@@ -88,12 +94,12 @@ public class FileObjectDiskMapped implements FileObject {
private
void
reMap
()
throws
IOException
{
private
void
reMap
()
throws
IOException
{
int
oldPos
=
0
;
int
oldPos
=
0
;
if
(
mapped
!=
null
)
{
if
(
mapped
!=
null
)
{
oldPos
=
mapped
.
position
()
;
oldPos
=
pos
;
mapped
.
force
();
mapped
.
force
();
unMap
();
unMap
();
}
}
long
length
=
file
.
length
();
long
length
=
file
.
length
();
checkFile
Length
(
length
);
checkFile
SizeLimit
(
length
);
// maps new MappedByteBuffer; the old one is disposed during GC
// maps new MappedByteBuffer; the old one is disposed during GC
mapped
=
file
.
getChannel
().
map
(
mode
,
0
,
length
);
mapped
=
file
.
getChannel
().
map
(
mode
,
0
,
length
);
int
limit
=
mapped
.
limit
();
int
limit
=
mapped
.
limit
();
...
@@ -104,11 +110,10 @@ public class FileObjectDiskMapped implements FileObject {
...
@@ -104,11 +110,10 @@ public class FileObjectDiskMapped implements FileObject {
if
(
SysProperties
.
NIO_LOAD_MAPPED
)
{
if
(
SysProperties
.
NIO_LOAD_MAPPED
)
{
mapped
.
load
();
mapped
.
load
();
}
}
int
pos
=
Math
.
min
(
oldPos
,
(
int
)
length
);
this
.
pos
=
Math
.
min
(
oldPos
,
(
int
)
length
);
mapped
.
position
(
pos
);
}
}
private
void
checkFile
Length
(
long
length
)
throws
IOException
{
private
void
checkFile
SizeLimit
(
long
length
)
throws
IOException
{
if
(
length
>
Integer
.
MAX_VALUE
)
{
if
(
length
>
Integer
.
MAX_VALUE
)
{
throw
new
IOException
(
"File over 2GB is not supported yet when using this file system"
);
throw
new
IOException
(
"File over 2GB is not supported yet when using this file system"
);
}
}
...
@@ -121,7 +126,7 @@ public class FileObjectDiskMapped implements FileObject {
...
@@ -121,7 +126,7 @@ public class FileObjectDiskMapped implements FileObject {
}
}
public
long
getFilePointer
()
{
public
long
getFilePointer
()
{
return
mapped
.
position
()
;
return
pos
;
}
}
public
String
getName
()
{
public
String
getName
()
{
...
@@ -134,7 +139,12 @@ public class FileObjectDiskMapped implements FileObject {
...
@@ -134,7 +139,12 @@ public class FileObjectDiskMapped implements FileObject {
public
void
readFully
(
byte
[]
b
,
int
off
,
int
len
)
throws
EOFException
{
public
void
readFully
(
byte
[]
b
,
int
off
,
int
len
)
throws
EOFException
{
try
{
try
{
mapped
.
position
(
pos
);
mapped
.
get
(
b
,
off
,
len
);
mapped
.
get
(
b
,
off
,
len
);
}
catch
(
IllegalArgumentException
e
)
{
EOFException
e2
=
new
EOFException
(
"EOF"
);
e2
.
initCause
(
e
);
throw
e2
;
}
catch
(
BufferUnderflowException
e
)
{
}
catch
(
BufferUnderflowException
e
)
{
EOFException
e2
=
new
EOFException
(
"EOF"
);
EOFException
e2
=
new
EOFException
(
"EOF"
);
e2
.
initCause
(
e
);
e2
.
initCause
(
e
);
...
@@ -143,26 +153,27 @@ public class FileObjectDiskMapped implements FileObject {
...
@@ -143,26 +153,27 @@ public class FileObjectDiskMapped implements FileObject {
}
}
public
void
seek
(
long
pos
)
throws
IOException
{
public
void
seek
(
long
pos
)
throws
IOException
{
checkFile
Length
(
pos
);
checkFile
SizeLimit
(
pos
);
mapped
.
position
((
int
)
pos
)
;
this
.
pos
=
(
int
)
pos
;
}
}
public
void
setFileLength
(
long
newLength
)
throws
IOException
{
public
void
setFileLength
(
long
newLength
)
throws
IOException
{
checkFile
Length
(
newLength
);
checkFile
SizeLimit
(
newLength
);
IOUtils
.
setLength
(
file
,
newLength
);
IOUtils
.
setLength
(
file
,
newLength
);
reMap
();
reMap
();
}
}
public
void
sync
()
throws
IOException
{
public
void
sync
()
throws
IOException
{
file
.
getFD
().
sync
();
mapped
.
force
();
mapped
.
force
();
file
.
getFD
().
sync
();
}
}
public
void
write
(
byte
[]
b
,
int
off
,
int
len
)
throws
IOException
{
public
void
write
(
byte
[]
b
,
int
off
,
int
len
)
throws
IOException
{
// check if need to expand file
// check if need to expand file
if
(
mapped
.
capacity
()
<
mapped
.
position
()
+
len
)
{
if
(
mapped
.
capacity
()
<
pos
+
len
)
{
setFileLength
(
mapped
.
position
()
+
len
);
setFileLength
(
pos
+
len
);
}
}
mapped
.
position
(
pos
);
mapped
.
put
(
b
,
off
,
len
);
mapped
.
put
(
b
,
off
,
len
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestFileSystem.java
浏览文件 @
587c4750
...
@@ -43,6 +43,7 @@ public class TestFileSystem extends TestBase {
...
@@ -43,6 +43,7 @@ public class TestFileSystem extends TestBase {
testDatabaseInJar
();
testDatabaseInJar
();
// set default part size to 1 << 10
// set default part size to 1 << 10
FileSystem
.
getInstance
(
"split:10:"
+
getBaseDir
()
+
"/fs"
);
FileSystem
.
getInstance
(
"split:10:"
+
getBaseDir
()
+
"/fs"
);
testFileSystem
(
"split:nioMapped:"
+
getBaseDir
()
+
"/fs"
);
testFileSystem
(
"split:"
+
getBaseDir
()
+
"/fs"
);
testFileSystem
(
"split:"
+
getBaseDir
()
+
"/fs"
);
testFileSystem
(
getBaseDir
()
+
"/fs"
);
testFileSystem
(
getBaseDir
()
+
"/fs"
);
testFileSystem
(
FileSystemMemory
.
PREFIX
);
testFileSystem
(
FileSystemMemory
.
PREFIX
);
...
@@ -151,6 +152,12 @@ public class TestFileSystem extends TestBase {
...
@@ -151,6 +152,12 @@ public class TestFileSystem extends TestBase {
Random
random
=
new
Random
(
1
);
Random
random
=
new
Random
(
1
);
random
.
nextBytes
(
buffer
);
random
.
nextBytes
(
buffer
);
fo
.
write
(
buffer
,
0
,
10000
);
fo
.
write
(
buffer
,
0
,
10000
);
fo
.
seek
(
20000
);
try
{
fo
.
readFully
(
buffer
,
0
,
1
);
}
catch
(
EOFException
e
)
{
// expected
}
fo
.
close
();
fo
.
close
();
long
lastMod
=
fs
.
getLastModified
(
fsBase
+
"/test"
);
long
lastMod
=
fs
.
getLastModified
(
fsBase
+
"/test"
);
if
(
lastMod
<
time
-
1999
)
{
if
(
lastMod
<
time
-
1999
)
{
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论