提交 589f38be authored 作者: Thomas Mueller's avatar Thomas Mueller

New experimental page store.

上级 9c219404
...@@ -135,6 +135,12 @@ public class PageBtreeIndex extends BaseIndex { ...@@ -135,6 +135,12 @@ public class PageBtreeIndex extends BaseIndex {
PageBtree getPage(int id) throws SQLException { PageBtree getPage(int id) throws SQLException {
Record rec = store.getRecord(id); Record rec = store.getRecord(id);
if (rec != null) { if (rec != null) {
if (SysProperties.CHECK) {
PageBtree result = (PageBtree) rec;
if (result.index.headPos != this.headPos) {
throw Message.throwInternalError("Wrong index: " + result.index + " " + this);
}
}
return (PageBtree) rec; return (PageBtree) rec;
} }
DataPage data = store.readPage(id); DataPage data = store.readPage(id);
......
...@@ -14,6 +14,7 @@ import java.util.Iterator; ...@@ -14,6 +14,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.log.UndoLogRecord; import org.h2.log.UndoLogRecord;
...@@ -71,12 +72,6 @@ public class PageScanIndex extends BaseIndex implements RowIndex { ...@@ -71,12 +72,6 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
store.addMeta(this, session, headPos); store.addMeta(this, session, headPos);
PageDataLeaf root = new PageDataLeaf(this, headPos, Page.ROOT, store.createDataPage()); PageDataLeaf root = new PageDataLeaf(this, headPos, Page.ROOT, store.createDataPage());
store.updateRecord(root, true, root.data); store.updateRecord(root, true, root.data);
// } else if (store.isNew()) {
// // the system table for a new database
// PageDataLeaf root = new PageDataLeaf(this, headPos,
// Page.ROOT, store.createDataPage());
// store.updateRecord(root, true, root.data);
} else { } else {
this.headPos = headPos; this.headPos = headPos;
PageData root = getPage(headPos, 0); PageData root = getPage(headPos, 0);
...@@ -168,6 +163,12 @@ public class PageScanIndex extends BaseIndex implements RowIndex { ...@@ -168,6 +163,12 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
PageData getPage(int id, int parent) throws SQLException { PageData getPage(int id, int parent) throws SQLException {
Record rec = store.getRecord(id); Record rec = store.getRecord(id);
if (rec != null) { if (rec != null) {
if (SysProperties.CHECK) {
PageData result = (PageData) rec;
if (result.index.headPos != this.headPos) {
throw Message.throwInternalError("Wrong index: " + result.index + " " + this);
}
}
return (PageData) rec; return (PageData) rec;
} }
DataPage data = store.readPage(id); DataPage data = store.readPage(id);
......
...@@ -124,9 +124,6 @@ public class PageInputStream extends InputStream { ...@@ -124,9 +124,6 @@ public class PageInputStream extends InputStream {
store.allocatePage(n); store.allocatePage(n);
} }
trunkPage = t.getNextTrunk(); trunkPage = t.getNextTrunk();
if (trunkPage != 0) {
break;
}
} }
} }
......
...@@ -117,6 +117,7 @@ public class PageStore implements CacheWriter { ...@@ -117,6 +117,7 @@ public class PageStore implements CacheWriter {
// remove CacheObject.blockCount // remove CacheObject.blockCount
// remove Record.getMemorySize // remove Record.getMemorySize
// simplify InDoubtTransaction // simplify InDoubtTransaction
// remove parameter in Record.write(DataPage buff)
/** /**
* The smallest possible page size. * The smallest possible page size.
...@@ -135,7 +136,6 @@ public class PageStore implements CacheWriter { ...@@ -135,7 +136,6 @@ public class PageStore implements CacheWriter {
private static final int PAGE_ID_FREE_LIST_ROOT = 3; private static final int PAGE_ID_FREE_LIST_ROOT = 3;
private static final int PAGE_ID_META_ROOT = 4; private static final int PAGE_ID_META_ROOT = 4;
private static final int PAGE_ID_LOG_TRUNK = 5;
private static final int MIN_PAGE_COUNT = 6; private static final int MIN_PAGE_COUNT = 6;
...@@ -200,7 +200,7 @@ public class PageStore implements CacheWriter { ...@@ -200,7 +200,7 @@ public class PageStore implements CacheWriter {
this.database = database; this.database = database;
trace = database.getTrace(Trace.PAGE_STORE); trace = database.getTrace(Trace.PAGE_STORE);
int test; int test;
//trace.setLevel(TraceSystem.DEBUG); // trace.setLevel(TraceSystem.DEBUG);
this.cacheSize = cacheSizeDefault; this.cacheSize = cacheSizeDefault;
String cacheType = database.getCacheType(); String cacheType = database.getCacheType();
this.cache = CacheLRU.getCache(this, cacheType, cacheSize); this.cache = CacheLRU.getCache(this, cacheType, cacheSize);
...@@ -490,7 +490,6 @@ public class PageStore implements CacheWriter { ...@@ -490,7 +490,6 @@ public class PageStore implements CacheWriter {
if (trace.isDebugEnabled()) { if (trace.isDebugEnabled()) {
trace.debug("writeBack " + record); trace.debug("writeBack " + record);
} }
int todoRemoveParameter;
record.write(null); record.write(null);
record.setChanged(false); record.setChanged(false);
} }
...@@ -582,6 +581,9 @@ public class PageStore implements CacheWriter { ...@@ -582,6 +581,9 @@ public class PageStore implements CacheWriter {
if (pos >= pageCount) { if (pos >= pageCount) {
increaseFileSize(INCREMENT_PAGES); increaseFileSize(INCREMENT_PAGES);
} }
if (trace.isDebugEnabled()) {
trace.debug("allocatePage " + pos);
}
return pos; return pos;
} }
} }
...@@ -853,10 +855,8 @@ public class PageStore implements CacheWriter { ...@@ -853,10 +855,8 @@ public class PageStore implements CacheWriter {
index.getTable().removeIndex(index); index.getTable().removeIndex(index);
if (index instanceof PageBtreeIndex) { if (index instanceof PageBtreeIndex) {
index.getSchema().remove(index); index.getSchema().remove(index);
} else if (index instanceof PageScanIndex) {
// TODO test why this doesn't work
// index.remove(null);
} }
index.remove(systemSession);
} }
private void addMeta(Row row, Session session, boolean redo) throws SQLException { private void addMeta(Row row, Session session, boolean redo) throws SQLException {
...@@ -873,11 +873,8 @@ public class PageStore implements CacheWriter { ...@@ -873,11 +873,8 @@ public class PageStore implements CacheWriter {
trace.debug("addMeta id=" + id + " type=" + type + " parent=" + parent + " columns=" + columnList); trace.debug("addMeta id=" + id + " type=" + type + " parent=" + parent + " columns=" + columnList);
} }
if (redo) { if (redo) {
int test; writePage(headPos, createDataPage());
byte[] empty = new byte[pageSize]; allocatePage(headPos);
file.seek(headPos * pageSize);
file.write(empty, 0, pageSize);
removeRecord(headPos);
} }
if (type == META_TYPE_SCAN_INDEX) { if (type == META_TYPE_SCAN_INDEX) {
ObjectArray<Column> columnArray = ObjectArray.newInstance(); ObjectArray<Column> columnArray = ObjectArray.newInstance();
...@@ -941,18 +938,14 @@ public class PageStore implements CacheWriter { ...@@ -941,18 +938,14 @@ public class PageStore implements CacheWriter {
Table table = index.getTable(); Table table = index.getTable();
CompareMode mode = table.getCompareMode(); CompareMode mode = table.getCompareMode();
String options = mode.getName()+ "," + mode.getStrength(); String options = mode.getName()+ "," + mode.getStrength();
addMeta(index.getId(), type, table.getId(), headPos, options, columnList, session);
}
private void addMeta(int id, int type, int parent, int headPos, String options, String columnList, Session session) throws SQLException {
Row row = metaTable.getTemplateRow(); Row row = metaTable.getTemplateRow();
row.setValue(0, ValueInt.get(id)); row.setValue(0, ValueInt.get(index.getId()));
row.setValue(1, ValueInt.get(type)); row.setValue(1, ValueInt.get(type));
row.setValue(2, ValueInt.get(parent)); row.setValue(2, ValueInt.get(table.getId()));
row.setValue(3, ValueInt.get(headPos)); row.setValue(3, ValueInt.get(headPos));
row.setValue(4, ValueString.get(options)); row.setValue(4, ValueString.get(options));
row.setValue(5, ValueString.get(columnList)); row.setValue(5, ValueString.get(columnList));
row.setPos(id + 1); row.setPos(index.getId() + 1);
metaIndex.add(session, row); metaIndex.add(session, row);
} }
...@@ -963,9 +956,11 @@ public class PageStore implements CacheWriter { ...@@ -963,9 +956,11 @@ public class PageStore implements CacheWriter {
* @param session the session * @param session the session
*/ */
public void removeMeta(Index index, Session session) throws SQLException { public void removeMeta(Index index, Session session) throws SQLException {
if (!recoveryRunning) {
Row row = metaIndex.getRow(session, index.getId() + 1); Row row = metaIndex.getRow(session, index.getId() + 1);
metaIndex.remove(session, row); metaIndex.remove(session, row);
} }
}
private void updateChecksum(byte[] d, int pos) { private void updateChecksum(byte[] d, int pos) {
int ps = pageSize; int ps = pageSize;
......
...@@ -56,6 +56,11 @@ public class PageStreamTrunk extends Record { ...@@ -56,6 +56,11 @@ public class PageStreamTrunk extends Record {
store.readPage(getPos(), data); store.readPage(getPos(), data);
parent = data.readInt(); parent = data.readInt();
int t = data.readByte(); int t = data.readByte();
if (t == Page.TYPE_EMPTY) {
// end of file
pageIds = new int[0];
return;
}
if (t != Page.TYPE_STREAM_TRUNK) { if (t != Page.TYPE_STREAM_TRUNK) {
throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1, "pos:" + getPos() + " type:" + t + " parent:" + parent throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1, "pos:" + getPos() + " type:" + t + " parent:" + parent
+ " expected type:" + Page.TYPE_STREAM_TRUNK); + " expected type:" + Page.TYPE_STREAM_TRUNK);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论