提交 86846013 authored 作者: Andrei Tokar's avatar Andrei Tokar

batch

上级 aad6a418
...@@ -836,6 +836,8 @@ public abstract class Page implements Cloneable ...@@ -836,6 +836,8 @@ public abstract class Page implements Cloneable
} }
} }
public abstract CursorPos getAppendCursorPos(CursorPos cursorPos);
public abstract void removeAllRecursive(); public abstract void removeAllRecursive();
private Object[] createKeyStorage(int size) private Object[] createKeyStorage(int size)
...@@ -1083,6 +1085,13 @@ public abstract class Page implements Cloneable ...@@ -1083,6 +1085,13 @@ public abstract class Page implements Cloneable
removePage(); removePage();
} }
@Override
public CursorPos getAppendCursorPos(CursorPos cursorPos) {
int keyCount = getKeyCount();
Page childPage = getChildPage(keyCount);
return childPage.getAppendCursorPos(new CursorPos(this, keyCount, cursorPos));
}
@Override @Override
protected void readPayLoad(ByteBuffer buff) { protected void readPayLoad(ByteBuffer buff) {
int keyCount = getKeyCount(); int keyCount = getKeyCount();
...@@ -1322,6 +1331,12 @@ public abstract class Page implements Cloneable ...@@ -1322,6 +1331,12 @@ public abstract class Page implements Cloneable
removePage(); removePage();
} }
@Override
public CursorPos getAppendCursorPos(CursorPos cursorPos) {
int keyCount = getKeyCount();
return new CursorPos(this, -keyCount - 1, cursorPos);
}
@Override @Override
protected void readPayLoad(ByteBuffer buff) { protected void readPayLoad(ByteBuffer buff) {
int keyCount = getKeyCount(); int keyCount = getKeyCount();
......
...@@ -300,7 +300,7 @@ public class Transaction { ...@@ -300,7 +300,7 @@ public class Transaction {
} }
int currentStatus = getStatus(currentState); int currentStatus = getStatus(currentState);
checkOpen(currentStatus); checkOpen(currentStatus);
store.removeUndoLogRecord(transactionId, logId); store.removeUndoLogRecord(transactionId);
} }
/** /**
......
...@@ -88,9 +88,9 @@ public class TransactionMap<K, V> { ...@@ -88,9 +88,9 @@ public class TransactionMap<K, V> {
for (int i = opentransactions.nextSetBit(0); i >= 0; i = opentransactions.nextSetBit(i+1)) { for (int i = opentransactions.nextSetBit(0); i >= 0; i = opentransactions.nextSetBit(i+1)) {
MVMap<Long, Object[]> undoLog = store.undoLogs[i]; MVMap<Long, Object[]> undoLog = store.undoLogs[i];
if (undoLog != null) { if (undoLog != null) {
MVMap.RootReference rootReference = undoLog.getRoot(); MVMap.RootReference rootReference = undoLog.flushAppendBuffer();
undoLogRootReferences[i] = rootReference; undoLogRootReferences[i] = rootReference;
undoLogSize += rootReference.root.getTotalCount(); undoLogSize += rootReference.root.getTotalCount() + rootReference.appendCounter;
} }
} }
} while(committingTransactions != store.committingTransactions.get() || } while(committingTransactions != store.committingTransactions.get() ||
......
...@@ -16,6 +16,7 @@ import org.h2.mvstore.Cursor; ...@@ -16,6 +16,7 @@ import org.h2.mvstore.Cursor;
import org.h2.mvstore.DataUtils; import org.h2.mvstore.DataUtils;
import org.h2.mvstore.MVMap; import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore; import org.h2.mvstore.MVStore;
import org.h2.mvstore.Page;
import org.h2.mvstore.WriteBuffer; import org.h2.mvstore.WriteBuffer;
import org.h2.mvstore.type.DataType; import org.h2.mvstore.type.DataType;
import org.h2.mvstore.type.ObjectDataType; import org.h2.mvstore.type.ObjectDataType;
...@@ -132,7 +133,9 @@ public class TransactionStore { ...@@ -132,7 +133,9 @@ public class TransactionStore {
ArrayType undoLogValueType = new ArrayType(new DataType[]{ ArrayType undoLogValueType = new ArrayType(new DataType[]{
new ObjectDataType(), dataType, oldValueType new ObjectDataType(), dataType, oldValueType
}); });
undoLogBuilder = new MVMap.Builder<Long, Object[]>().valueType(undoLogValueType); undoLogBuilder = new MVMap.Builder<Long, Object[]>()
.singleWriter()
.valueType(undoLogValueType);
} }
/** /**
...@@ -381,24 +384,16 @@ public class TransactionStore { ...@@ -381,24 +384,16 @@ public class TransactionStore {
"is still open: {0}", "is still open: {0}",
transactionId); transactionId);
} }
undoLog.put(undoKey, undoLogRecord); undoLog.append(undoKey, undoLogRecord);
return undoKey; return undoKey;
} }
/** /**
* Remove an undo log entry. * Remove an undo log entry.
* @param transactionId id of the transaction * @param transactionId id of the transaction
* @param logId sequential number of the log record within transaction
*/ */
public void removeUndoLogRecord(int transactionId, long logId) { void removeUndoLogRecord(int transactionId) {
Long undoKey = getOperationId(transactionId, logId); undoLogs[transactionId].trimLast();
Object[] old = undoLogs[transactionId].remove(undoKey);
if (old == null) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_TRANSACTION_ILLEGAL_STATE,
"Transaction {0} was concurrently rolled back",
transactionId);
}
} }
/** /**
...@@ -432,7 +427,9 @@ public class TransactionStore { ...@@ -432,7 +427,9 @@ public class TransactionStore {
store.renameMap(undoLog, getUndoLogName(true, transactionId)); store.renameMap(undoLog, getUndoLogName(true, transactionId));
} }
try { try {
Cursor<Long, Object[]> cursor = undoLog.cursor(null); MVMap.RootReference rootReference = undoLog.flushAppendBuffer();
Page rootPage = rootReference.root;
Cursor<Long, Object[]> cursor = new Cursor<>(rootPage, null);
while (cursor.hasNext()) { while (cursor.hasNext()) {
Long undoKey = cursor.next(); Long undoKey = cursor.next();
Object[] op = cursor.getValue(); Object[] op = cursor.getValue();
...@@ -587,6 +584,7 @@ public class TransactionStore { ...@@ -587,6 +584,7 @@ public class TransactionStore {
void rollbackTo(Transaction t, long maxLogId, long toLogId) { void rollbackTo(Transaction t, long maxLogId, long toLogId) {
int transactionId = t.getId(); int transactionId = t.getId();
MVMap<Long, Object[]> undoLog = undoLogs[transactionId]; MVMap<Long, Object[]> undoLog = undoLogs[transactionId];
undoLog.flushAppendBuffer();
RollbackDecisionMaker decisionMaker = new RollbackDecisionMaker(this, transactionId, toLogId, t.listener); RollbackDecisionMaker decisionMaker = new RollbackDecisionMaker(this, transactionId, toLogId, t.listener);
for (long logId = maxLogId - 1; logId >= toLogId; logId--) { for (long logId = maxLogId - 1; logId >= toLogId; logId--) {
Long undoKey = getOperationId(transactionId, logId); Long undoKey = getOperationId(transactionId, logId);
...@@ -608,6 +606,7 @@ public class TransactionStore { ...@@ -608,6 +606,7 @@ public class TransactionStore {
final long toLogId) { final long toLogId) {
final MVMap<Long, Object[]> undoLog = undoLogs[t.getId()]; final MVMap<Long, Object[]> undoLog = undoLogs[t.getId()];
undoLog.flushAppendBuffer();
return new Iterator<Change>() { return new Iterator<Change>() {
private long logId = maxLogId - 1; private long logId = maxLogId - 1;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论