提交 74d34875 authored 作者: Thomas Mueller's avatar Thomas Mueller

Page store: more internal checks

上级 00a4016d
......@@ -148,9 +148,10 @@ abstract class PageData extends Page {
* @param id the new page id
*/
void setPageId(int id) throws SQLException {
int old = getPos();
index.getPageStore().removeRecord(getPos());
setPos(id);
remapChildren();
remapChildren(old);
}
/**
......@@ -182,8 +183,10 @@ abstract class PageData extends Page {
/**
* Update the parent id of all children.
*
* @param old the previous position
*/
abstract void remapChildren() throws SQLException;
abstract void remapChildren(int old) throws SQLException;
/**
* Remove a row.
......
......@@ -49,6 +49,7 @@ public class PageDataIndex extends PageIndex implements RowIndex {
public PageDataIndex(TableData table, int id, IndexColumn[] columns, IndexType indexType, int headPos, Session session) throws SQLException {
initBaseIndex(table, id, table.getName() + "_TABLE_SCAN", columns, indexType);
// trace = database.getTrace(Trace.PAGE_STORE + "_di");
// trace.setLevel(TraceSystem.DEBUG);
if (database.isMultiVersion()) {
sessionRowCount = New.hashMap();
......@@ -73,7 +74,7 @@ public class PageDataIndex extends PageIndex implements RowIndex {
rowCount = root.getRowCount();
}
if (trace.isDebugEnabled()) {
trace.debug("opened " + getName() + " rows:" + rowCount);
trace.debug(this + " opened rows:" + rowCount);
}
table.setRowCount(rowCount);
fastDuplicateKeyException = super.getDuplicateKeyException();
......@@ -99,9 +100,6 @@ public class PageDataIndex extends PageIndex implements RowIndex {
retry = true;
}
}
if (trace.isDebugEnabled()) {
trace.debug("add table:" + table.getId() + " " + row);
}
if (tableData.getContainsLargeObject()) {
for (int i = 0; i < row.getColumnCount(); i++) {
Value v = row.getValue(i);
......@@ -149,7 +147,7 @@ public class PageDataIndex extends PageIndex implements RowIndex {
break;
}
if (trace.isDebugEnabled()) {
trace.debug("split " + splitPoint);
trace.debug(this + " split");
}
long pivot = splitPoint == 0 ? row.getKey() : root.getKey(splitPoint - 1);
PageData page1 = root;
......@@ -208,9 +206,6 @@ public class PageDataIndex extends PageIndex implements RowIndex {
store.update(empty);
return empty;
}
if (p.index.rootPageId != rootPageId) {
throw Message.throwInternalError("Wrong index: " + p.index.getName() + ":" + p.index.rootPageId + " " + getName() + ":" + rootPageId);
}
if (parent != -1) {
if (p.getParentPageId() != parent) {
throw Message.throwInternalError(p + " parent " + p.getParentPageId() + " expected " + parent);
......@@ -280,9 +275,6 @@ public class PageDataIndex extends PageIndex implements RowIndex {
}
public void remove(Session session, Row row) throws SQLException {
if (trace.isDebugEnabled()) {
trace.debug("remove " + row.getKey());
}
if (tableData.getContainsLargeObject()) {
for (int i = 0; i < row.getColumnCount(); i++) {
Value v = row.getValue(i);
......@@ -322,7 +314,7 @@ public class PageDataIndex extends PageIndex implements RowIndex {
public void remove(Session session) throws SQLException {
if (trace.isDebugEnabled()) {
trace.debug("remove");
trace.debug(this + " remove");
}
removeAllRows();
store.free(rootPageId, true);
......@@ -331,7 +323,7 @@ public class PageDataIndex extends PageIndex implements RowIndex {
public void truncate(Session session) throws SQLException {
if (trace.isDebugEnabled()) {
trace.debug("truncate");
trace.debug(this + " truncate");
}
store.logTruncate(session, tableData.getId());
removeAllRows();
......@@ -421,7 +413,7 @@ public class PageDataIndex extends PageIndex implements RowIndex {
public void close(Session session) throws SQLException {
if (trace.isDebugEnabled()) {
trace.debug("close");
trace.debug(this + " close");
}
if (delta != null) {
delta.clear();
......@@ -488,4 +480,8 @@ public class PageDataIndex extends PageIndex implements RowIndex {
return memorySizePerPage;
}
public String toString() {
return getName();
}
}
......@@ -368,7 +368,7 @@ public class PageDataLeaf extends PageData {
return this;
}
protected void remapChildren() throws SQLException {
protected void remapChildren(int old) throws SQLException {
if (firstOverflowPageId == 0) {
return;
}
......@@ -503,9 +503,8 @@ public class PageDataLeaf extends PageData {
}
p2.entryCount = entryCount;
p2.offsets = offsets;
p2.parentPageId = parentPageId;
p2.start = start;
p2.remapChildren();
p2.remapChildren(getPos());
p2.write();
p2.data.truncate(index.getPageStore().getPageSize());
store.update(p2);
......
......@@ -190,13 +190,13 @@ public class PageDataNode extends PageData {
removeChild(splitPoint - 1);
childPageIds[splitPoint - 1] = lastChild;
p2.childPageIds[0] = firstChild;
p2.remapChildren();
p2.remapChildren(getPos());
return p2;
}
protected void remapChildren() throws SQLException {
protected void remapChildren(int old) throws SQLException {
for (int child : childPageIds) {
PageData p = index.getPage(child, -1);
PageData p = index.getPage(child, old);
p.setParentPageId(getPos());
index.getPageStore().update(p);
}
......
......@@ -873,7 +873,7 @@ public class Recover extends Tool implements DataHandler {
boolean last = (type & Page.FLAG_LAST) != 0;
type &= ~Page.FLAG_LAST;
if (!PageStore.checksumTest(s.getBytes(), page, pageSize)) {
writer.println("-- ERROR: page " + page + " checksum mismatch");
writer.println("-- ERROR: page " + page + " checksum mismatch type: " + type);
}
s.readShortInt();
switch (type) {
......@@ -1166,12 +1166,12 @@ public class Recover extends Tool implements DataHandler {
store.seek((long) nextPage * pageSize);
store.readFully(page.getBytes(), 0, pageSize);
page.reset();
if (!PageStore.checksumTest(page.getBytes(), nextPage, pageSize)) {
int t = page.readByte();
if (t != 0 && !PageStore.checksumTest(page.getBytes(), nextPage, pageSize)) {
writer.println("-- ERROR: checksum mismatch page: " +nextPage);
endOfFile = true;
return;
}
int t = page.readByte();
page.readShortInt();
int p = page.readInt();
int k = page.readInt();
......@@ -1199,14 +1199,12 @@ public class Recover extends Tool implements DataHandler {
int entryCount = s.readShortInt();
int[] children = new int[entryCount + 1];
int[] offsets = new int[entryCount];
int rightmost = s.readInt();
checkParent(writer, pageId, rightmost);
children[entryCount] = rightmost;
children[entryCount] = s.readInt();
checkParent(writer, pageId, children, entryCount);
int empty = Integer.MAX_VALUE;
for (int i = 0; i < entryCount; i++) {
int child = s.readInt();
checkParent(writer, pageId, child);
children[i] = child;
children[i] = s.readInt();
checkParent(writer, pageId, children, i);
int off = s.readShortInt();
empty = Math.min(off, empty);
offsets[i] = off;
......@@ -1292,24 +1290,23 @@ public class Recover extends Tool implements DataHandler {
}
}
private void checkParent(PrintWriter writer, long pageId, long child) {
private void checkParent(PrintWriter writer, long pageId, int[] children, int index) {
int child = children[index];
if (child < 0 || child >= parents.length) {
writer.println("-- ERROR [" + pageId + "] child: " + child + " page count: " + parents.length);
} else if (parents[(int) child] != pageId) {
writer.println("-- ERROR [" + pageId + "] expected child: " + child + " got: " + parents[(int) child]);
writer.println("-- ERROR [" + pageId + "] child[" + index + "]: " + child + " >= page count: " + parents.length);
} else if (parents[child] != pageId) {
writer.println("-- ERROR [" + pageId + "] child[" + index + "]: " + child + " parent: " + parents[child]);
}
}
private void dumpPageDataNode(PrintWriter writer, Data s, long pageId, int entryCount) {
int[] children = new int[entryCount + 1];
long[] keys = new long[entryCount];
int child = s.readInt();
children[entryCount] = child;
checkParent(writer, pageId, child);
children[entryCount] = s.readInt();
checkParent(writer, pageId, children, entryCount);
for (int i = 0; i < entryCount; i++) {
child = s.readInt();
children[i] = child;
checkParent(writer, pageId, child);
children[i] = s.readInt();
checkParent(writer, pageId, children, i);
keys[i] = s.readVarLong();
}
if (!trace) {
......@@ -1347,7 +1344,7 @@ public class Recover extends Tool implements DataHandler {
s.setPos(pageSize);
long parent = pageId;
while (true) {
checkParent(writer, parent, next);
checkParent(writer, parent, new int[]{(int) next}, 0);
parent = next;
store.seek(pageSize * next);
store.readFully(s2.getBytes(), 0, pageSize);
......
......@@ -297,6 +297,8 @@ java org.h2.test.TestAll timer
/*
check freelist undo recursion
mvcc merge problem
System.setProperty("h2.optimizeInList", "true");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论