提交 5799af16 authored 作者: Thomas Mueller's avatar Thomas Mueller

New experimental page store.

上级 edce6934
...@@ -54,12 +54,16 @@ public class PageScanIndex extends BaseIndex implements RowIndex { ...@@ -54,12 +54,16 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
int todo; int todo;
return; return;
} }
this.store = database.getPageStorage(); this.store = database.getPageStore();
if (headPos == Index.EMPTY_HEAD || store.isNew()) { if (headPos == Index.EMPTY_HEAD) {
// new table, or the system table for a new database // new table
headPos = store.allocatePage(); headPos = store.allocatePage();
PageDataLeaf root = new PageDataLeaf(this, headPos, Page.ROOT, store.createDataPage()); PageDataLeaf root = new PageDataLeaf(this, headPos, Page.ROOT, store.createDataPage());
store.updateRecord(root, root.data); store.updateRecord(root, 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, root.data);
} else { } else {
lastKey = getPage(headPos).getLastKey(); lastKey = getPage(headPos).getLastKey();
rowCount = getPage(headPos).getRowCount(); rowCount = getPage(headPos).getRowCount();
...@@ -100,6 +104,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex { ...@@ -100,6 +104,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
root = newRoot; root = newRoot;
} }
rowCount++; rowCount++;
int todo;
// store.getLog().addRow(headPos, row);
} }
/** /**
...@@ -125,6 +131,9 @@ public class PageScanIndex extends BaseIndex implements RowIndex { ...@@ -125,6 +131,9 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
case Page.TYPE_DATA_NODE: case Page.TYPE_DATA_NODE:
result = new PageDataNode(this, id, parentPageId, data); result = new PageDataNode(this, id, parentPageId, data);
break; break;
case Page.TYPE_EMPTY:
PageDataLeaf empty = new PageDataLeaf(this, id, parentPageId, data);
return empty;
default: default:
throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1, "page=" + id + " type=" + type); throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1, "page=" + id + " type=" + type);
} }
...@@ -229,8 +238,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex { ...@@ -229,8 +238,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
} }
private void trace(String message) { private void trace(String message) {
int todoSometimeSlow;
if (headPos != 1) { if (headPos != 1) {
int test;
// System.out.println(message); // System.out.println(message);
} }
} }
......
...@@ -18,6 +18,8 @@ import org.h2.message.Message; ...@@ -18,6 +18,8 @@ import org.h2.message.Message;
import org.h2.message.Trace; import org.h2.message.Trace;
import org.h2.store.DataPage; import org.h2.store.DataPage;
import org.h2.store.DiskFile; import org.h2.store.DiskFile;
import org.h2.store.PageLog;
import org.h2.store.PageStore;
import org.h2.store.Record; import org.h2.store.Record;
import org.h2.store.Storage; import org.h2.store.Storage;
import org.h2.util.FileUtils; import org.h2.util.FileUtils;
...@@ -61,6 +63,7 @@ public class LogSystem { ...@@ -61,6 +63,7 @@ public class LogSystem {
private int keepFiles; private int keepFiles;
private boolean closed; private boolean closed;
private String accessMode; private String accessMode;
private PageLog pageLog;
/** /**
* Create new transaction log object. This will not open or create files * Create new transaction log object. This will not open or create files
...@@ -70,9 +73,13 @@ public class LogSystem { ...@@ -70,9 +73,13 @@ public class LogSystem {
* @param fileNamePrefix the name of the database file * @param fileNamePrefix the name of the database file
* @param readOnly if the log should be opened in read-only mode * @param readOnly if the log should be opened in read-only mode
* @param accessMode the file access mode (r, rw, rws, rwd) * @param accessMode the file access mode (r, rw, rws, rwd)
* @param pageStore
*/ */
public LogSystem(Database database, String fileNamePrefix, boolean readOnly, String accessMode) { public LogSystem(Database database, String fileNamePrefix, boolean readOnly, String accessMode, PageStore pageStore) {
this.database = database; this.database = database;
if (pageStore != null) {
this.pageLog = pageStore.getLog();
}
this.readOnly = readOnly; this.readOnly = readOnly;
this.accessMode = accessMode; this.accessMode = accessMode;
closed = true; closed = true;
...@@ -465,6 +472,9 @@ public class LogSystem { ...@@ -465,6 +472,9 @@ public class LogSystem {
if (closed) { if (closed) {
return; return;
} }
if (pageLog != null) {
pageLog.commit(session);
}
currentLog.commit(session); currentLog.commit(session);
session.setAllCommitted(); session.setAllCommitted();
} }
......
...@@ -18,7 +18,7 @@ import org.h2.message.Message; ...@@ -18,7 +18,7 @@ import org.h2.message.Message;
* The format is: * The format is:
* <ul><li>0-3: parent page id * <ul><li>0-3: parent page id
* </li><li>4-4: page type * </li><li>4-4: page type
* </li><li>5-8: the next page (if there are more) or length * </li><li>5-8: the next page (if there is one) or length
* </li><li>9-remainder: data * </li><li>9-remainder: data
* </li></ul> * </li></ul>
*/ */
......
...@@ -10,6 +10,7 @@ import java.io.DataInputStream; ...@@ -10,6 +10,7 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.engine.Session;
import org.h2.index.Page; import org.h2.index.Page;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.util.BitField; import org.h2.util.BitField;
...@@ -17,7 +18,7 @@ import org.h2.util.BitField; ...@@ -17,7 +18,7 @@ import org.h2.util.BitField;
/** /**
* Transaction log mechanism. * Transaction log mechanism.
* The data format is: * The data format is:
* <ul><li>0-0: type (0: undo) * <ul><li>0-0: type (0: undo,...)
* </li><li>1-4: page id * </li><li>1-4: page id
* </li><li>5-: data * </li><li>5-: data
* </li></ul> * </li></ul>
...@@ -25,6 +26,7 @@ import org.h2.util.BitField; ...@@ -25,6 +26,7 @@ import org.h2.util.BitField;
public class PageLog { public class PageLog {
private static final int UNDO = 0; private static final int UNDO = 0;
private static final int COMMIT = 1;
private PageStore store; private PageStore store;
private BitField undo = new BitField(); private BitField undo = new BitField();
private DataOutputStream out; private DataOutputStream out;
...@@ -57,13 +59,17 @@ public class PageLog { ...@@ -57,13 +59,17 @@ public class PageLog {
} }
if (x == UNDO) { if (x == UNDO) {
int pageId = in.readInt(); int pageId = in.readInt();
int test;
System.out.println("redo " + pageId);
in.read(data.getBytes(), 0, store.getPageSize()); in.read(data.getBytes(), 0, store.getPageSize());
store.writePage(pageId, data); store.writePage(pageId, data);
} }
} }
} catch (IOException e) { } catch (IOException e) {
throw Message.convertIOException(e, "recovering"); int todoSomeExceptionAreOkSomeNot;
// throw Message.convertIOException(e, "recovering");
} }
int todoDeleteAfterRecovering;
} }
/** /**
...@@ -78,6 +84,8 @@ public class PageLog { ...@@ -78,6 +84,8 @@ public class PageLog {
if (undo.get(pageId)) { if (undo.get(pageId)) {
return; return;
} }
int test;
System.out.println("undo " + pageId);
out.write(UNDO); out.write(UNDO);
out.writeInt(pageId); out.writeInt(pageId);
out.write(page.getBytes(), 0, store.getPageSize()); out.write(page.getBytes(), 0, store.getPageSize());
...@@ -87,4 +95,18 @@ public class PageLog { ...@@ -87,4 +95,18 @@ public class PageLog {
} }
} }
/**
* Mark a committed transaction.
*
* @param session the session
*/
public void commit(Session session) throws SQLException {
try {
out.write(COMMIT);
out.writeInt(session.getId());
} catch (IOException e) {
throw Message.convertIOException(e, "recovering");
}
}
} }
...@@ -98,6 +98,10 @@ public class PageOutputStream extends OutputStream { ...@@ -98,6 +98,10 @@ public class PageOutputStream extends OutputStream {
store = null; store = null;
} }
public void flush() throws IOException {
int todo;
}
// public void write(byte[] buff, int off, int len) throws IOException { // public void write(byte[] buff, int off, int len) throws IOException {
// if (len > 0) { // if (len > 0) {
// try { // try {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论