提交 9cc5ebee authored 作者: Andrei Tokar's avatar Andrei Tokar

Refactor code around append buffer locking

上级 5de4e30b
......@@ -1400,7 +1400,7 @@ public class MVStore implements AutoCloseable {
try {
ChunkIdsCollector collector = new ChunkIdsCollector(meta.getId());
long oldestVersionToKeep = getOldestVersionToKeep();
MVMap.RootReference rootReference = meta.getRoot();
MVMap.RootReference rootReference = meta.flushAndGetRoot();
if (fast) {
MVMap.RootReference previous;
while (rootReference.version >= oldestVersionToKeep && (previous = rootReference.previous) != null) {
......
......@@ -134,7 +134,7 @@ public final class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
int attempt = 0;
while(true) {
++attempt;
RootReference rootReference = getRoot();
RootReference rootReference = flushAndGetRoot();
Page p = rootReference.root.copy(true);
V result = operate(p, key, value, decisionMaker);
if (!p.isLeaf() && p.getTotalCount() == 0) {
......
......@@ -104,7 +104,7 @@ public class TransactionMap<K, V> extends AbstractMap<K, V> {
long undoLogSize;
do {
committingTransactions = store.committingTransactions.get();
mapRootReference = map.getRoot();
mapRootReference = map.flushAndGetRoot();
BitSet opentransactions = store.openTransactions.get();
undoLogRootReferences = new MVMap.RootReference[opentransactions.length()];
undoLogSize = 0;
......@@ -113,7 +113,7 @@ public class TransactionMap<K, V> extends AbstractMap<K, V> {
if (undoLog != null) {
MVMap.RootReference rootReference = undoLog.getRoot();
undoLogRootReferences[i] = rootReference;
undoLogSize += rootReference.root.getTotalCount() + rootReference.getAppendCounter();
undoLogSize += rootReference.getTotalCount();
}
}
} while(committingTransactions != store.committingTransactions.get() ||
......@@ -124,7 +124,7 @@ public class TransactionMap<K, V> extends AbstractMap<K, V> {
// should be considered as committed.
// Subsequent processing uses this snapshot info only.
Page mapRootPage = mapRootReference.root;
long size = mapRootPage.getTotalCount();
long size = mapRootReference.getTotalCount();
// if we are looking at the map without any uncommitted values
if (undoLogSize == 0) {
return size;
......@@ -240,6 +240,16 @@ public class TransactionMap<K, V> extends AbstractMap<K, V> {
return set(key, decisionMaker);
}
/**
* Appends entry to uderlying map. This method may be used concurrently,
* but latest appended values are not guaranteed to be visible.
* @param key should be higher in map's order than any existing key
* @param value to be appended
*/
public void append(K key, V value) {
map.append(key, VersionedValue.getInstance(transaction.log(map.getId(), key, null), value, null));
}
/**
* Lock row for the given key.
* <p>
......@@ -678,7 +688,7 @@ public class TransactionMap<K, V> extends AbstractMap<K, V> {
MVMap.RootReference mapRootReference;
do {
committingTransactions = store.committingTransactions.get();
mapRootReference = map.getRoot();
mapRootReference = map.flushAndGetRoot();
} while (committingTransactions != store.committingTransactions.get());
// Now we have a snapshot, where mapRootReference points to state of the map
// and committingTransactions mask tells us which of seemingly uncommitted changes
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论