提交 a8693704 authored 作者: Thomas Mueller's avatar Thomas Mueller

New experimental page store.

上级 2376a5e1
...@@ -9,6 +9,7 @@ package org.h2.command.dml; ...@@ -9,6 +9,7 @@ package org.h2.command.dml;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.SysProperties;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.log.LogSystem; import org.h2.log.LogSystem;
...@@ -123,8 +124,8 @@ public class TransactionCommand extends Prepared { ...@@ -123,8 +124,8 @@ public class TransactionCommand extends Prepared {
break; break;
case CHECKPOINT: case CHECKPOINT:
session.getUser().checkAdmin(); session.getUser().checkAdmin();
if (SysProperties.PAGE_STORE) {
PageStore store = session.getDatabase().getPageStore(); PageStore store = session.getDatabase().getPageStore();
if (store != null) {
store.checkpoint(); store.checkpoint();
} }
session.getDatabase().getLog().checkpoint(); session.getDatabase().getLog().checkpoint();
......
...@@ -2091,7 +2091,7 @@ public class Database implements DataHandler { ...@@ -2091,7 +2091,7 @@ public class Database implements DataHandler {
} }
public PageStore getPageStore() throws SQLException { public PageStore getPageStore() throws SQLException {
if (pageStore == null) { if (pageStore == null && SysProperties.PAGE_STORE) {
pageStore = new PageStore(this, databaseName + Constants.SUFFIX_PAGE_FILE, accessModeData, pageStore = new PageStore(this, databaseName + Constants.SUFFIX_PAGE_FILE, accessModeData,
SysProperties.CACHE_SIZE_DEFAULT); SysProperties.CACHE_SIZE_DEFAULT);
pageStore.open(); pageStore.open();
......
...@@ -42,7 +42,7 @@ public class LogSystem { ...@@ -42,7 +42,7 @@ public class LogSystem {
private LogFile currentLog; private LogFile currentLog;
private String fileNamePrefix; private String fileNamePrefix;
private HashMap storages = new HashMap(); private HashMap storages = new HashMap();
private HashMap sessions = new HashMap(); private HashMap sessionStates = new HashMap();
private DataPage rowBuff; private DataPage rowBuff;
private ObjectArray undo; private ObjectArray undo;
// TODO log file / deleteOldLogFilesAutomatically: // TODO log file / deleteOldLogFilesAutomatically:
...@@ -252,7 +252,7 @@ public class LogSystem { ...@@ -252,7 +252,7 @@ public class LogSystem {
database.getIndexFile().flushRedoLog(); database.getIndexFile().flushRedoLog();
} }
int end = currentLog.getPos(); int end = currentLog.getPos();
Object[] states = sessions.values().toArray(); Object[] states = sessionStates.values().toArray();
inDoubtTransactions = new ObjectArray(); inDoubtTransactions = new ObjectArray();
for (int i = 0; i < states.length; i++) { for (int i = 0; i < states.length; i++) {
SessionState state = (SessionState) states[i]; SessionState state = (SessionState) states[i];
...@@ -260,10 +260,10 @@ public class LogSystem { ...@@ -260,10 +260,10 @@ public class LogSystem {
inDoubtTransactions.add(state.inDoubtTransaction); inDoubtTransactions.add(state.inDoubtTransaction);
} }
} }
for (int i = undo.size() - 1; i >= 0 && sessions.size() > 0; i--) { for (int i = undo.size() - 1; i >= 0 && sessionStates.size() > 0; i--) {
database.setProgress(DatabaseEventListener.STATE_RECOVER, null, undo.size() - 1 - i, undo.size()); database.setProgress(DatabaseEventListener.STATE_RECOVER, null, undo.size() - 1 - i, undo.size());
LogRecord record = (LogRecord) undo.get(i); LogRecord record = (LogRecord) undo.get(i);
if (sessions.get(ObjectUtils.getInteger(record.sessionId)) != null) { if (sessionStates.get(ObjectUtils.getInteger(record.sessionId)) != null) {
// undo only if the session is not yet committed // undo only if the session is not yet committed
record.log.undo(record.logRecordId); record.log.undo(record.logRecordId);
database.getDataFile().flushRedoLog(); database.getDataFile().flushRedoLog();
...@@ -359,7 +359,7 @@ public class LogSystem { ...@@ -359,7 +359,7 @@ public class LogSystem {
*/ */
boolean isSessionCommitted(int sessionId, int logId, int pos) { boolean isSessionCommitted(int sessionId, int logId, int pos) {
Integer key = ObjectUtils.getInteger(sessionId); Integer key = ObjectUtils.getInteger(sessionId);
SessionState state = (SessionState) sessions.get(key); SessionState state = (SessionState) sessionStates.get(key);
if (state == null) { if (state == null) {
return true; return true;
} }
...@@ -389,10 +389,10 @@ public class LogSystem { ...@@ -389,10 +389,10 @@ public class LogSystem {
*/ */
SessionState getOrAddSessionState(int sessionId) { SessionState getOrAddSessionState(int sessionId) {
Integer key = ObjectUtils.getInteger(sessionId); Integer key = ObjectUtils.getInteger(sessionId);
SessionState state = (SessionState) sessions.get(key); SessionState state = (SessionState) sessionStates.get(key);
if (state == null) { if (state == null) {
state = new SessionState(); state = new SessionState();
sessions.put(key, state); sessionStates.put(key, state);
state.sessionId = sessionId; state.sessionId = sessionId;
} }
return state; return state;
...@@ -433,7 +433,7 @@ public class LogSystem { ...@@ -433,7 +433,7 @@ public class LogSystem {
* @param sessionId the session id * @param sessionId the session id
*/ */
void removeSession(int sessionId) { void removeSession(int sessionId) {
sessions.remove(ObjectUtils.getInteger(sessionId)); sessionStates.remove(ObjectUtils.getInteger(sessionId));
} }
/** /**
......
...@@ -15,22 +15,22 @@ public class SessionState { ...@@ -15,22 +15,22 @@ public class SessionState {
/** /**
* The session id * The session id
*/ */
int sessionId; public int sessionId;
/** /**
* The last log file id where a commit for this session is found. * The last log file id where a commit for this session is found.
*/ */
int lastCommitLog; public int lastCommitLog;
/** /**
* The position where a commit for this session is found. * The position where a commit for this session is found.
*/ */
int lastCommitPos; public int lastCommitPos;
/** /**
* The in-doubt transaction if there is one. * The in-doubt transaction if there is one.
*/ */
InDoubtTransaction inDoubtTransaction; public InDoubtTransaction inDoubtTransaction;
/** /**
* Check if this session state is already committed at this point. * Check if this session state is already committed at this point.
...@@ -39,7 +39,7 @@ public class SessionState { ...@@ -39,7 +39,7 @@ public class SessionState {
* @param pos the position in the log file * @param pos the position in the log file
* @return true if it is committed * @return true if it is committed
*/ */
boolean isCommitted(int logId, int pos) { public boolean isCommitted(int logId, int pos) {
if (logId != lastCommitLog) { if (logId != lastCommitLog) {
return lastCommitLog > logId; return lastCommitLog > logId;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论