提交 3b5b3f45 authored 作者: Thomas Mueller's avatar Thomas Mueller

Page store: opening a database sometimes failed if large rows where updated, or…

Page store: opening a database sometimes failed if large rows where updated, or if a table was truncated before.
上级 191c9a39
......@@ -189,6 +189,7 @@ public abstract class PageBtree extends Page {
written = false;
index.getPageStore().removeRecord(getPos());
setPos(id);
index.getPageStore().logUndo(this, null);
remapChildren();
}
......
......@@ -61,7 +61,7 @@ public class PageBtreeLeaf extends PageBtree {
*/
static PageBtreeLeaf create(PageBtreeIndex index, int pageId, int parentPageId) throws SQLException {
PageBtreeLeaf p = new PageBtreeLeaf(index, pageId, index.getPageStore().createData());
index.getPageStore().logUndo(p, p.data);
index.getPageStore().logUndo(p, null);
p.parentPageId = parentPageId;
p.writeHead();
p.start = p.data.length();
......@@ -240,6 +240,7 @@ public class PageBtreeLeaf extends PageBtree {
public void write(DataPage buff) throws SQLException {
write();
index.getPageStore().checkUndo(getPos());
index.getPageStore().writePage(getPos(), data);
}
......
......@@ -74,7 +74,7 @@ public class PageBtreeNode extends PageBtree {
*/
static PageBtreeNode create(PageBtreeIndex index, int pageId, int parentPageId) throws SQLException {
PageBtreeNode p = new PageBtreeNode(index, pageId, index.getPageStore().createData());
index.getPageStore().logUndo(p, p.data);
index.getPageStore().logUndo(p, null);
p.parentPageId = parentPageId;
p.writeHead();
// 4 bytes for the rightmost child page id
......@@ -390,6 +390,7 @@ public class PageBtreeNode extends PageBtree {
public void write(DataPage buff) throws SQLException {
check();
write();
index.getPageStore().checkUndo(getPos());
index.getPageStore().writePage(getPos(), data);
}
......
......@@ -151,6 +151,7 @@ abstract class PageData extends Page {
int old = getPos();
index.getPageStore().removeRecord(getPos());
setPos(id);
index.getPageStore().logUndo(this, null);
remapChildren(old);
}
......
......@@ -19,6 +19,7 @@ import org.h2.message.Message;
import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.store.Data;
import org.h2.store.Page;
import org.h2.store.PageStore;
import org.h2.table.Column;
import org.h2.table.IndexColumn;
......@@ -198,7 +199,11 @@ public class PageDataIndex extends PageIndex implements RowIndex {
* @return the page
*/
PageData getPage(int id, int parent) throws SQLException {
PageData p = (PageData) store.getPage(id);
Page pd = store.getPage(id);
if (pd != null && !(pd instanceof PageData)) {
System.out.println("test");
}
PageData p = (PageData) pd;
if (p == null) {
PageDataLeaf empty = PageDataLeaf.create(this, id, parent);
// could have been created before, but never committed
......
......@@ -83,7 +83,7 @@ public class PageDataLeaf extends PageData {
*/
static PageDataLeaf create(PageDataIndex index, int pageId, int parentPageId) throws SQLException {
PageDataLeaf p = new PageDataLeaf(index, pageId, index.getPageStore().createData());
index.getPageStore().logUndo(p, p.data);
index.getPageStore().logUndo(p, null);
p.parentPageId = parentPageId;
p.columnCount = index.getTable().getColumns().length;
p.writeHead();
......@@ -320,6 +320,10 @@ public class PageDataLeaf extends PageData {
int next = firstOverflowPageId;
do {
PageDataOverflow page = index.getPageOverflow(next);
if (page == null) {
page = index.getPageOverflow(next);
System.out.println("stop!");
}
next = page.readInto(buff);
} while (next != 0);
overflowRowSize = pageSize + buff.length();
......@@ -429,6 +433,7 @@ public class PageDataLeaf extends PageData {
public void write(DataPage buff) throws SQLException {
write();
index.getPageStore().checkUndo(getPos());
index.getPageStore().writePage(getPos(), data);
data.truncate(index.getPageStore().getPageSize());
}
......
......@@ -65,7 +65,7 @@ public class PageDataNode extends PageData {
*/
static PageDataNode create(PageDataIndex index, int pageId, int parentPageId) throws SQLException {
PageDataNode p = new PageDataNode(index, pageId, index.getPageStore().createData());
index.getPageStore().logUndo(p, p.data);
index.getPageStore().logUndo(p, null);
p.parentPageId = parentPageId;
p.writeHead();
// 4 bytes for the rightmost child page id
......@@ -326,6 +326,7 @@ public class PageDataNode extends PageData {
public void write(DataPage buff) throws SQLException {
write();
index.getPageStore().checkUndo(getPos());
index.getPageStore().writePage(getPos(), data);
}
......
......@@ -110,7 +110,7 @@ public class PageDataOverflow extends Page {
static PageDataOverflow create(PageStore store, int page, int type, int parentPageId, int next, Data all, int offset, int size) throws SQLException {
Data data = store.createData();
PageDataOverflow p = new PageDataOverflow(store, page, data);
store.logUndo(p, data);
store.logUndo(p, null);
data.writeByte((byte) type);
data.writeShortInt(0);
data.writeInt(parentPageId);
......@@ -180,6 +180,7 @@ public class PageDataOverflow extends Page {
public void write(DataPage buff) throws SQLException {
write();
store.checkUndo(getPos());
store.writePage(getPos(), data);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论