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

Page store improvements.

上级 f90c7a7f
......@@ -19,7 +19,7 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul><li>Possibility to set a vendor id in Constants.java, so that unofficial builds are distinguishable
from official releases
from official releases.
</li></ul>
<h2>Version 1.1.119 (2009-09-26)</h2>
......
......@@ -459,6 +459,7 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>Improve concurrency for in-memory database operations.
</li><li>Issue 122: Support for connection aliases for remote tcp connections.
</li><li>Fast scrambling (strong encryption doesn't help if the password is included in the application).
</li><li>Faster startup if there is a large number of LOB files.
</li></ul>
<h2>Not Planned</h2>
......
......@@ -86,6 +86,7 @@ public class PageBtreeLeaf extends PageBtree {
offsets[i] = data.readShortInt();
}
start = data.length();
written = true;
}
int addRowTry(SearchRow row) throws SQLException {
......
......@@ -107,6 +107,7 @@ public class PageBtreeNode extends PageBtree {
}
check();
start = data.length();
written = true;
}
/**
......
......@@ -17,6 +17,11 @@ import org.h2.store.Page;
*/
abstract class PageData extends Page {
/**
* The position of the parent page id.
*/
static final int START_PARENT = 3;
/**
* This is a root page.
*/
......@@ -143,7 +148,6 @@ abstract class PageData extends Page {
* @param id the new page id
*/
void setPageId(int id) throws SQLException {
written = false;
index.getPageStore().removeRecord(getPos());
setPos(id);
remapChildren();
......@@ -169,8 +173,10 @@ abstract class PageData extends Page {
* @param id the new parent page id
*/
void setParentPageId(int id) {
written = false;
parentPageId = id;
if (written) {
data.setInt(START_PARENT, parentPageId);
}
}
/**
......
......@@ -10,6 +10,7 @@ import java.lang.ref.SoftReference;
import java.sql.SQLException;
import java.util.Arrays;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.result.Row;
......@@ -34,11 +35,6 @@ import org.h2.store.PageStore;
*/
public class PageDataLeaf extends PageData {
/**
* The start of the data in the last overflow page.
*/
static final int START_PARENT = 3;
/**
* The row offsets.
*/
......@@ -132,6 +128,7 @@ public class PageDataLeaf extends PageData {
offsets[i] = data.readShortInt();
}
start = data.length();
written = true;
}
private int getRowLength(Row row) throws SQLException {
......@@ -423,6 +420,7 @@ public class PageDataLeaf extends PageData {
}
private void writeHead() {
data.reset();
int type;
if (firstOverflowPageId == 0) {
type = Page.TYPE_DATA_LEAF | Page.FLAG_LAST;
......@@ -431,6 +429,11 @@ public class PageDataLeaf extends PageData {
}
data.writeByte((byte) type);
data.writeShortInt(0);
if (SysProperties.CHECK2) {
if (data.length() != START_PARENT) {
Message.throwInternalError();
}
}
data.writeInt(parentPageId);
data.writeVarInt(index.getId());
data.writeVarInt(columnCount);
......@@ -441,8 +444,10 @@ public class PageDataLeaf extends PageData {
if (written) {
return;
}
if (SysProperties.CHECK && firstOverflowPageId != 0 && rows[0] == null) {
Message.throwInternalError(toString());
}
readAllRows();
data.reset();
writeHead();
if (firstOverflowPageId != 0) {
data.writeInt(firstOverflowPageId);
......@@ -478,12 +483,17 @@ public class PageDataLeaf extends PageData {
p2.firstOverflowPageId = firstOverflowPageId;
p2.rowRef = rowRef;
p2.rows = rows;
if (firstOverflowPageId != 0) {
p2.rows[0] = getRowAt(0);
}
p2.entryCount = entryCount;
p2.offsets = offsets;
p2.parentPageId = parentPageId;
p2.start = start;
store.updateRecord(p2, false, null);
p2.remapChildren();
p2.write();
p2.data.truncate(index.getPageStore().getPageSize());
store.freePage(getPos(), true, data);
if (parentPageId == ROOT) {
index.setRootPageId(session, newPos);
......@@ -494,8 +504,11 @@ public class PageDataLeaf extends PageData {
}
void setOverflow(int overflow) throws SQLException {
written = false;
this.firstOverflowPageId = overflow;
firstOverflowPageId = overflow;
if (written) {
writeHead();
data.writeInt(firstOverflowPageId);
}
index.getPageStore().updateRecord(this, true, data);
}
......
......@@ -9,6 +9,7 @@ package org.h2.index;
import java.sql.SQLException;
import java.util.Arrays;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.result.Row;
......@@ -106,6 +107,7 @@ public class PageDataNode extends PageData {
}
length = data.length();
check();
written = true;
}
private void addChild(int x, int childPageId, long key) {
......@@ -159,6 +161,9 @@ public class PageDataNode extends PageData {
}
if (rowCountStored != UNKNOWN_ROWCOUNT) {
rowCountStored = UNKNOWN_ROWCOUNT;
if (written) {
writeHead();
}
index.getPageStore().updateRecord(this, true, data);
}
}
......@@ -292,6 +297,9 @@ public class PageDataNode extends PageData {
this.rowCount = rowCount;
if (rowCountStored != rowCount) {
rowCountStored = rowCount;
if (written) {
writeHead();
}
index.getPageStore().updateRecord(this, true, data);
}
}
......@@ -314,8 +322,14 @@ public class PageDataNode extends PageData {
}
private void writeHead() {
data.reset();
data.writeByte((byte) Page.TYPE_DATA_NODE);
data.writeShortInt(0);
if (SysProperties.CHECK2) {
if (data.length() != START_PARENT) {
Message.throwInternalError();
}
}
data.writeInt(parentPageId);
data.writeVarInt(index.getId());
data.writeInt(rowCountStored);
......@@ -327,7 +341,6 @@ public class PageDataNode extends PageData {
return;
}
check();
data.reset();
writeHead();
data.writeInt(childPageIds[entryCount]);
for (int i = 0; i < entryCount; i++) {
......
......@@ -292,8 +292,6 @@ java org.h2.test.TestAll timer
/*
slow startup with a large number of lob files
mvcc merge problem
System.setProperty("h2.optimizeInList", "true");
......@@ -307,7 +305,7 @@ out of memory in tests: analyze heap dump
-------------
create a short documentation
integrate the short documentation, but where?
documentation: rolling review at roadmap.html: done
......
......@@ -136,7 +136,7 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
conn.createStatement().execute("drop table employee if exists");
conn.createStatement().execute("create table employee(id int primary key, name varchar, salary int)");
conn.close();
int len = this.getSize(200, 1000);
int len = getSize(200, 1000);
Thread[] threads = new Thread[len];
for (int i = 0; i < len; i++) {
threads[i] = new Thread() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论