提交 9ab2a6b4 authored 作者: Thomas Mueller's avatar Thomas Mueller

MVStore: store the file header also at the end of each chunk, which means even…

MVStore: store the file header also at the end of each chunk, which means even less write operations
上级 249d5f2c
...@@ -7,9 +7,10 @@ package org.h2.test.store; ...@@ -7,9 +7,10 @@ package org.h2.test.store;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
...@@ -99,7 +100,8 @@ public class TestConcurrent extends TestMVStore { ...@@ -99,7 +100,8 @@ public class TestConcurrent extends TestMVStore {
} }
private void testConcurrentOnlineBackup() throws Exception { private void testConcurrentOnlineBackup() throws Exception {
String fileName = getBaseDir() + "/onlineBackup.h3"; // need to use NIO because we mix absolute and relative operations
String fileName = "nio:" + getBaseDir() + "/onlineBackup.h3";
String fileNameRestore = getBaseDir() + "/onlineRestore.h3"; String fileNameRestore = getBaseDir() + "/onlineRestore.h3";
final MVStore s = openStore(fileName); final MVStore s = openStore(fileName);
final MVMap<Integer, byte[]> map = s.openMap("test"); final MVMap<Integer, byte[]> map = s.openMap("test");
...@@ -129,7 +131,7 @@ public class TestConcurrent extends TestMVStore { ...@@ -129,7 +131,7 @@ public class TestConcurrent extends TestMVStore {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
// System.out.println("test " + i); // System.out.println("test " + i);
s.setReuseSpace(false); s.setReuseSpace(false);
byte[] buff = readFileSlowly(fileName, s.getFile().size()); byte[] buff = readFileSlowly(s.getFile(), s.getFile().size());
s.setReuseSpace(true); s.setReuseSpace(true);
FileOutputStream out = new FileOutputStream(fileNameRestore); FileOutputStream out = new FileOutputStream(fileNameRestore);
out.write(buff); out.write(buff);
...@@ -146,8 +148,13 @@ public class TestConcurrent extends TestMVStore { ...@@ -146,8 +148,13 @@ public class TestConcurrent extends TestMVStore {
s.close(); s.close();
} }
private static byte[] readFileSlowly(String fileName, long length) throws Exception { private static byte[] readFileSlowly(FileChannel file, long length) throws Exception {
InputStream in = new BufferedInputStream(new FileInputStream(fileName)); file.position(0);
InputStream in = new BufferedInputStream(Channels.newInputStream(file)) {
public void close() {
// don't close
}
};
ByteArrayOutputStream buff = new ByteArrayOutputStream(); ByteArrayOutputStream buff = new ByteArrayOutputStream();
for (int j = 0; j < length; j++) { for (int j = 0; j < length; j++) {
int x = in.read(); int x = in.read();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论