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

Page store bugfixes.

上级 fa1a87b4
......@@ -53,7 +53,7 @@ public class PageBtreeIndex extends PageIndex {
store.addMeta(this, session);
PageBtreeLeaf root = PageBtreeLeaf.create(this, rootPageId, PageBtree.ROOT);
store.logUndo(root, null);
store.updateRecord(root);
store.update(root);
} else {
rootPageId = store.getRootPageId(id);
PageBtree root = getPage(rootPageId);
......@@ -95,9 +95,9 @@ public class PageBtreeIndex extends PageIndex {
PageBtreeNode newRoot = PageBtreeNode.create(this, rootPageId, PageBtree.ROOT);
store.logUndo(newRoot, null);
newRoot.init(page1, pivot, page2);
store.updateRecord(page1);
store.updateRecord(page2);
store.updateRecord(newRoot);
store.update(page1);
store.update(page2);
store.update(newRoot);
root = newRoot;
}
rowCount++;
......@@ -131,7 +131,7 @@ public class PageBtreeIndex extends PageIndex {
PageBtreeLeaf empty = PageBtreeLeaf.create(this, id, PageBtree.ROOT);
// could have been created before, but never committed
store.logUndo(empty, null);
store.updateRecord(empty);
store.update(empty);
return empty;
}
return p;
......@@ -226,7 +226,7 @@ public class PageBtreeIndex extends PageIndex {
trace.debug("remove");
}
removeAllRows();
store.freePage(rootPageId, false, null);
store.free(rootPageId, true);
store.removeMeta(this, session);
}
......@@ -247,7 +247,7 @@ public class PageBtreeIndex extends PageIndex {
root.freeChildren();
root = PageBtreeLeaf.create(this, rootPageId, PageBtree.ROOT);
store.removeRecord(rootPageId);
store.updateRecord(root);
store.update(root);
rowCount = 0;
}
......
......@@ -147,7 +147,7 @@ public class PageBtreeLeaf extends PageBtree {
newRows[x] = row;
offsets = newOffsets;
rows = newRows;
index.getPageStore().updateRecord(this);
index.getPageStore().update(this);
return -1;
}
......@@ -202,13 +202,13 @@ public class PageBtreeLeaf extends PageBtree {
if (index.compareRows(row, delete) != 0 || delete.getKey() != row.getKey()) {
throw Message.getSQLException(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1, index.getSQL() + ": " + row);
}
index.getPageStore().logUndo(this, data);
if (entryCount == 1) {
// the page is now empty
return row;
}
index.getPageStore().logUndo(this, data);
removeRow(at);
index.getPageStore().updateRecord(this);
index.getPageStore().update(this);
if (at == entryCount) {
// the last row changed
return getRow(at - 1);
......@@ -327,14 +327,14 @@ public class PageBtreeLeaf extends PageBtree {
p2.onlyPosition = onlyPosition;
p2.parentPageId = parentPageId;
p2.start = start;
store.updateRecord(p2);
store.update(p2);
if (parentPageId == ROOT) {
index.setRootPageId(session, newPos);
} else {
PageBtreeNode p = (PageBtreeNode) store.getPage(parentPageId);
p.moveChild(getPos(), newPos);
}
store.freePage(getPos(), true, data);
store.free(getPos(), true);
}
}
......@@ -203,9 +203,9 @@ public class PageBtreeNode extends PageBtree {
PageBtree page2 = page.split(splitPoint);
readAllRows();
addChild(x, page2.getPos(), pivot);
index.getPageStore().updateRecord(page);
index.getPageStore().updateRecord(page2);
index.getPageStore().updateRecord(this);
index.getPageStore().update(page);
index.getPageStore().update(page2);
index.getPageStore().update(this);
}
updateRowCount(1);
written = false;
......@@ -247,7 +247,7 @@ public class PageBtreeNode extends PageBtree {
for (int child : childPageIds) {
PageBtree p = index.getPage(child);
p.setParentPageId(getPos());
index.getPageStore().updateRecord(p);
index.getPageStore().update(p);
}
}
......@@ -311,7 +311,7 @@ public class PageBtreeNode extends PageBtree {
return null;
} else if (last == row) {
// this child is now empty
index.getPageStore().freePage(page.getPos(), true, page.data);
index.getPageStore().free(page.getPos(), true);
if (entryCount < 1) {
// no more children - this page is empty as well
return row;
......@@ -323,7 +323,7 @@ public class PageBtreeNode extends PageBtree {
last = null;
}
removeChild(at);
index.getPageStore().updateRecord(this);
index.getPageStore().update(this);
return last;
}
// the last row is in the last child
......@@ -339,7 +339,7 @@ public class PageBtreeNode extends PageBtree {
int temp = childPageIds[at];
childPageIds[at] = childPageIds[at + 1];
childPageIds[at + 1] = temp;
index.getPageStore().updateRecord(this);
index.getPageStore().update(this);
return null;
}
......@@ -408,7 +408,7 @@ public class PageBtreeNode extends PageBtree {
for (int i = 0; i <= entryCount; i++) {
int childPageId = childPageIds[i];
PageBtree child = index.getPage(childPageId);
index.getPageStore().freePage(childPageId, false, null);
index.getPageStore().free(childPageId, false);
child.freeChildren();
}
}
......@@ -516,7 +516,7 @@ public class PageBtreeNode extends PageBtree {
p2.onlyPosition = onlyPosition;
p2.parentPageId = parentPageId;
p2.start = start;
store.updateRecord(p2);
store.update(p2);
if (parentPageId == ROOT) {
index.setRootPageId(session, newPos);
} else {
......@@ -526,9 +526,9 @@ public class PageBtreeNode extends PageBtree {
for (int i = 0; i < childPageIds.length; i++) {
PageBtree p = (PageBtree) store.getPage(childPageIds[i]);
p.setParentPageId(newPos);
store.updateRecord(p);
store.update(p);
}
store.freePage(getPos(), true, data);
store.free(getPos(), true);
}
/**
......@@ -543,7 +543,7 @@ public class PageBtreeNode extends PageBtree {
index.getPageStore().logUndo(this, data);
written = false;
childPageIds[i] = newPos;
index.getPageStore().updateRecord(this);
index.getPageStore().update(this);
return;
}
}
......
......@@ -65,7 +65,7 @@ public class PageDataIndex extends PageIndex implements RowIndex {
rootPageId = store.allocatePage();
store.addMeta(this, session);
PageDataLeaf root = PageDataLeaf.create(this, rootPageId, PageData.ROOT);
store.updateRecord(root);
store.update(root);
} else {
rootPageId = store.getRootPageId(id);
PageData root = getPage(rootPageId, 0);
......@@ -161,9 +161,9 @@ public class PageDataIndex extends PageIndex implements RowIndex {
page2.setParentPageId(rootPageId);
PageDataNode newRoot = PageDataNode.create(this, rootPageId, PageData.ROOT);
newRoot.init(page1, pivot, page2);
store.updateRecord(page1);
store.updateRecord(page2);
store.updateRecord(newRoot);
store.update(page1);
store.update(page2);
store.update(newRoot);
root = newRoot;
}
row.setDeleted(false);
......@@ -205,7 +205,7 @@ public class PageDataIndex extends PageIndex implements RowIndex {
PageDataLeaf empty = PageDataLeaf.create(this, id, parent);
// could have been created before, but never committed
store.logUndo(empty, null);
store.updateRecord(empty);
store.update(empty);
return empty;
}
if (p.index.rootPageId != rootPageId) {
......@@ -325,7 +325,7 @@ public class PageDataIndex extends PageIndex implements RowIndex {
trace.debug("remove");
}
removeAllRows();
store.freePage(rootPageId, false, null);
store.free(rootPageId, true);
store.removeMeta(this, session);
}
......@@ -349,7 +349,7 @@ public class PageDataIndex extends PageIndex implements RowIndex {
root.freeChildren();
root = PageDataLeaf.create(this, rootPageId, PageData.ROOT);
store.removeRecord(rootPageId);
store.updateRecord(root);
store.update(root);
rowCount = 0;
lastKey = 0;
}
......
......@@ -198,7 +198,7 @@ public class PageDataLeaf extends PageData {
offsets = newOffsets;
keys = newKeys;
rows = newRows;
index.getPageStore().updateRecord(this);
index.getPageStore().update(this);
if (offset < start) {
if (entryCount > 1) {
Message.throwInternalError();
......@@ -234,7 +234,7 @@ public class PageDataLeaf extends PageData {
next = index.getPageStore().allocatePage();
}
PageDataOverflow overflow = PageDataOverflow.create(index.getPageStore(), page, type, previous, next, all, dataOffset, size);
index.getPageStore().updateRecord(overflow);
index.getPageStore().update(overflow);
dataOffset += size;
remaining -= size;
previous = page;
......@@ -365,7 +365,7 @@ public class PageDataLeaf extends PageData {
}
PageDataOverflow overflow = index.getPageOverflow(firstOverflowPageId);
overflow.setParentPageId(getPos());
index.getPageStore().updateRecord(overflow);
index.getPageStore().update(overflow);
}
boolean remove(long key) throws SQLException {
......@@ -379,7 +379,7 @@ public class PageDataLeaf extends PageData {
return true;
}
removeRow(i);
index.getPageStore().updateRecord(this);
index.getPageStore().update(this);
return false;
}
......@@ -389,7 +389,7 @@ public class PageDataLeaf extends PageData {
int next = firstOverflowPageId;
do {
PageDataOverflow page = index.getPageOverflow(next);
store.freePage(next, false, null);
store.free(next, false);
next = page.getNextOverflow();
} while (next != 0);
}
......@@ -499,8 +499,8 @@ public class PageDataLeaf extends PageData {
p2.remapChildren();
p2.write();
p2.data.truncate(index.getPageStore().getPageSize());
store.updateRecord(p2);
store.freePage(getPos(), true, data);
store.update(p2);
store.free(getPos(), true);
if (parentPageId == ROOT) {
index.setRootPageId(session, newPos);
} else {
......@@ -516,7 +516,7 @@ public class PageDataLeaf extends PageData {
writeHead();
data.writeInt(firstOverflowPageId);
}
index.getPageStore().updateRecord(this);
index.getPageStore().update(this);
}
public int getMemorySize() {
......
......@@ -149,10 +149,10 @@ public class PageDataNode extends PageData {
}
long pivot = splitPoint == 0 ? row.getKey() : page.getKey(splitPoint - 1);
PageData page2 = page.split(splitPoint);
index.getPageStore().updateRecord(page);
index.getPageStore().updateRecord(page2);
index.getPageStore().update(page);
index.getPageStore().update(page2);
addChild(x, page2.getPos(), pivot);
index.getPageStore().updateRecord(this);
index.getPageStore().update(this);
}
updateRowCount(1);
return -1;
......@@ -168,7 +168,7 @@ public class PageDataNode extends PageData {
if (written) {
writeHead();
}
index.getPageStore().updateRecord(this);
index.getPageStore().update(this);
}
}
......@@ -198,7 +198,7 @@ public class PageDataNode extends PageData {
for (int child : childPageIds) {
PageData p = index.getPage(child, -1);
p.setParentPageId(getPos());
index.getPageStore().updateRecord(p);
index.getPageStore().update(p);
}
}
......@@ -251,19 +251,20 @@ public class PageDataNode extends PageData {
// TODO maybe implement merge
PageData page = index.getPage(childPageIds[at], getPos());
boolean empty = page.remove(key);
index.getPageStore().logUndo(this, data);
updateRowCount(-1);
if (!empty) {
// the first row didn't change - nothing to do
return false;
}
// this child is now empty
index.getPageStore().freePage(page.getPos(), true, page.data);
index.getPageStore().free(page.getPos(), true);
if (entryCount < 1) {
// no more children - this page is empty as well
return true;
}
removeChild(at);
index.getPageStore().updateRecord(this);
index.getPageStore().update(this);
return false;
}
......@@ -271,7 +272,7 @@ public class PageDataNode extends PageData {
for (int i = 0; i <= entryCount; i++) {
int childPageId = childPageIds[i];
PageData child = index.getPage(childPageId, getPos());
index.getPageStore().freePage(childPageId, false, null);
index.getPageStore().free(childPageId, false);
child.freeChildren();
}
}
......@@ -305,7 +306,7 @@ public class PageDataNode extends PageData {
if (written) {
writeHead();
}
index.getPageStore().updateRecord(this);
index.getPageStore().update(this);
}
}
......@@ -393,7 +394,7 @@ public class PageDataNode extends PageData {
p2.keys = keys;
p2.entryCount = entryCount;
p2.length = length;
store.updateRecord(p2);
store.update(p2);
if (parentPageId == ROOT) {
index.setRootPageId(session, newPos);
} else {
......@@ -403,9 +404,9 @@ public class PageDataNode extends PageData {
for (int i = 0; i < childPageIds.length; i++) {
PageData p = (PageData) store.getPage(childPageIds[i]);
p.setParentPageId(newPos);
store.updateRecord(p);
store.update(p);
}
store.freePage(getPos(), true, data);
store.free(getPos(), true);
}
/**
......@@ -420,7 +421,7 @@ public class PageDataNode extends PageData {
index.getPageStore().logUndo(this, data);
written = false;
childPageIds[i] = newPos;
index.getPageStore().updateRecord(this);
index.getPageStore().update(this);
return;
}
}
......
......@@ -216,11 +216,11 @@ public class PageDataOverflow extends Page {
public void moveTo(Session session, int newPos) throws SQLException {
store.logUndo(this, data);
PageDataOverflow p2 = PageDataOverflow.create(store, newPos, type, parentPageId, nextPage, data, start, size);
store.updateRecord(p2);
store.update(p2);
if (nextPage != 0) {
PageDataOverflow p3 = (PageDataOverflow) store.getPage(nextPage);
p3.setParentPageId(newPos);
store.updateRecord(p3);
store.update(p3);
}
Page p = store.getPage(parentPageId);
if (p == null) {
......@@ -233,8 +233,8 @@ public class PageDataOverflow extends Page {
PageDataLeaf p1 = (PageDataLeaf) p;
p1.setOverflow(newPos);
}
store.updateRecord(p);
store.freePage(getPos(), true, data);
store.update(p);
store.free(getPos(), true);
}
private void setNext(int nextPage) throws SQLException {
......
......@@ -88,7 +88,7 @@ public class PageFreeList extends Page {
} else {
store.logUndo(this, data);
used.set(free);
store.updateRecord(this);
store.update(this);
return free + getPos();
}
}
......@@ -121,7 +121,7 @@ public class PageFreeList extends Page {
if (idx >= 0 && !used.get(idx)) {
store.logUndo(this, data);
used.set(idx);
store.updateRecord(this);
store.update(this);
}
return pageId;
}
......@@ -135,7 +135,7 @@ public class PageFreeList extends Page {
full = false;
store.logUndo(this, data);
used.clear(pageId - getPos());
store.updateRecord(this);
store.update(this);
}
/**
......@@ -197,7 +197,7 @@ public class PageFreeList extends Page {
public void moveTo(Session session, int newPos) throws SQLException {
// the old data does not need to be copied, as free-list pages
// at the end of the file are not required
store.freePage(getPos(), true, data);
store.free(getPos(), false);
}
public String toString() {
......
......@@ -198,7 +198,7 @@ public class PageLog {
while (firstTrunkPage != 0) {
PageStreamTrunk t = (PageStreamTrunk) store.getPage(firstTrunkPage);
if (t == null) {
store.freePage(firstTrunkPage, false, null);
store.free(firstTrunkPage, false);
// EOF
break;
}
......@@ -352,7 +352,7 @@ public class PageLog {
int pageId = in.readVarInt();
if (stage == RECOVERY_STAGE_REDO) {
if (!usedLogPages.get(pageId)) {
store.freePage(pageId, false, null);
store.free(pageId, false);
}
}
}
......
......@@ -717,27 +717,27 @@ public class PageStore implements CacheWriter {
}
/**
* Update a record.
* Update a page.
*
* @param record the record
* @param page the page
*/
public void updateRecord(Record record) throws SQLException {
public void update(Page page) throws SQLException {
synchronized (database) {
if (trace.isDebugEnabled()) {
if (!record.isChanged()) {
trace.debug("updateRecord " + record.toString());
if (!page.isChanged()) {
trace.debug("updateRecord " + page.toString());
}
}
checkOpen();
database.checkWritingAllowed();
record.setChanged(true);
int pos = record.getPos();
page.setChanged(true);
int pos = page.getPos();
if (SysProperties.CHECK && !recoveryRunning) {
// ensure the undo entry is already written
log.addUndo(pos, null);
}
allocatePage(pos);
cache.update(pos, record);
cache.update(pos, page);
}
}
......@@ -854,29 +854,22 @@ public class PageStore implements CacheWriter {
/**
* Add a page to the free list.
*
* @param pageId the page id
* @param logUndo if an undo entry need to be logged
* @param old the old data (if known)
* @param page the page
* @param undo if the undo record must have been written
*/
public void freePage(int pageId, boolean logUndo, Data old) throws SQLException {
public void free(int pageId, boolean undo) throws SQLException {
if (trace.isDebugEnabled()) {
// trace.debug("freePage " + pageId);
}
int todoRemoveOld;
synchronized (database) {
if (SysProperties.CHECK && !recoveryRunning && logUndo) {
cache.remove(pageId);
if (SysProperties.CHECK && !recoveryRunning && undo) {
// ensure the undo entry is already written
log.addUndo(pageId, null);
}
cache.remove(pageId);
freePage(pageId);
if (recoveryRunning) {
writePage(pageId, createData());
} else if (logUndo) {
if (old == null) {
old = readPage(pageId);
}
log.addUndo(pageId, old);
}
}
}
......
......@@ -168,11 +168,11 @@ public class PageStreamTrunk extends Page {
* @return the number of pages freed
*/
int free() throws SQLException {
store.freePage(getPos(), false, null);
store.free(getPos(), false);
int freed = 1;
for (int i = 0; i < pageCount; i++) {
int page = pageIds[i];
store.freePage(page, false, null);
store.free(page, false);
freed++;
}
return freed;
......@@ -201,7 +201,7 @@ public class PageStreamTrunk extends Page {
break;
}
}
store.updateRecord(this);
store.update(this);
}
public void moveTo(Session session, int newPos) {
......
......@@ -141,6 +141,11 @@ public class WriterThread implements Runnable {
if (traceSystem != null) {
traceSystem.getTrace(Trace.LOG).error("flush", e);
}
} catch (RuntimeException e) {
TraceSystem traceSystem = database.getTraceSystem();
if (traceSystem != null) {
traceSystem.getTrace(Trace.LOG).error("flush", e);
}
}
// TODO log writer: could also flush the dirty cache when there is
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论