提交 e51f5f4c authored 作者: Thomas Mueller's avatar Thomas Mueller

Page store bugfixes

上级 76011ce9
......@@ -453,6 +453,7 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
See PostgreSQL.
</li><li>Add option to enable TCP_NODELAY using Socket.setTcpNoDelay(true).
</li><li>Maybe disallow = within database names (jdbc:h2:mem:MODE=DB2 means database name MODE=DB2).
</li><li>Fast alter table add column.
</li></ul>
<h2>Not Planned</h2>
......
......@@ -197,4 +197,8 @@ public class PageFreeList extends Page {
store.freePage(getPos(), true, data);
}
public String toString() {
return "page [" + getPos() + "] freeList" + (full ? "full" : "");
}
}
......@@ -1004,6 +1004,7 @@ public class PageStore implements CacheWriter {
writeBack();
// clear the cache because it contains pages with closed indexes
cache.clear();
freeLists.clear();
if (setReadOnly) {
database.setReadOnly(true);
}
......
......@@ -299,7 +299,9 @@ java org.h2.test.TestAll timer
/*
test cacheTQ
test linked table cache.patch
mvcc merge problem
javadoc: constructor parameters are not verified (PageOutputStream)
......@@ -426,6 +428,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
diskResult = true;
deleteIndex = true;
traceLevelFile = 3;
cache2Q = true;
throttle = 1;
cipher = "XTEA";
test();
......@@ -434,6 +437,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
diskResult = false;
deleteIndex = false;
traceLevelFile = 1;
cache2Q = false;
throttle = 0;
cipher = null;
test();
......@@ -471,6 +475,9 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
* Run all tests with the current settings.
*/
private void test() throws SQLException {
//if(logMode != 2) return;
System.out.println();
System.out.println("Test " + toString() + " (" + MemoryUtils.getMemoryUsed() + " KB used)");
beforeTest();
......
......@@ -254,7 +254,7 @@ public abstract class TestBase {
if (config.mvcc && url.indexOf("MVCC=") < 0) {
url += ";MVCC=TRUE";
}
if (config.cache2Q) {
if (config.cache2Q && url.indexOf("CACHE_TYPE=") < 0) {
url += ";CACHE_TYPE=TQ";
}
if (config.diskResult && admin) {
......
......@@ -12,12 +12,19 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.Random;
import org.h2.message.Trace;
import org.h2.test.TestBase;
import org.h2.util.Cache;
import org.h2.util.CacheLRU;
import org.h2.util.CacheObject;
import org.h2.util.CacheWriter;
/**
* Tests the cache.
*/
public class TestCache extends TestBase {
public class TestCache extends TestBase implements CacheWriter {
private String out;
/**
* Run just this test.
......@@ -29,11 +36,67 @@ public class TestCache extends TestBase {
}
public void test() throws SQLException {
testCache(false);
testCache(true);
testCacheDb(false);
testCacheDb(true);
}
private void testCache(boolean lru) throws SQLException {
out = "";
Cache c = CacheLRU.getCache(this, lru ? "LRU" : "TQ", 16);
for (int i = 0; i < 20; i++) {
c.put(new Obj(i));
}
assertEquals(lru ? "0 1 2 3 " : "4 5 6 ", out);
}
/**
* A simple cache object
*/
class Obj extends CacheObject {
Obj(int pos) {
setPos(pos);
}
public int getMemorySize() {
return 1024;
}
public boolean canRemove() {
return true;
}
public boolean isChanged() {
return true;
}
public String toString() {
return "[" + getPos() + "]";
}
}
public void flushLog() {
out += "flush ";
}
public Trace getTrace() {
return null;
}
public void writeBack(CacheObject entry) {
out += entry.getPos() + " ";
}
private void testCacheDb(boolean lru) throws SQLException {
if (config.memory) {
return;
}
deleteDb("cache");
Connection conn = getConnection("cache");
Connection conn = getConnection("cache;CACHE_TYPE=" + (lru ? "LRU" : "TQ"));
Statement stat = conn.createStatement();
stat.execute("SET CACHE_SIZE 1024");
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论