提交 b3e4cfa0 authored 作者: John M Bradley's avatar John M Bradley

Synchronize on undoLog when following MVMap get with TransactionMap getValue

上级 05015717
...@@ -933,9 +933,11 @@ public class TransactionStore { ...@@ -933,9 +933,11 @@ public class TransactionStore {
long size = 0; long size = 0;
Cursor<K, VersionedValue> cursor = map.cursor(null); Cursor<K, VersionedValue> cursor = map.cursor(null);
while (cursor.hasNext()) { while (cursor.hasNext()) {
VersionedValue data;
synchronized (transaction.store.undoLog) {
K key = cursor.next(); K key = cursor.next();
VersionedValue data = cursor.getValue(); data = getValue(key, readLogId, cursor.getValue());
data = getValue(key, readLogId, data); }
if (data != null && data.value != null) { if (data != null && data.value != null) {
size++; size++;
} }
...@@ -1197,9 +1199,11 @@ public class TransactionStore { ...@@ -1197,9 +1199,11 @@ public class TransactionStore {
} }
private VersionedValue getValue(K key, long maxLog) { private VersionedValue getValue(K key, long maxLog) {
synchronized (transaction.store.undoLog) {
VersionedValue data = map.get(key); VersionedValue data = map.get(key);
return getValue(key, maxLog, data); return getValue(key, maxLog, data);
} }
}
/** /**
* Get the versioned value for the given key. * Get the versioned value for the given key.
...@@ -1210,6 +1214,13 @@ public class TransactionStore { ...@@ -1210,6 +1214,13 @@ public class TransactionStore {
* @return the value * @return the value
*/ */
VersionedValue getValue(K key, long maxLog, VersionedValue data) { VersionedValue getValue(K key, long maxLog, VersionedValue data) {
if (MVStore.ASSERT) {
if (!Thread.holdsLock(transaction.store.undoLog)) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_INTERNAL,
"getValue not invoked while synchronized on undoLog");
}
}
while (true) { while (true) {
if (data == null) { if (data == null) {
// doesn't exist or deleted by a committed transaction // doesn't exist or deleted by a committed transaction
...@@ -1229,9 +1240,7 @@ public class TransactionStore { ...@@ -1229,9 +1240,7 @@ public class TransactionStore {
} }
// get the value before the uncommitted transaction // get the value before the uncommitted transaction
Object[] d; Object[] d;
synchronized (transaction.store.undoLog) {
d = transaction.store.undoLog.get(id); d = transaction.store.undoLog.get(id);
}
if (d == null) { if (d == null) {
// this entry should be committed or rolled back // this entry should be committed or rolled back
// in the meantime (the transaction might still be open) // in the meantime (the transaction might still be open)
...@@ -1441,6 +1450,7 @@ public class TransactionStore { ...@@ -1441,6 +1450,7 @@ public class TransactionStore {
private void fetchNext() { private void fetchNext() {
while (cursor.hasNext()) { while (cursor.hasNext()) {
K k; K k;
synchronized (transaction.store.undoLog) {
try { try {
k = cursor.next(); k = cursor.next();
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
...@@ -1473,6 +1483,7 @@ public class TransactionStore { ...@@ -1473,6 +1483,7 @@ public class TransactionStore {
return; return;
} }
} }
}
current = null; current = null;
currentKey = null; currentKey = null;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论