提交 03402e74 authored 作者: Thomas Mueller's avatar Thomas Mueller

Transaction store: re-use transaction ids, and they are not integer and no…

Transaction store: re-use transaction ids, and they are not integer and no longer long (work in progress)
上级 71888e43
...@@ -76,6 +76,11 @@ public class DataUtils { ...@@ -76,6 +76,11 @@ public class DataUtils {
*/ */
public static final int ERROR_TRANSACTION_LOCK_TIMEOUT = 101; public static final int ERROR_TRANSACTION_LOCK_TIMEOUT = 101;
/**
* A very old transaction is still open.
*/
public static final int ERROR_TRANSACTION_STILL_OPEN = 102;
/** /**
* The type for leaf page. * The type for leaf page.
*/ */
......
...@@ -45,6 +45,7 @@ public class TestTransactionStore extends TestBase { ...@@ -45,6 +45,7 @@ public class TestTransactionStore extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
FileUtils.createDirectories(getBaseDir()); FileUtils.createDirectories(getBaseDir());
testTransactionAge();
testStopWhileCommitting(); testStopWhileCommitting();
testGetModifiedMaps(); testGetModifiedMaps();
testKeyIterator(); testKeyIterator();
...@@ -55,6 +56,46 @@ public class TestTransactionStore extends TestBase { ...@@ -55,6 +56,46 @@ public class TestTransactionStore extends TestBase {
testSingleConnection(); testSingleConnection();
testCompareWithPostgreSQL(); testCompareWithPostgreSQL();
} }
private void testTransactionAge() throws Exception {
MVStore s;
TransactionStore ts;
s = MVStore.open(null);
ts = new TransactionStore(s);
ts.setMaxTransactionId(16);
for (int i = 0, j = 1; i < 64; i++) {
Transaction t = ts.begin();
assertEquals(j, t.getId());
t.commit();
j++;
if (j > 16) {
j = 1;
}
}
s = MVStore.open(null);
ts = new TransactionStore(s);
ts.setMaxTransactionId(16);
ArrayList<Transaction> fifo = New.arrayList();
int open = 0;
for (int i = 0; i < 64; i++) {
Transaction t = ts.begin();
if (open >= 16) {
try {
t.openMap("data").put(i, i);
fail();
} catch (IllegalStateException e) {
// expected - too many open
}
Transaction first = fifo.remove(0);
first.commit();
open--;
}
fifo.add(t);
open++;
t.openMap("data").put(i, i);
}
s.close();
}
private void testStopWhileCommitting() throws Exception { private void testStopWhileCommitting() throws Exception {
String fileName = getBaseDir() + "/testStopWhileCommitting.h3"; String fileName = getBaseDir() + "/testStopWhileCommitting.h3";
...@@ -342,7 +383,7 @@ public class TestTransactionStore extends TestBase { ...@@ -342,7 +383,7 @@ public class TestTransactionStore extends TestBase {
assertEquals(null, tx.getName()); assertEquals(null, tx.getName());
tx.setName("first transaction"); tx.setName("first transaction");
assertEquals("first transaction", tx.getName()); assertEquals("first transaction", tx.getName());
assertEquals(0, tx.getId()); assertEquals(1, tx.getId());
assertEquals(Transaction.STATUS_OPEN, tx.getStatus()); assertEquals(Transaction.STATUS_OPEN, tx.getStatus());
m = tx.openMap("test"); m = tx.openMap("test");
m.put("1", "Hello"); m.put("1", "Hello");
...@@ -350,6 +391,7 @@ public class TestTransactionStore extends TestBase { ...@@ -350,6 +391,7 @@ public class TestTransactionStore extends TestBase {
assertEquals(1, list.size()); assertEquals(1, list.size());
txOld = list.get(0); txOld = list.get(0);
assertTrue(tx.getId() == txOld.getId()); assertTrue(tx.getId() == txOld.getId());
assertEquals("first transaction", txOld.getName());
s.commit(); s.commit();
ts.close(); ts.close();
s.close(); s.close();
...@@ -357,14 +399,14 @@ public class TestTransactionStore extends TestBase { ...@@ -357,14 +399,14 @@ public class TestTransactionStore extends TestBase {
s = MVStore.open(fileName); s = MVStore.open(fileName);
ts = new TransactionStore(s); ts = new TransactionStore(s);
tx = ts.begin(); tx = ts.begin();
assertEquals(1, tx.getId()); assertEquals(2, tx.getId());
m = tx.openMap("test"); m = tx.openMap("test");
assertEquals(null, m.get("1")); assertEquals(null, m.get("1"));
m.put("2", "Hello"); m.put("2", "Hello");
list = ts.getOpenTransactions(); list = ts.getOpenTransactions();
assertEquals(2, list.size()); assertEquals(2, list.size());
txOld = list.get(0); txOld = list.get(0);
assertEquals(0, txOld.getId()); assertEquals(1, txOld.getId());
assertEquals(Transaction.STATUS_OPEN, txOld.getStatus()); assertEquals(Transaction.STATUS_OPEN, txOld.getStatus());
assertEquals("first transaction", txOld.getName()); assertEquals("first transaction", txOld.getName());
txOld.prepare(); txOld.prepare();
...@@ -376,17 +418,16 @@ public class TestTransactionStore extends TestBase { ...@@ -376,17 +418,16 @@ public class TestTransactionStore extends TestBase {
ts = new TransactionStore(s); ts = new TransactionStore(s);
tx = ts.begin(); tx = ts.begin();
m = tx.openMap("test"); m = tx.openMap("test");
// TransactionStore was not closed, so we lost some ids assertEquals(2, tx.getId());
assertEquals(65, tx.getId());
list = ts.getOpenTransactions(); list = ts.getOpenTransactions();
assertEquals(2, list.size()); assertEquals(2, list.size());
txOld = list.get(1); txOld = list.get(1);
assertEquals(1, txOld.getId()); assertEquals(2, txOld.getId());
assertEquals(Transaction.STATUS_OPEN, txOld.getStatus()); assertEquals(Transaction.STATUS_OPEN, txOld.getStatus());
assertEquals(null, txOld.getName()); assertEquals(null, txOld.getName());
txOld.rollback(); txOld.rollback();
txOld = list.get(0); txOld = list.get(0);
assertEquals(0, txOld.getId()); assertEquals(1, txOld.getId());
assertEquals(Transaction.STATUS_PREPARED, txOld.getStatus()); assertEquals(Transaction.STATUS_PREPARED, txOld.getStatus());
assertEquals("first transaction", txOld.getName()); assertEquals("first transaction", txOld.getName());
txOld.commit(); txOld.commit();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论