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

new experimental page store

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