Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c1dd5a5c
提交
c1dd5a5c
authored
11月 13, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Handle interrupts in FilePathAsync and add it to tests
上级
57843714
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
40 行增加
和
25 行删除
+40
-25
FilePathAsync.java
h2/src/main/org/h2/store/fs/FilePathAsync.java
+27
-22
TestConcurrent.java
h2/src/test/org/h2/test/store/TestConcurrent.java
+12
-3
TestFileSystem.java
h2/src/test/org/h2/test/unit/TestFileSystem.java
+1
-0
没有找到文件。
h2/src/main/org/h2/store/fs/FilePathAsync.java
浏览文件 @
c1dd5a5c
...
...
@@ -15,6 +15,7 @@ import java.nio.file.OpenOption;
import
java.nio.file.Paths
;
import
java.nio.file.StandardOpenOption
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.Future
;
/**
* This file system stores files on disk and uses
...
...
@@ -81,6 +82,23 @@ class FileAsync extends FileBase {
private
long
position
;
private
static
<
T
>
T
complete
(
Future
<
T
>
future
)
throws
IOException
{
boolean
interrupted
=
false
;
for
(;;)
{
try
{
T
result
=
future
.
get
();
if
(
interrupted
)
{
Thread
.
currentThread
().
interrupt
();
}
return
result
;
}
catch
(
InterruptedException
e
)
{
interrupted
=
true
;
}
catch
(
ExecutionException
e
)
{
throw
new
IOException
(
e
.
getCause
());
}
}
}
FileAsync
(
String
fileName
,
String
mode
)
throws
IOException
{
this
.
name
=
fileName
;
OpenOption
[]
options
;
...
...
@@ -120,15 +138,10 @@ class FileAsync extends FileBase {
@Override
public
int
read
(
ByteBuffer
dst
)
throws
IOException
{
int
read
;
try
{
read
=
channel
.
read
(
dst
,
position
).
get
();
int
read
=
complete
(
channel
.
read
(
dst
,
position
));
if
(
read
>
0
)
{
position
+=
read
;
}
}
catch
(
InterruptedException
|
ExecutionException
e
)
{
throw
new
IOException
(
e
);
}
return
read
;
}
...
...
@@ -140,21 +153,15 @@ class FileAsync extends FileBase {
@Override
public
int
read
(
ByteBuffer
dst
,
long
position
)
throws
IOException
{
try
{
return
channel
.
read
(
dst
,
position
).
get
();
}
catch
(
InterruptedException
|
ExecutionException
e
)
{
throw
new
IOException
(
e
);
}
return
complete
(
channel
.
read
(
dst
,
position
));
}
@Override
public
int
write
(
ByteBuffer
src
,
long
position
)
throws
IOException
{
try
{
return
c
hannel
.
write
(
src
,
position
).
get
(
);
return
c
omplete
(
channel
.
write
(
src
,
position
)
);
}
catch
(
NonWritableChannelException
e
)
{
throw
new
IOException
(
"read only"
);
}
catch
(
InterruptedException
|
ExecutionException
e
)
{
throw
new
IOException
(
e
);
}
}
...
...
@@ -174,16 +181,14 @@ class FileAsync extends FileBase {
@Override
public
int
write
(
ByteBuffer
src
)
throws
IOException
{
int
read
;
int
written
;
try
{
read
=
channel
.
write
(
src
,
position
).
get
(
);
position
+=
read
;
written
=
complete
(
channel
.
write
(
src
,
position
)
);
position
+=
written
;
}
catch
(
NonWritableChannelException
e
)
{
throw
new
IOException
(
"read only"
);
}
catch
(
InterruptedException
|
ExecutionException
e
)
{
throw
new
IOException
(
e
);
}
return
read
;
return
written
;
}
@Override
...
...
h2/src/test/org/h2/test/store/TestConcurrent.java
浏览文件 @
c1dd5a5c
...
...
@@ -47,7 +47,8 @@ public class TestConcurrent extends TestMVStore {
@Override
public
void
test
()
throws
Exception
{
FileUtils
.
createDirectories
(
getBaseDir
());
testInterruptReopen
();
testInterruptReopenAsync
();
testInterruptReopenRetryNIO
();
testConcurrentSaveCompact
();
testConcurrentDataType
();
testConcurrentAutoCommitAndChange
();
...
...
@@ -64,8 +65,16 @@ public class TestConcurrent extends TestMVStore {
testConcurrentRead
();
}
private
void
testInterruptReopen
()
{
String
fileName
=
"retry:nio:"
+
getBaseDir
()
+
"/"
+
getTestName
();
private
void
testInterruptReopenAsync
()
{
testInterruptReopen
(
"async:"
);
}
private
void
testInterruptReopenRetryNIO
()
{
testInterruptReopen
(
"retry:nio:"
);
}
private
void
testInterruptReopen
(
String
prefix
)
{
String
fileName
=
prefix
+
getBaseDir
()
+
"/"
+
getTestName
();
FileUtils
.
delete
(
fileName
);
final
MVStore
s
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
...
...
h2/src/test/org/h2/test/unit/TestFileSystem.java
浏览文件 @
c1dd5a5c
...
...
@@ -83,6 +83,7 @@ public class TestFileSystem extends TestDb {
String
f
=
"split:10:"
+
getBaseDir
()
+
"/fs"
;
FileUtils
.
toRealPath
(
f
);
testFileSystem
(
getBaseDir
()
+
"/fs"
);
testFileSystem
(
"async:"
+
getBaseDir
()
+
"/fs"
);
testFileSystem
(
"memFS:"
);
testFileSystem
(
"memLZF:"
);
testFileSystem
(
"nioMemFS:"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论