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

Page store improvements.

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