提交 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,36 +137,36 @@ public class TransactionMap<K, V> { ...@@ -137,36 +137,36 @@ 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) { MVMap<Object, Integer> temp = transaction.store
// re-fetch in case any transaction was committed now .createTempMap();
long size = map.sizeAsLong(); try {
MVMap<Object, Integer> temp = transaction.store Cursor cursor = new Cursor<Long, Object[]>(undoRootPage, null);
.createTempMap(); while (cursor.hasNext()) {
try { cursor.next();
for (Map.Entry<Long, Object[]> e : undo.entrySet()) { Object[] op = (Object[]) cursor.getValue();
Object[] op = e.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 continue;
continue; }
} @SuppressWarnings("unchecked")
@SuppressWarnings("unchecked") K key = (K) op[1];
K key = (K) op[1]; VersionedValue data = map.get(mapRootPage, key);
if (get(key) == null) { data = getValue(mapRootPage, undoRootPage, key, readLogId, data, committingTransactions);
Integer old = temp.put(key, 1); if (data == null || data.value == null) {
// count each key only once (there might be Integer old = temp.put(key, 1);
// multiple // count each key only once (there might be
// changes for the same key) // multiple
if (old == null) { // changes for the same key)
size--; if (old == null) {
} size--;
} }
} }
} finally {
transaction.store.store.removeMap(temp);
} }
return size; } finally {
transaction.store.store.removeMap(temp);
} }
return size;
} finally { } finally {
transaction.store.rwLock.readLock().unlock(); transaction.store.rwLock.readLock().unlock();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论