提交 aa55aed2 authored 作者: Noel Grandin's avatar Noel Grandin

implement support for partial writes when testing MVStore

上级 fdc5aa12
...@@ -11,7 +11,6 @@ import java.nio.channels.FileChannel; ...@@ -11,7 +11,6 @@ import java.nio.channels.FileChannel;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import org.h2.mvstore.MVStore; import org.h2.mvstore.MVStore;
import org.h2.mvstore.MVStoreTool; import org.h2.mvstore.MVStoreTool;
import org.h2.store.fs.FilePath; import org.h2.store.fs.FilePath;
...@@ -129,6 +128,7 @@ public class TestReorderWrites extends TestBase { ...@@ -129,6 +128,7 @@ public class TestReorderWrites extends TestBase {
private void testFileSystem() throws IOException { private void testFileSystem() throws IOException {
FilePathReorderWrites fs = FilePathReorderWrites.register(); FilePathReorderWrites fs = FilePathReorderWrites.register();
FilePathReorderWrites.setPartialWrites(true);
String fileName = "reorder:memFS:test"; String fileName = "reorder:memFS:test";
ByteBuffer empty = ByteBuffer.allocate(1024); ByteBuffer empty = ByteBuffer.allocate(1024);
Random r = new Random(1); Random r = new Random(1);
......
...@@ -71,11 +71,11 @@ public class FilePathReorderWrites extends FilePathWrapper { ...@@ -71,11 +71,11 @@ public class FilePathReorderWrites extends FilePathWrapper {
* *
* @param partialWrites true to enable * @param partialWrites true to enable
*/ */
public void setPartialWrites(boolean partialWrites) { public static void setPartialWrites(boolean partialWrites) {
FilePathReorderWrites.partialWrites = partialWrites; FilePathReorderWrites.partialWrites = partialWrites;
} }
boolean getPartialWrites() { static boolean getPartialWrites() {
return partialWrites; return partialWrites;
} }
...@@ -261,12 +261,25 @@ class FileReorderWrites extends FileBase { ...@@ -261,12 +261,25 @@ class FileReorderWrites extends FileBase {
@Override @Override
public int write(ByteBuffer src) throws IOException { public int write(ByteBuffer src) throws IOException {
return addOperation(new FileWriteOperation(id++, readBase.position(), src)); return write(src, readBase.position());
} }
@Override @Override
public int write(ByteBuffer src, long position) throws IOException { public int write(ByteBuffer src, long position) throws IOException {
return addOperation(new FileWriteOperation(id++, position, src)); if (FilePathReorderWrites.getPartialWrites() && src.remaining() > 2) {
ByteBuffer buf1 = src.slice();
ByteBuffer buf2 = src.slice();
int len1 = src.remaining() / 2;
int len2 = src.remaining() - len1;
buf1.limit(buf1.limit() - len2);
buf2.position(buf2.position() + len1);
int x = addOperation(new FileWriteOperation(id++, position, buf1));
x += addOperation(
new FileWriteOperation(id++, position + len1, buf2));
return x;
} else {
return addOperation(new FileWriteOperation(id++, position, src));
}
} }
private void checkError() throws IOException { private void checkError() throws IOException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论