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

Page store bugfixes.

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