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

properly convert appendCounter

上级 97709e50
...@@ -962,14 +962,14 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -962,14 +962,14 @@ public class MVMap<K, V> extends AbstractMap<K, V>
*/ */
public final long sizeAsLong() { public final long sizeAsLong() {
RootReference rootReference = getRoot(); RootReference rootReference = getRoot();
return rootReference.root.getTotalCount() + rootReference.appendCounter; return rootReference.root.getTotalCount() + rootReference.getAppendCounter();
} }
@Override @Override
public boolean isEmpty() { public boolean isEmpty() {
RootReference rootReference = getRoot(); RootReference rootReference = getRoot();
Page rootPage = rootReference.root; Page rootPage = rootReference.root;
return rootPage.isLeaf() && rootPage.getKeyCount() == 0 && rootReference.appendCounter == 0; return rootPage.isLeaf() && rootPage.getKeyCount() == 0 && rootReference.getAppendCounter() == 0;
} }
public final long getCreateVersion() { public final long getCreateVersion() {
...@@ -1179,7 +1179,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1179,7 +1179,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
if (rootReference == null) { if (rootReference == null) {
rootReference = getRoot(); rootReference = getRoot();
} }
byte keyCount = rootReference.appendCounter; int keyCount = rootReference.getAppendCounter();
if (keyCount == 0) { if (keyCount == 0) {
break; break;
} }
...@@ -1192,7 +1192,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1192,7 +1192,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
break; break;
} }
} }
assert rootReference.appendCounter == 0; assert rootReference.getAppendCounter() == 0;
return rootReference; return rootReference;
} }
...@@ -1274,14 +1274,16 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1274,14 +1274,16 @@ public class MVMap<K, V> extends AbstractMap<K, V>
boolean success = false; boolean success = false;
while(!success) { while(!success) {
RootReference rootReference = getRoot(); RootReference rootReference = getRoot();
if (rootReference.appendCounter >= keysPerPage) { int appendCounter = rootReference.getAppendCounter();
if (appendCounter >= keysPerPage) {
rootReference = flushAppendBuffer(rootReference); rootReference = flushAppendBuffer(rootReference);
assert rootReference.appendCounter < keysPerPage; appendCounter = rootReference.getAppendCounter();
assert appendCounter < keysPerPage;
} }
keysBuffer[rootReference.appendCounter] = key; keysBuffer[appendCounter] = key;
valuesBuffer[rootReference.appendCounter] = value; valuesBuffer[appendCounter] = value;
RootReference updatedRootReference = new RootReference(rootReference, (byte) (rootReference.appendCounter + 1), ++attempt); RootReference updatedRootReference = new RootReference(rootReference, appendCounter + 1, ++attempt);
success = root.compareAndSet(rootReference, updatedRootReference); success = root.compareAndSet(rootReference, updatedRootReference);
} }
} }
...@@ -1296,8 +1298,9 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1296,8 +1298,9 @@ public class MVMap<K, V> extends AbstractMap<K, V>
boolean success; boolean success;
do { do {
RootReference rootReference = getRoot(); RootReference rootReference = getRoot();
if (rootReference.appendCounter > 0) { int appendCounter = rootReference.getAppendCounter();
RootReference updatedRootReference = new RootReference(rootReference, (byte) (rootReference.appendCounter - 1), ++attempt); if (appendCounter > 0) {
RootReference updatedRootReference = new RootReference(rootReference, appendCounter - 1, ++attempt);
success = root.compareAndSet(rootReference, updatedRootReference); success = root.compareAndSet(rootReference, updatedRootReference);
} else { } else {
assert rootReference.root.getKeyCount() > 0; assert rootReference.root.getKeyCount() > 0;
...@@ -1409,14 +1412,18 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1409,14 +1412,18 @@ public class MVMap<K, V> extends AbstractMap<K, V>
} }
// This one is used for append buffer maintance // This one is used for append buffer maintance
RootReference(RootReference r, byte appendCounter, int attempt) { RootReference(RootReference r, int appendCounter, int attempt) {
this.root = r.root; this.root = r.root;
this.version = r.version; this.version = r.version;
this.previous = r.previous; this.previous = r.previous;
this.updateCounter = r.updateCounter + 1; this.updateCounter = r.updateCounter + 1;
this.updateAttemptCounter = r.updateAttemptCounter + attempt; this.updateAttemptCounter = r.updateAttemptCounter + attempt;
this.lockedForUpdate = r.lockedForUpdate; this.lockedForUpdate = r.lockedForUpdate;
this.appendCounter = appendCounter; this.appendCounter = (byte)appendCounter;
}
public int getAppendCounter() {
return appendCounter & 0xff;
} }
@Override @Override
......
...@@ -90,7 +90,7 @@ public class TransactionMap<K, V> { ...@@ -90,7 +90,7 @@ public class TransactionMap<K, V> {
if (undoLog != null) { if (undoLog != null) {
MVMap.RootReference rootReference = undoLog.flushAppendBuffer(); MVMap.RootReference rootReference = undoLog.flushAppendBuffer();
undoLogRootReferences[i] = rootReference; undoLogRootReferences[i] = rootReference;
undoLogSize += rootReference.root.getTotalCount() + rootReference.appendCounter; undoLogSize += rootReference.root.getTotalCount() + rootReference.getAppendCounter();
} }
} }
} while(committingTransactions != store.committingTransactions.get() || } while(committingTransactions != store.committingTransactions.get() ||
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论