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