提交 03e1c25a authored 作者: Thomas Mueller's avatar Thomas Mueller

new experimental page store

上级 d7e9f4a2
...@@ -524,7 +524,9 @@ public class Database implements DataHandler { ...@@ -524,7 +524,9 @@ public class Database implements DataHandler {
// wait until pending changes are written // wait until pending changes are written
isReconnectNeeded(); isReconnectNeeded();
if (SysProperties.PAGE_STORE) { if (SysProperties.PAGE_STORE) {
starting = true;
getPageStore(); getPageStore();
starting = false;
} }
if (FileUtils.exists(dataFileName)) { if (FileUtils.exists(dataFileName)) {
lobFilesInDirectories &= !ValueLob.existsLobFile(getDatabasePath()); lobFilesInDirectories &= !ValueLob.existsLobFile(getDatabasePath());
...@@ -582,7 +584,7 @@ public class Database implements DataHandler { ...@@ -582,7 +584,7 @@ public class Database implements DataHandler {
cols.add(new Column("SQL", Value.STRING)); cols.add(new Column("SQL", Value.STRING));
int headPos = 0; int headPos = 0;
if (pageStore != null) { if (pageStore != null) {
headPos = pageStore.getMetaTableHeadPos(); headPos = pageStore.getSystemTableHeadPos();
} }
meta = mainSchema.createTable("SYS", 0, cols, persistent, false, headPos); meta = mainSchema.createTable("SYS", 0, cols, persistent, false, headPos);
tableMap.put(0, meta); tableMap.put(0, meta);
...@@ -2143,31 +2145,6 @@ public class Database implements DataHandler { ...@@ -2143,31 +2145,6 @@ public class Database implements DataHandler {
return pageStore; return pageStore;
} }
/**
* Redo a change in a table.
*
* @param tableId the object id of the table
* @param row the row
* @param add true if the record is added, false if deleted
*/
public void redo(int tableId, Row row, boolean add) throws SQLException {
TableData table = (TableData) tableMap.get(tableId);
if (add) {
table.addRow(systemSession, row);
} else {
table.removeRow(systemSession, row);
}
if (tableId == 0) {
MetaRecord m = new MetaRecord(row);
if (add) {
objectIds.set(m.getId());
m.execute(this, systemSession, eventListener);
} else {
m.undo(this, systemSession, eventListener);
}
}
}
/** /**
* Get the first user defined table. * Get the first user defined table.
* *
......
...@@ -11,6 +11,7 @@ import org.h2.constant.ErrorCode; ...@@ -11,6 +11,7 @@ import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.message.TraceSystem;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.result.SearchRow; import org.h2.result.SearchRow;
import org.h2.store.DataPage; import org.h2.store.DataPage;
...@@ -36,6 +37,7 @@ public class PageBtreeIndex extends BaseIndex { ...@@ -36,6 +37,7 @@ public class PageBtreeIndex extends BaseIndex {
public PageBtreeIndex(TableData table, int id, String indexName, IndexColumn[] columns, public PageBtreeIndex(TableData table, int id, String indexName, IndexColumn[] columns,
IndexType indexType, int headPos) throws SQLException { IndexType indexType, int headPos) throws SQLException {
initBaseIndex(table, id, indexName, columns, indexType); initBaseIndex(table, id, indexName, columns, indexType);
int test;
// trace.setLevel(TraceSystem.DEBUG); // trace.setLevel(TraceSystem.DEBUG);
if (database.isMultiVersion()) { if (database.isMultiVersion()) {
int todoMvcc; int todoMvcc;
...@@ -49,22 +51,20 @@ public class PageBtreeIndex extends BaseIndex { ...@@ -49,22 +51,20 @@ public class PageBtreeIndex extends BaseIndex {
if (headPos == Index.EMPTY_HEAD) { if (headPos == Index.EMPTY_HEAD) {
// new index // new index
needRebuild = true; needRebuild = true;
headPos = store.allocatePage(); this.headPos = headPos = store.allocatePage();
PageBtreeLeaf root = new PageBtreeLeaf(this, headPos, Page.ROOT, store.createDataPage()); PageBtreeLeaf root = new PageBtreeLeaf(this, headPos, Page.ROOT, store.createDataPage());
store.updateRecord(root, true, root.data); store.updateRecord(root, true, root.data);
int test; store.addMeta(this);
// } else if (store.isNew()) {
// // the system table for a new database
// PageBtreeLeaf root = new PageBtreeLeaf(this,
// headPos, Page.ROOT, store.createDataPage());
// store.updateRecord(root, true, root.data);
} else { } else {
rowCount = getPage(headPos).getRowCount(); this.headPos = headPos;
PageBtree root = getPage(headPos);
rowCount = root.getRowCount();
// could have been created before, but never committed
store.updateRecord(root, false, null);
int reuseKeysIfManyDeleted; int reuseKeysIfManyDeleted;
} }
this.headPos = headPos;
if (trace.isDebugEnabled()) { if (trace.isDebugEnabled()) {
trace.debug("open " + rowCount); trace.debug("opened " + getName() +" rows:"+ rowCount);
} }
} }
...@@ -211,7 +211,7 @@ public class PageBtreeIndex extends BaseIndex { ...@@ -211,7 +211,7 @@ public class PageBtreeIndex extends BaseIndex {
if (trace.isDebugEnabled()) { if (trace.isDebugEnabled()) {
trace.debug("remove"); trace.debug("remove");
} }
int todo; store.removeMeta(this);
} }
public void truncate(Session session) throws SQLException { public void truncate(Session session) throws SQLException {
......
...@@ -12,6 +12,7 @@ import org.h2.constant.ErrorCode; ...@@ -12,6 +12,7 @@ import org.h2.constant.ErrorCode;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.message.TraceSystem;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.result.SearchRow; import org.h2.result.SearchRow;
import org.h2.store.DataPage; import org.h2.store.DataPage;
...@@ -32,25 +33,27 @@ public class PageScanIndex extends BaseIndex implements RowIndex { ...@@ -32,25 +33,27 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
private PageStore store; private PageStore store;
private TableData tableData; private TableData tableData;
private int headPos; private final int headPos;
private int lastKey; private int lastKey;
private long rowCount; private long rowCount;
public PageScanIndex(TableData table, int id, IndexColumn[] columns, IndexType indexType, int headPos) throws SQLException { public PageScanIndex(TableData table, int id, IndexColumn[] columns, IndexType indexType, int headPos) throws SQLException {
initBaseIndex(table, id, table.getName() + "_TABLE_SCAN", columns, indexType); initBaseIndex(table, id, table.getName() + "_TABLE_SCAN", columns, indexType);
int test;
// trace.setLevel(TraceSystem.DEBUG); // trace.setLevel(TraceSystem.DEBUG);
if (database.isMultiVersion()) { if (database.isMultiVersion()) {
int todoMvcc; int todoMvcc;
} }
tableData = table; tableData = table;
if (!database.isPersistent() || id < 0) { this.store = database.getPageStore();
if (!database.isPersistent()) {
int todo; int todo;
this.headPos = 0;
return; return;
} }
this.store = database.getPageStore();
if (headPos == Index.EMPTY_HEAD) { if (headPos == Index.EMPTY_HEAD) {
// new table // new table
headPos = store.allocatePage(); this.headPos = headPos = store.allocatePage();
store.addMeta(this); store.addMeta(this);
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);
...@@ -61,6 +64,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex { ...@@ -61,6 +64,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
// Page.ROOT, store.createDataPage()); // Page.ROOT, store.createDataPage());
// store.updateRecord(root, true, root.data); // store.updateRecord(root, true, root.data);
} else { } else {
this.headPos = headPos;
PageData root = getPage(headPos); PageData root = getPage(headPos);
lastKey = root.getLastKey(); lastKey = root.getLastKey();
rowCount = root.getRowCount(); rowCount = root.getRowCount();
...@@ -68,9 +72,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex { ...@@ -68,9 +72,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
store.updateRecord(root, false, null); store.updateRecord(root, false, null);
int reuseKeysIfManyDeleted; int reuseKeysIfManyDeleted;
} }
this.headPos = headPos;
if (trace.isDebugEnabled()) { if (trace.isDebugEnabled()) {
trace.debug("open " + rowCount); trace.debug("opened " + getName() + " rows:" + rowCount);
} }
table.setRowCount(rowCount); table.setRowCount(rowCount);
} }
...@@ -80,7 +83,9 @@ public class PageScanIndex extends BaseIndex implements RowIndex { ...@@ -80,7 +83,9 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
} }
public void add(Session session, Row row) throws SQLException { public void add(Session session, Row row) throws SQLException {
row.setPos(++lastKey); if (row.getPos() == 0) {
row.setPos(++lastKey);
}
if (trace.isDebugEnabled()) { if (trace.isDebugEnabled()) {
trace.debug("add " + row.getPos()); trace.debug("add " + row.getPos());
} }
...@@ -217,7 +222,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex { ...@@ -217,7 +222,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
if (trace.isDebugEnabled()) { if (trace.isDebugEnabled()) {
trace.debug("remove"); trace.debug("remove");
} }
int todo; store.removeMeta(this);
} }
public void truncate(Session session) throws SQLException { public void truncate(Session session) throws SQLException {
......
...@@ -154,12 +154,11 @@ public class PageLog { ...@@ -154,12 +154,11 @@ public class PageLog {
int tableId = in.readInt(); int tableId = in.readInt();
Row row = readRow(in, data); Row row = readRow(in, data);
if (!undo) { if (!undo) {
Database db = store.getDatabase();
if (store.isSessionCommitted(sessionId, id, pos)) { if (store.isSessionCommitted(sessionId, id, pos)) {
if (trace.isDebugEnabled()) { if (trace.isDebugEnabled()) {
trace.debug("log redo " + (x == ADD ? "+" : "-") + " " + row); trace.debug("log redo " + (x == ADD ? "+" : "-") + " table:" + tableId + " " + row);
} }
db.redo(tableId, row, x == ADD); store.redo(tableId, row, x == ADD);
} }
} }
} else if (x == COMMIT) { } else if (x == COMMIT) {
......
...@@ -239,15 +239,15 @@ public class TableData extends Table implements RecordReader { ...@@ -239,15 +239,15 @@ public class TableData extends Table implements RecordReader {
} else { } else {
database.addSchemaObject(session, index); database.addSchemaObject(session, index);
} }
// Need to update, because maybe the index is rebuilt at startup, // must not do this when using the page store
// and so the head pos may have changed, which needs to be stored now. // because recovery is not done yet
// addSchemaObject doesn't update the sys table at startup if (!SysProperties.PAGE_STORE) {
if (index.getIndexType().getPersistent() && !database.getReadOnly() // need to update, because maybe the index is rebuilt at startup,
&& !database.getLog().containsInDoubtTransactions()) { // and so the head pos may have changed, which needs to be stored now.
// can not save anything in the log file if it contains in-doubt transactions // addSchemaObject doesn't update the sys table at startup
if (!SysProperties.PAGE_STORE) { if (index.getIndexType().getPersistent() && !database.getReadOnly()
// must not do this when using the page store && !database.getLog().containsInDoubtTransactions()) {
// because recovery is not done yet // can not save anything in the log file if it contains in-doubt transactions
database.update(session, index); database.update(session, index);
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论