AMQ-7084 - ensure allocated and unused free pages are visible to subsequent transactions, fix and test with test updates to reflect proper usage

(cherry picked from commit 8a1abd9bb2)
This commit is contained in:
gtully 2018-10-23 16:00:57 +01:00 committed by Christopher L. Shannon (cshannon)
parent a549ee6688
commit deb87353c4
6 changed files with 36 additions and 15 deletions

View File

@ -670,6 +670,8 @@ public class Transaction implements Iterable<Page> {
allocateList.clear();
writes.clear();
writeTransactionId = -1;
} else {
freePages(allocateList);
}
size = 0;
}
@ -692,6 +694,8 @@ public class Transaction implements Iterable<Page> {
allocateList.clear();
writes.clear();
writeTransactionId = -1;
} else {
freePages(allocateList);
}
size = 0;
}

View File

@ -57,11 +57,12 @@ public class BTreeIndexTest extends IndexTestSupport {
protected Index<String, Long> createIndex() throws Exception {
long id = tx.allocate().getPageId();
tx.commit();
BTreeIndex<String, Long> index = new BTreeIndex<String,Long>(pf, id);
index.setKeyMarshaller(StringMarshaller.INSTANCE);
index.setValueMarshaller(LongMarshaller.INSTANCE);
index.load(tx);
tx.commit();
return index;
}
@ -231,8 +232,6 @@ public class BTreeIndexTest extends IndexTestSupport {
this.index.load(tx);
long id = tx.allocate().getPageId();
tx.commit();
BTreeIndex<String, String> sindex = new BTreeIndex<String,String>(pf, id);
sindex.setKeyMarshaller(StringMarshaller.INSTANCE);
sindex.setValueMarshaller(StringMarshaller.INSTANCE);
@ -273,7 +272,6 @@ public class BTreeIndexTest extends IndexTestSupport {
this.index.load(tx);
long id = tx.allocate().getPageId();
tx.commit();
BTreeIndex<String, String> sindex = new BTreeIndex<String,String>(pf, id);
sindex.setKeyMarshaller(StringMarshaller.INSTANCE);
@ -364,7 +362,6 @@ public class BTreeIndexTest extends IndexTestSupport {
pf.load();
tx = pf.tx();
long id = tx.allocate().getPageId();
tx.commit();
BTreeIndex<Long, HashSet<String>> test = new BTreeIndex<Long, HashSet<String>>(pf, id);
test.setKeyMarshaller(LongMarshaller.INSTANCE);

View File

@ -27,12 +27,13 @@ public class HashIndexBenchMark extends IndexBenchmark {
Transaction tx = pf.tx();
long id = tx.allocate().getPageId();
tx.commit();
HashIndex<String, Long> index = new HashIndex<String, Long>(pf, id);
index.setKeyMarshaller(StringMarshaller.INSTANCE);
index.setValueMarshaller(LongMarshaller.INSTANCE);
index.load(tx);
tx.commit();
return index;
}

View File

@ -25,13 +25,12 @@ public class HashIndexTest extends IndexTestSupport {
protected Index<String, Long> createIndex() throws Exception {
long id = tx.allocate().getPageId();
tx.commit();
HashIndex<String, Long> index = new HashIndex<String,Long>(pf, id);
index.setBinCapacity(12);
index.setKeyMarshaller(StringMarshaller.INSTANCE);
index.setValueMarshaller(LongMarshaller.INSTANCE);
index.load(tx);
tx.commit();
return index;
}

View File

@ -57,12 +57,11 @@ public class ListIndexTest extends IndexTestSupport {
protected Index<String, Long> createIndex() throws Exception {
long id = tx.allocate().getPageId();
tx.commit();
ListIndex<String, Long> index = new ListIndex<String, Long>(pf, id);
index.setKeyMarshaller(StringMarshaller.INSTANCE);
index.setValueMarshaller(LongMarshaller.INSTANCE);
index.load(tx);
tx.commit();
return index;
}

View File

@ -142,7 +142,6 @@ public class PageFileTest extends TestCase {
Transaction tx = pf.tx();
Page page = tx.allocate();
tx.commit();
OutputStream pos = tx.openOutputStream(page, true);
DataOutputStream os = new DataOutputStream(pos);
@ -227,7 +226,7 @@ public class PageFileTest extends TestCase {
//Load a second instance on the same directory fo the page file which
//simulates an unclean shutdown from the previous run
PageFile pf2 = new PageFile(new File("target/test-data"), getName());
final PageFile pf2 = new PageFile(new File("target/test-data"), getName());
pf2.setEnableRecoveryFile(false);
pf2.load();
try {
@ -247,6 +246,28 @@ public class PageFileTest extends TestCase {
}
}
public void testAllocatedAndUnusedAreFree() throws Exception {
PageFile pf = new PageFile(new File("target/test-data"), getName());
pf.delete();
pf.load();
Transaction tx = pf.tx();
tx.allocate(10);
tx.commit();
assertEquals(10, pf.getPageCount());
assertEquals(pf.getFreePageCount(), 10);
// free pages should get reused
tx.allocate(10);
tx.rollback();
assertEquals(10, pf.getPageCount());
assertEquals(pf.getFreePageCount(), 10);
}
public void testBackgroundRecoveryIsThreadSafe() throws Exception {
PageFile pf = new PageFile(new File("target/test-data"), getName());