提交 05ad3781 authored 作者: andrei's avatar andrei

getSizeAsLong

上级 0b760740
...@@ -116,14 +116,14 @@ public class TransactionMap<K, V> { ...@@ -116,14 +116,14 @@ public class TransactionMap<K, V> {
Page undoRootPage = undoLogRootReference.root; Page undoRootPage = undoLogRootReference.root;
long undoLogSize = undoRootPage.getTotalCount(); long undoLogSize = undoRootPage.getTotalCount();
Page mapRootPage = mapRootReference.root; Page mapRootPage = mapRootReference.root;
long sizeRaw = mapRootPage.getTotalCount(); long size = mapRootPage.getTotalCount();
if (undoLogSize == 0) { if (undoLogSize == 0) {
return sizeRaw; return size;
} }
if (undoLogSize > sizeRaw) { if (undoLogSize > size) {
// the undo log is larger than the map - // the undo log is larger than the map -
// count the entries of the map // count the entries of the map
long size = 0; size = 0;
Cursor<K, VersionedValue> cursor = map.cursor(null); Cursor<K, VersionedValue> cursor = map.cursor(null);
while (cursor.hasNext()) { while (cursor.hasNext()) {
K key = cursor.next(); K key = cursor.next();
...@@ -137,14 +137,13 @@ public class TransactionMap<K, V> { ...@@ -137,14 +137,13 @@ public class TransactionMap<K, V> {
} }
// the undo log is smaller than the map - // the undo log is smaller than the map -
// scan the undo log and subtract invisible entries // scan the undo log and subtract invisible entries
synchronized (undo) {
// re-fetch in case any transaction was committed now
long size = map.sizeAsLong();
MVMap<Object, Integer> temp = transaction.store MVMap<Object, Integer> temp = transaction.store
.createTempMap(); .createTempMap();
try { try {
for (Map.Entry<Long, Object[]> e : undo.entrySet()) { Cursor cursor = new Cursor<Long, Object[]>(undoRootPage, null);
Object[] op = e.getValue(); while (cursor.hasNext()) {
cursor.next();
Object[] op = (Object[]) cursor.getValue();
int m = (Integer) op[0]; int m = (Integer) op[0];
if (m != mapId) { if (m != mapId) {
// a different map - ignore // a different map - ignore
...@@ -152,7 +151,9 @@ public class TransactionMap<K, V> { ...@@ -152,7 +151,9 @@ public class TransactionMap<K, V> {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
K key = (K) op[1]; K key = (K) op[1];
if (get(key) == null) { VersionedValue data = map.get(mapRootPage, key);
data = getValue(mapRootPage, undoRootPage, key, readLogId, data, committingTransactions);
if (data == null || data.value == null) {
Integer old = temp.put(key, 1); Integer old = temp.put(key, 1);
// count each key only once (there might be // count each key only once (there might be
// multiple // multiple
...@@ -166,7 +167,6 @@ public class TransactionMap<K, V> { ...@@ -166,7 +167,6 @@ public class TransactionMap<K, V> {
transaction.store.store.removeMap(temp); transaction.store.store.removeMap(temp);
} }
return size; return size;
}
} finally { } finally {
transaction.store.rwLock.readLock().unlock(); transaction.store.rwLock.readLock().unlock();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论