提交 3be159f0 authored 作者: Thomas Mueller's avatar Thomas Mueller

Bugfix (repeated changes to the same entry)

上级 16aede4d
......@@ -1062,11 +1062,7 @@ public class TransactionStore {
}
VersionedValue getValue(K key, long maxLog, VersionedValue data) {
;
// TODO test case for many updates within the same transaction
// TODO detect loops
for (int i = 0; i < 1000; i++) {
int tx;
while (true) {
if (data == null) {
// doesn't exist or deleted by a committed transaction
return null;
......@@ -1076,7 +1072,7 @@ public class TransactionStore {
// it is committed
return data;
}
tx = getTransactionId(id);
int tx = getTransactionId(id);
if (tx == transaction.transactionId) {
// added by this transaction
if (getLogId(id) < maxLog) {
......@@ -1095,6 +1091,22 @@ public class TransactionStore {
} else {
data = (VersionedValue) d[2];
}
// verify this is either committed,
// or the same transaction and earlier
if (data != null) {
long id2 = data.operationId;
if (id2 != 0) {
int tx2 = getTransactionId(id2);
if (tx2 != tx) {
// a different transaction
break;
}
if (getLogId(id2) > getLogId(id)) {
// newer than before
break;
}
}
}
}
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_TRANSACTION_CORRUPT,
......
......@@ -45,6 +45,7 @@ public class TestTransactionStore extends TestBase {
@Override
public void test() throws Exception {
FileUtils.createDirectories(getBaseDir());
testRepeatedChange();
testTransactionAge();
testStopWhileCommitting();
testGetModifiedMaps();
......@@ -57,6 +58,30 @@ public class TestTransactionStore extends TestBase {
testCompareWithPostgreSQL();
}
private void testRepeatedChange() {
MVStore s;
TransactionStore ts;
s = MVStore.open(null);
ts = new TransactionStore(s);
Transaction tx0 = ts.begin();
TransactionMap<Integer, Integer> map0 = tx0.openMap("data");
map0.put(1, -1);
tx0.commit();
Transaction tx = ts.begin();
TransactionMap<Integer, Integer> map = tx.openMap("data");
for (int i = 0; i < 2000; i++) {
map.put(1, i);
}
Transaction tx2 = ts.begin();
TransactionMap<Integer, Integer> map2 = tx2.openMap("data");
assertEquals(-1, map2.get(1).intValue());
s.close();
}
private void testTransactionAge() throws Exception {
MVStore s;
TransactionStore ts;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论