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

Refactor code around append buffer locking

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