From: <mar...@us...> - 2010-09-01 14:39:19
|
Revision: 3480 http://bigdata.svn.sourceforge.net/bigdata/?rev=3480&view=rev Author: martyncutcher Date: 2010-09-01 14:39:13 +0000 (Wed, 01 Sep 2010) Log Message: ----------- Add tests for AllocationContexts Modified Paths: -------------- branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java Modified: branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java 2010-09-01 14:27:44 UTC (rev 3479) +++ branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java 2010-09-01 14:39:13 UTC (rev 3480) @@ -44,7 +44,9 @@ import com.bigdata.journal.AbstractRestartSafeTestCase; import com.bigdata.journal.BufferMode; import com.bigdata.journal.DiskOnlyStrategy; +import com.bigdata.journal.IAllocationContext; import com.bigdata.journal.Journal; +import com.bigdata.journal.JournalShadow; import com.bigdata.journal.RWStrategy; import com.bigdata.journal.TestJournalBasics; import com.bigdata.journal.Journal.Options; @@ -380,10 +382,10 @@ RWStore rw = bufferStrategy.getRWStore(); ArrayList<Integer> sizes = new ArrayList<Integer>(); TreeMap<Long, Integer> paddrs = new TreeMap<Long, Integer>(); - for (int i = 0; i < 1000000; i++) { + for (int i = 0; i < 100000; i++) { int s = r.nextInt(250); sizes.add(s); - int a = rw.alloc(s); + int a = rw.alloc(s, null); long pa = rw.physicalAddress(a); assertTrue(paddrs.get(pa) == null); paddrs.put(pa, a); @@ -392,7 +394,7 @@ for (int i = 0; i < 50; i++) { int s = r.nextInt(500); sizes.add(s); - int a = rw.alloc(s); + int a = rw.alloc(s, null); long pa = rw.physicalAddress(a); paddrs.put(pa, a); } @@ -442,9 +444,9 @@ } long allocBatch(RWStore rw, int bsize, int asze, int ainc) { - long curAddress = rw.physicalAddress(rw.alloc(asze)); + long curAddress = rw.physicalAddress(rw.alloc(asze, null)); for (int i = 1; i < bsize; i++) { - int a = rw.alloc(asze); + int a = rw.alloc(asze, null); long nxt = rw.physicalAddress(a); assertTrue("Problem with index: " + i, (curAddress+ainc) == nxt || (nxt % 8192 == 0)); curAddress = nxt; @@ -460,7 +462,7 @@ r.nextBytes(batchBuffer); for (int i = 0; i < bsize; i++) { int as = base + r.nextInt(scope); - retaddrs[i] = (int) rw.alloc(batchBuffer, as); + retaddrs[i] = (int) rw.alloc(batchBuffer, as, null); } return retaddrs; @@ -499,12 +501,12 @@ private long reallocBatch(RWStore rw, int tsts, int sze, int grp) { long[] addr = new long[grp]; for (int i = 0; i < grp; i++) { - addr[i] = rw.alloc(sze); + addr[i] = rw.alloc(sze, null); } for (int t = 0; t < tsts; t++) { for (int i = 0; i < grp; i++) { long old = addr[i]; - addr[i] = rw.alloc(sze); + addr[i] = rw.alloc(sze, null); rw.free(old, sze); } } @@ -711,7 +713,6 @@ showStore(store); store.close(); - System.out.println("Re-open Journal"); store = (Journal) getStore(); showStore(store); @@ -843,11 +844,15 @@ // now delete the memory bs.delete(faddr); + // since deferred frees, we must commit in order to ensure the + // address in invalid, indicating it is available for + bs.commit(); + try { rdBuf = bs.read(faddr); // should fail with illegal state throw new RuntimeException("Fail"); } catch (Exception ise) { - assertTrue("Expected IllegalStateException", ise instanceof IllegalStateException); + assertTrue("Expected IllegalStateException reading from " + (faddr >> 32) + " instead got: " + ise, ise instanceof IllegalStateException); } } finally { @@ -932,9 +937,97 @@ store.destroy(); } } + + static class DummyAllocationContext implements IAllocationContext { + static int s_id = 23; + + int m_id = s_id++; - public void test_stressAlloc() { + public int compareTo(Object o) { + if (o instanceof DummyAllocationContext) { + return m_id - ((DummyAllocationContext) o).m_id; + } else { + return -1; + } + } + + public long minimumReleaseTime() { + return 0; // indicates immediate release + } + + } + + /** + * From a RWStore, creates multiple AllocationContexts to isolate + * updates, re-allocate storage and protect against by concurrent + * Contexts. This is the core functionality required to support + * Transactions. + * + * If an allocation is made for an AllocationContext then this will + * result in a ContextAllocation object being created in the RWStore + * within which "shadow" allocations can be made. If such a shadow + * allocation is deleted, within the AllocationContext, then this + * can be removed immediately. + * + * @throws IOException + */ + public void test_allocationContexts() throws IOException { + Journal store = (Journal) getStore(); + + RWStrategy bs = (RWStrategy) store.getBufferStrategy(); + + RWStore rw = bs.getRWStore(); + // JournalShadow shadow = new JournalShadow(store); + + // Create a couple of contexts + IAllocationContext allocContext1 = new DummyAllocationContext(); + IAllocationContext allocContext2 = new DummyAllocationContext(); + + int sze = 650; + byte[] buf = new byte[sze+4]; // extra for checksum + r.nextBytes(buf); + + long addr1a = bs.write(ByteBuffer.wrap(buf), allocContext1); + long addr1b = bs.write(ByteBuffer.wrap(buf), allocContext1); + rw.detachContext(allocContext1); + + + long addr2a = bs.write(ByteBuffer.wrap(buf), allocContext2); + long addr2b = bs.write(ByteBuffer.wrap(buf), allocContext2); + rw.detachContext(allocContext2); + + // Re-establish context + long addr1c = bs.write(ByteBuffer.wrap(buf), allocContext1); + + // By detaching contexts we end up using the same allocator + assertTrue("allocator re-use", bs.getPhysicalAddress(addr1c) > bs.getPhysicalAddress(addr2b)); + + // Now, prior to commit, try deleting an uncommitted allocation + bs.delete(addr1c, allocContext1); + // and re-allocating it from the same context + long addr1d = bs.write(ByteBuffer.wrap(buf), allocContext1); + + assertTrue("re-allocation", addr1c==addr1d); + + rw.detachContext(allocContext1); + + // Now commit + store.commit(); + + // now try deleting and re-allocating again, but in a global context + bs.delete(addr1d); // this should call deferFree + long addr1e = bs.write(ByteBuffer.wrap(buf), allocContext1); + + assertTrue("deferred-delete", addr1e != addr1d); + + // Now commit + store.commit(); + + } + + public void test_stressAlloc() { + Journal store = (Journal) getStore(); RWStrategy bs = (RWStrategy) store.getBufferStrategy(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2010-09-08 14:49:07
|
Revision: 3518 http://bigdata.svn.sourceforge.net/bigdata/?rev=3518&view=rev Author: martyncutcher Date: 2010-09-08 14:49:01 +0000 (Wed, 08 Sep 2010) Log Message: ----------- add stressAlloc and pureAlloc tests to test allocation structures for large stores Modified Paths: -------------- branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java Modified: branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java 2010-09-08 14:46:40 UTC (rev 3517) +++ branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java 2010-09-08 14:49:01 UTC (rev 3518) @@ -432,6 +432,11 @@ System.out.println("Final allocation: " + faddr + ", allocations: " + (rw.getTotalAllocations() - numAllocs) + ", allocated bytes: " + (rw.getTotalAllocationsSize() - startAllocations)); + + store.commit(); + + // Confirm that we can re-open the journal after commit + bufferStrategy.reopen(); } finally { store.destroy(); @@ -1018,7 +1023,7 @@ long realAddr = 0; try { // allocBatch(store, 1, 32, 650, 100000000); - allocBatch(store, 1, 32, 650, 100000); + allocBatch(store, 1, 32, 650, 5000000); store.commit(); System.out.println("Final allocations: " + rw.getTotalAllocations() + ", allocated bytes: " + rw.getTotalAllocationsSize() + ", file length: " @@ -1033,23 +1038,80 @@ } } - private long allocBatch(Journal store, int tsts, int min, int sze, int grp) { - - RWStrategy bs = (RWStrategy) store - .getBufferStrategy(); + /** + * The pureAlloc test is to test the allocation aspect of the memory + * management rather than worrying about writing the data + */ + public void test_pureAlloc() { + + Journal store = (Journal) getStore(); - byte[] buf = new byte[sze+4]; // extra for checksum - r.nextBytes(buf); - - - for (int i = 0; i < grp; i++) { - int alloc = min + r.nextInt(sze-min); - ByteBuffer bb = ByteBuffer.wrap(buf, 0, alloc); - bs.write(bb); - } + RWStrategy bs = (RWStrategy) store.getBufferStrategy(); - return 0L; - } + RWStore rw = bs.getRWStore(); + long realAddr = 0; + try { + // allocBatch(store, 1, 32, 650, 100000000); + pureAllocBatch(store, 1, 32, 3075, 300000); // cover wider range of blocks + store.commit(); + System.out.println("Final allocations: " + rw.getTotalAllocations() + + ", allocated bytes: " + rw.getTotalAllocationsSize() + ", file length: " + + rw.getStoreFile().length()); + store.close(); + System.out.println("Re-open Journal"); + store = (Journal) getStore(); + + showStore(store); + } finally { + store.destroy(); + } + } + + private long allocBatch(Journal store, int tsts, int min, int sze, int grp) { + + RWStrategy bs = (RWStrategy) store + .getBufferStrategy(); + + byte[] buf = new byte[sze+4]; // extra for checksum + r.nextBytes(buf); + + + for (int i = 0; i < grp; i++) { + int alloc = min + r.nextInt(sze-min); + ByteBuffer bb = ByteBuffer.wrap(buf, 0, alloc); + bs.write(bb); + } + + return 0L; + } + /* + * Allocate tests but save 50% to re-alloc + */ + private long pureAllocBatch(Journal store, int tsts, int min, int sze, int grp) { + + RWStrategy bs = (RWStrategy) store + .getBufferStrategy(); + + RWStore rw = bs.getRWStore(); + int freeAddr[] = new int[2048]; + int freeCurs = 0; + for (int i = 0; i < grp; i++) { + int alloc = min + r.nextInt(sze-min); + int addr = rw.alloc(alloc, null); + + if (i % 3 != 0) { //make avail 2 out of 3 for realloc + freeAddr[freeCurs++] = addr; + if (freeCurs == freeAddr.length) { + for (int f = 0; f < freeAddr.length; f++) { + rw.free(freeAddr[f], 0); + } + freeCurs = 0; + } + } + } + + return 0L; + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2010-11-04 15:01:49
|
Revision: 3892 http://bigdata.svn.sourceforge.net/bigdata/?rev=3892&view=rev Author: martyncutcher Date: 2010-11-04 15:01:43 +0000 (Thu, 04 Nov 2010) Log Message: ----------- Reduce some of the stress test parameters for automated tests Modified Paths: -------------- branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java Modified: branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java 2010-11-04 15:01:01 UTC (rev 3891) +++ branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java 2010-11-04 15:01:43 UTC (rev 3892) @@ -756,9 +756,9 @@ long startAllocations = rw.getTotalAllocationsSize(); int startBlob = 1024 * 256; int endBlob = 1024 * 1256; - int[] faddrs = allocBatchBuffer(rw, 500, startBlob, endBlob); + int[] faddrs = allocBatchBuffer(rw, 100, startBlob, endBlob); - System.out.println("Final allocation: " + rw.physicalAddress(faddrs[499]) + System.out.println("Final allocation: " + rw.physicalAddress(faddrs[99]) + ", allocations: " + (rw.getTotalAllocations() - numAllocs) + ", allocated bytes: " + (rw.getTotalAllocationsSize() - startAllocations)); } finally { @@ -1036,7 +1036,7 @@ // long realAddr = 0; try { // allocBatch(store, 1, 32, 650, 100000000); - allocBatch(store, 1, 32, 650, 5000000); + allocBatch(store, 1, 32, 650, 50000); store.commit(); System.out.println("Final allocations: " + rw.getTotalAllocations() + ", allocated bytes: " + rw.getTotalAllocationsSize() + ", file length: " This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2010-11-18 17:50:01
|
Revision: 3964 http://bigdata.svn.sourceforge.net/bigdata/?rev=3964&view=rev Author: thompsonbry Date: 2010-11-18 17:49:55 +0000 (Thu, 18 Nov 2010) Log Message: ----------- +1 for rnd.next(n) to avoid zero size allocs. Modified Paths: -------------- branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java Modified: branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java 2010-11-18 17:49:36 UTC (rev 3963) +++ branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java 2010-11-18 17:49:55 UTC (rev 3964) @@ -415,7 +415,7 @@ ArrayList<Integer> sizes = new ArrayList<Integer>(); TreeMap<Long, Integer> paddrs = new TreeMap<Long, Integer>(); for (int i = 0; i < 100000; i++) { - int s = r.nextInt(250); + int s = r.nextInt(250)+1; sizes.add(s); int a = rw.alloc(s, null); long pa = rw.physicalAddress(a); @@ -424,7 +424,7 @@ } for (int i = 0; i < 50; i++) { - int s = r.nextInt(500); + int s = r.nextInt(500)+1; sizes.add(s); int a = rw.alloc(s, null); long pa = rw.physicalAddress(a); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2010-11-29 09:55:10
|
Revision: 3986 http://bigdata.svn.sourceforge.net/bigdata/?rev=3986&view=rev Author: martyncutcher Date: 2010-11-29 09:55:04 +0000 (Mon, 29 Nov 2010) Log Message: ----------- Add allocation tests and adjust for history retention. Modified Paths: -------------- branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java Modified: branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java 2010-11-29 09:53:27 UTC (rev 3985) +++ branches/JOURNAL_HA_BRANCH/bigdata/src/test/com/bigdata/rwstore/TestRWJournal.java 2010-11-29 09:55:04 UTC (rev 3986) @@ -481,6 +481,33 @@ } + public void testAllocationReserves() { + final int cReserve16K = 16 * 1024; + final int cReserve128K = 32 * 1024; + + showAllocReserve(false, 64, cReserve16K, cReserve16K); + showAllocReserve(false, 128, cReserve16K, cReserve16K); + showAllocReserve(false, 1024, cReserve16K, cReserve16K); + showAllocReserve(false, 2048, cReserve16K, cReserve16K); + showAllocReserve(false, 3072, cReserve16K, cReserve16K); + showAllocReserve(false, 4096, cReserve16K, cReserve16K); + showAllocReserve(false, 8192, cReserve16K, cReserve16K); + + showAllocReserve(true, 64, cReserve128K, cReserve16K); + showAllocReserve(true, 128, cReserve128K, cReserve16K); + showAllocReserve(true, 1024, cReserve128K, cReserve16K); + showAllocReserve(true, 2048, cReserve128K, cReserve16K); + showAllocReserve(true, 3072, cReserve128K, cReserve16K); + showAllocReserve(true, 4096, cReserve16K, cReserve16K); + showAllocReserve(true, 8192, cReserve128K, cReserve16K); + } + private void showAllocReserve(final boolean optDensity, final int slotSize, final int reserve, final int mod) { + final int ints = FixedAllocator.calcBitSize(optDensity, slotSize, reserve, mod); + // there are max 126 ints available to a FixedAllocator + final int maxuse = (126/(ints+1)) * ints; + System.out.println("Allocate " + ints + ":" + (32 * ints * slotSize) + " for " + slotSize + " in " + reserve + " using " + maxuse + " of 126 possible"); + } + long allocBatch(RWStore rw, int bsize, int asze, int ainc) { long curAddress = rw.physicalAddress(rw.alloc(asze, null)); for (int i = 1; i < bsize; i++) { @@ -786,7 +813,7 @@ int[] faddrs = allocBatchBuffer(rw, 100, startBlob, endBlob); final StringBuilder str = new StringBuilder(); - rw.showAllocators(str); + rw.getStorageStats().showStats(str); System.out.println(str); } finally { @@ -844,8 +871,9 @@ /** * Test of blob allocation and read-back, firstly from cache and then from disk. + * @throws InterruptedException */ - public void test_blob_realloc() { + public void test_blob_realloc() throws InterruptedException { final Journal store = (Journal) getStore(); @@ -877,6 +905,7 @@ // allocate another address, might (or might not) be the same. faddr = bs.write(bb); // rw.alloc(buf, buf.length); + final long pa = bs.getPhysicalAddress(faddr); bb.position(0); System.out.println("Now commit to disk (1)"); @@ -892,8 +921,12 @@ // now delete the memory bs.delete(faddr); - // Must not have been immediately freed. - assertNotSame(0L, bs.getPhysicalAddress(faddr)); + // Must not have been immediately freed if history is retained. + if (rw.getHistoryRetention() != 0) + assertEquals(pa, bs.getPhysicalAddress(faddr)); + else + assertEquals(0L, bs.getPhysicalAddress(faddr)); + /* * Commit before testing for deferred frees. Since there is a @@ -906,6 +939,8 @@ store.commit(); + Thread.currentThread().sleep(10); + // Request release of deferred frees. rw.checkDeferredFrees(true/* freeNow */, store); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |