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

Various bugfixes and improvements in the page store mechanism (still experimental).

上级 16bdacb2
...@@ -172,6 +172,7 @@ class PageBtreeNode extends PageBtree { ...@@ -172,6 +172,7 @@ class PageBtreeNode extends PageBtree {
p2.onlyPosition = true; p2.onlyPosition = true;
} }
int firstChild = childPageIds[splitPoint]; int firstChild = childPageIds[splitPoint];
readAllRows();
for (int i = splitPoint; i < entryCount;) { for (int i = splitPoint; i < entryCount;) {
p2.addChild(p2.entryCount, childPageIds[splitPoint + 1], rows[splitPoint]); p2.addChild(p2.entryCount, childPageIds[splitPoint + 1], rows[splitPoint]);
removeChild(splitPoint); removeChild(splitPoint);
...@@ -258,7 +259,6 @@ class PageBtreeNode extends PageBtree { ...@@ -258,7 +259,6 @@ class PageBtreeNode extends PageBtree {
// no more children - this page is empty as well // no more children - this page is empty as well
return true; return true;
} }
written = false;
removeChild(at); removeChild(at);
index.getPageStore().updateRecord(this, true, data); index.getPageStore().updateRecord(this, true, data);
return false; return false;
......
...@@ -60,6 +60,7 @@ class PageDataNode extends PageData { ...@@ -60,6 +60,7 @@ class PageDataNode extends PageData {
} }
private void addChild(int x, int childPageId, int key) { private void addChild(int x, int childPageId, int key) {
written = false;
int[] newKeys = new int[entryCount + 1]; int[] newKeys = new int[entryCount + 1];
int[] newChildPageIds = new int[entryCount + 2]; int[] newChildPageIds = new int[entryCount + 2];
if (childPageIds != null) { if (childPageIds != null) {
...@@ -256,6 +257,14 @@ class PageDataNode extends PageData { ...@@ -256,6 +257,14 @@ class PageDataNode extends PageData {
} }
public void write(DataPage buff) throws SQLException { public void write(DataPage buff) throws SQLException {
write();
index.getPageStore().writePage(getPos(), data);
}
private void write() {
if (written) {
return;
}
check(); check();
data.reset(); data.reset();
data.writeInt(parentPageId); data.writeInt(parentPageId);
...@@ -267,10 +276,11 @@ class PageDataNode extends PageData { ...@@ -267,10 +276,11 @@ class PageDataNode extends PageData {
data.writeInt(childPageIds[i]); data.writeInt(childPageIds[i]);
data.writeInt(keys[i]); data.writeInt(keys[i]);
} }
index.getPageStore().writePage(getPos(), data); written = true;
} }
private void removeChild(int i) { private void removeChild(int i) {
written = false;
entryCount--; entryCount--;
if (entryCount < 0) { if (entryCount < 0) {
Message.throwInternalError(); Message.throwInternalError();
......
...@@ -211,7 +211,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex { ...@@ -211,7 +211,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
result.read(); result.read();
if (parent != -1) { if (parent != -1) {
if (result.getParentPageId() != parent) { if (result.getParentPageId() != parent) {
throw Message.throwInternalError(result.getParentPageId() + " " + parent + " " + result); throw Message.throwInternalError(result + " parent " + result.getParentPageId() + " expected " + parent);
} }
} }
return result; return result;
......
...@@ -86,16 +86,18 @@ public class PageInputStream extends InputStream { ...@@ -86,16 +86,18 @@ public class PageInputStream extends InputStream {
if (trunk == null) { if (trunk == null) {
trunk = new PageStreamTrunk(store, trunkNext); trunk = new PageStreamTrunk(store, trunkNext);
trunk.read(); trunk.read();
trunkNext = trunk.getNextTrunk();
} }
int next; int next;
while (true) { while (true) {
next = trunk.getNextPageData(); next = trunk.getNextPageData();
if (dataPage == -1 || dataPage == next) { if (dataPage == -1 || dataPage == next) {
if (next != 0) { if (next != -1) {
break; break;
} }
trunk = new PageStreamTrunk(store, trunkNext); trunk = new PageStreamTrunk(store, trunkNext);
trunk.read(); trunk.read();
trunkNext = trunk.getNextTrunk();
} }
} }
if (trace.isDebugEnabled()) { if (trace.isDebugEnabled()) {
......
...@@ -669,6 +669,8 @@ public class PageStore implements CacheWriter { ...@@ -669,6 +669,8 @@ public class PageStore implements CacheWriter {
synchronized (database) { synchronized (database) {
if (pos >= pageCount) { if (pos >= pageCount) {
throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1, pos + " of " + pageCount); throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1, pos + " of " + pageCount);
} else if (pos < 0) {
throw Message.throwInternalError("negative offset: " + pos);
} }
file.seek((long) pos << pageSizeShift); file.seek((long) pos << pageSizeShift);
file.readFully(page.getBytes(), 0, pageSize); file.readFully(page.getBytes(), 0, pageSize);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论