final RWStore rw = bs.getStore(); final ByteBuffer bb = ByteBuffer.wrap(buf, 0, szes[i]); if (i % 5 == 0) addr[i / 5] = bs.write(bb); long old = addr[i]; try { bs.read(old); } catch (Exception e) { throw new RuntimeException("problem handling read: " + i + " in test: " + t + " from address: " addr[i] = bs.write(bb); bb.flip(); bs.delete(old);
try { RWStrategy bs = (RWStrategy) store.getBufferStrategy(); final IAllocationContext isolated = bs.newAllocationContext(true); final long addr = bs.write(randomData(78)); final long addr2 = bs.write(randomData(78)); assertTrue(bs.inWriteCache(addr)); bs.delete(addr); final long addr3 = bs.write(randomData(78)); assertTrue(bs.inWriteCache(addr3)); bs.delete(addr2, isolated); final long addr4 = bs.write(randomData(78), isolated); assertTrue(bs.inWriteCache(addr4)); bs.abort(); assertTrue(bs.inWriteCache(addr)); // not removed in reset assertFalse(bs.inWriteCache(addr3)); // unisolated removed assertTrue(bs.inWriteCache(addr4)); // isolated remains try { bs.read(addr3); fail("Exception expected"); } catch (IllegalArgumentException e) { bs.detachContext(isolated);
public void close() { // throw exception if open per the API. assertOpen(); m_store.close(); }
public void test_allocCommitFreeWithHistory() { final Journal store = (Journal) getStore(4); try { final RWStrategy bs = (RWStrategy) store.getBufferStrategy(); final long addr = bs.write(randomData(78)); store.commit(); bs.delete(addr); assertTrue(bs.isCommitted(addr)); } finally { store.destroy(); } }
void showStore(final Journal store) { final RWStrategy bufferStrategy = (RWStrategy) store.getBufferStrategy(); final RWStore rw = bufferStrategy.getStore(); if (log.isInfoEnabled()) log.info("Fixed Allocators: " + rw.getFixedAllocatorCount() + ", heap allocated: " + rw.getFileStorage() + ", utilised bytes: " + rw.getAllocatedSlots() + ", file length: " + rw.getStoreFile().length()); }
final RWStrategy bs = (RWStrategy) store.getBufferStrategy(); final long addr = bs.write(randomData(78)); assertTrue(bs.inWriteCache(addr)); bs.delete(addr); final long addr2 = bs.write(randomData(78)); assertTrue(bs.inWriteCache(addr2)); bs.abort(); assertTrue(bs.inWriteCache(addr)); // not removed in reset assertFalse(bs.inWriteCache(addr2)); try { bs.read(addr2); fail("Exception expected"); } catch (IllegalArgumentException e) { assertTrue(bs.isCommitted(addr)); } finally { store.destroy();
public void testSimpleReset() { final Properties properties = new Properties(getProperties()); final Journal store = (Journal) getStore(properties); try { final RWStrategy bs = (RWStrategy) store.getBufferStrategy(); final RWStore rw = bs.getStore(); for (int r = 0; r < 10; r++) { ArrayList<Long> addrs = new ArrayList<Long>(); for (int i = 0; i < 1000; i++) { addrs.add(bs.write(randomData(2048))); } rw.reset(); } final String fname = bs.getStore().getStoreFile().getAbsolutePath(); store.close(); } finally { store.destroy(); } }
final RWStrategy bs = (RWStrategy) store.getBufferStrategy(); final RWStore rw = bs.getStore(); r.nextBytes(buf); final long addr1a = bs.write(ByteBuffer.wrap(buf), allocContext1); final long addr1b = bs.write(ByteBuffer.wrap(buf), allocContext1); rw.detachContext(allocContext1); final long addr2a = bs.write(ByteBuffer.wrap(buf), allocContext2); final long addr2b = bs.write(ByteBuffer.wrap(buf), allocContext2); rw.detachContext(allocContext2); bs.write(ByteBuffer.wrap(buf), allocContext1); fail("Should have failed to re-use detached context"); } catch (IllegalStateException ise) { final long addr1c = bs.write(ByteBuffer.wrap(buf), allocContext3); assertTrue("allocator re-use", bs.getPhysicalAddress(addr1c) > bs.getPhysicalAddress(addr2b)); bs.delete(addr1c, allocContext3); final long addr1d = bs.write(ByteBuffer.wrap(buf), allocContext3); bs.delete(addr1d); // this should call deferFree final long addr1e = bs.write(ByteBuffer.wrap(buf));
final RWStrategy bs = (RWStrategy) store.getBufferStrategy(); final long addr = bs.write(randomData(78)); assertTrue(bs.inWriteCache(addr)); IRawTx tx = bs.newTx(); bs.delete(addr); assertTrue(bs.inWriteCache(addr)); assertTrue(bs.inWriteCache(addr)); assertFalse(bs.inWriteCache(addr));
public void test_allocCommitFreeCommitWriteCacheWithHistory() { final Journal store = (Journal) getStore(5); try { final RWStrategy bs = (RWStrategy) store.getBufferStrategy(); final long addr = bs.write(randomData(78)); // Has just been written so must be in cache assertTrue(bs.inWriteCache(addr)); store.commit(); bs.delete(addr); // since data is committed, should be accessible from any new // readCommitted transaction assertTrue(bs.inWriteCache(addr)); store.commit(); // Since state is retained, the delete is deferred assertTrue(bs.inWriteCache(addr)); } finally { store.destroy(); } }
final RWStore rws = bs.getStore(); final long addr = bs.write(randomData(78)); assertFalse(bs.isCommitted(addr)); // rolled back bs.write(randomData(78)); store.commit();
public void test_multiVoidCommit() { final Journal store = (Journal) getStore(); try { final RWStrategy bs = (RWStrategy) store.getBufferStrategy(); final RWStore rw = bs.getStore(); final boolean initRequire = bs.requiresCommit(store.getRootBlockView()); assertTrue(initRequire); for (int n = 0; n < 20; n++) { store.commit(); final IRootBlockView rbv = store.getRootBlockView(); assertTrue(1 == rbv.getCommitCounter()); assertFalse(bs.requiresCommit(store.getRootBlockView())); assertFalse(rw.requiresCommit()); } } finally { store.destroy(); } }
public long write(final ByteBuffer data) { return write(data, null); }
@Override public IAllocationContext newAllocationContext(final boolean isolated) { if (_bufferStrategy instanceof RWStrategy) { return ((RWStrategy) _bufferStrategy).newAllocationContext(isolated); } else { return null; } } }
public void delete(final long addr) { delete(addr, null/* IAllocationContext */); }
_bufferStrategy = new RWStrategy(fileMetadata, quorum); _bufferStrategy = new RWStrategy(fileMetadata, quorum);