提交 15b5949c authored 作者: Andrei Tokar's avatar Andrei Tokar

proper locking in MVMap.clear()

上级 ed6c4be6
...@@ -822,6 +822,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -822,6 +822,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
} }
RootReference previous = currentRoot; RootReference previous = currentRoot;
int appendCounter = 0;
long updateCounter = 1; long updateCounter = 1;
long newVersion = INITIAL_VERSION; long newVersion = INITIAL_VERSION;
if(currentRoot != null) { if(currentRoot != null) {
...@@ -835,12 +836,13 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -835,12 +836,13 @@ public class MVMap<K, V> extends AbstractMap<K, V>
newVersion = currentRoot.version; newVersion = currentRoot.version;
previous = currentRoot.previous; previous = currentRoot.previous;
appendCounter = currentRoot.getAppendCounter();
updateCounter += currentRoot.updateCounter; updateCounter += currentRoot.updateCounter;
attemptUpdateCounter += currentRoot.updateAttemptCounter; attemptUpdateCounter += currentRoot.updateAttemptCounter;
} }
RootReference updatedRootReference = new RootReference(newRootPage, newVersion, previous, updateCounter, RootReference updatedRootReference = new RootReference(newRootPage, newVersion, previous, appendCounter,
attemptUpdateCounter); updateCounter, attemptUpdateCounter);
boolean success = root.compareAndSet(currentRoot, updatedRootReference); boolean success = root.compareAndSet(currentRoot, updatedRootReference);
return success ? updatedRootReference : null; return success ? updatedRootReference : null;
} }
...@@ -1416,14 +1418,14 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1416,14 +1418,14 @@ public class MVMap<K, V> extends AbstractMap<K, V>
*/ */
public final byte appendCounter; public final byte appendCounter;
RootReference(Page root, long version, RootReference previous, long updateCounter, long updateAttemptCounter) { RootReference(Page root, long version, RootReference previous, int appendCounter, long updateCounter, long updateAttemptCounter) {
this.root = root; this.root = root;
this.version = version; this.version = version;
this.previous = previous; this.previous = previous;
this.updateCounter = updateCounter; this.updateCounter = updateCounter;
this.updateAttemptCounter = updateAttemptCounter; this.updateAttemptCounter = updateAttemptCounter;
this.lockedForUpdate = false; this.lockedForUpdate = false;
this.appendCounter = 0; this.appendCounter = (byte)appendCounter;
} }
// This one is used for locking // This one is used for locking
......
...@@ -389,7 +389,7 @@ public class TransactionStore { ...@@ -389,7 +389,7 @@ public class TransactionStore {
*/ */
long addUndoLogRecord(int transactionId, long logId, Object[] undoLogRecord) { long addUndoLogRecord(int transactionId, long logId, Object[] undoLogRecord) {
MVMap<Long, Object[]> undoLog = undoLogs[transactionId]; MVMap<Long, Object[]> undoLog = undoLogs[transactionId];
Long undoKey = getOperationId(transactionId, logId); long undoKey = getOperationId(transactionId, logId);
if (logId == 0 && !undoLog.isEmpty()) { if (logId == 0 && !undoLog.isEmpty()) {
throw DataUtils.newIllegalStateException( throw DataUtils.newIllegalStateException(
DataUtils.ERROR_TOO_MANY_OPEN_TRANSACTIONS, DataUtils.ERROR_TOO_MANY_OPEN_TRANSACTIONS,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论