Java Code Examples for com.bigdata.journal.Journal#abort()

The following examples show how to use com.bigdata.journal.Journal#abort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
       * Verify that we correctly restore the RWStore commit state if
       * {@link RWStore#commit()} is followed by {@link RWStore#reset()}
       * rather than {@link RWStore#postCommit()}.
       * 
       * @see <a href="http://trac.blazegraph.com/ticket/973" >RWStore commit is
       *      not robust to internal failure.</a>
       */
public void test_commitState() {
	Journal store = (Journal) getStore();
          try {

          	final RWStrategy bs = (RWStrategy) store.getBufferStrategy();
          	
          	final RWStore rws = bs.getStore();
          	
          	final long addr = bs.write(randomData(78));

          	// do 1st half of the RWStore commit protocol.
          	rws.commit();
          	            	
          	// then discard write set.
          	store.abort();
          	
          	assertFalse(bs.isCommitted(addr)); // rolled back
          	
          	// now cycle standard commit to confirm correct reset
          	for (int c = 0; c < 50; c++) {
          		bs.write(randomData(78));
          		store.commit();
          	}
         	
          	
          } finally {
          	store.destroy();
          }
}
 
Example 2
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
       * Verify that a double-commit causes an illegal state exception.
       * Further verify that an {@link RWStore#reset()} allwos us to then
       * apply and commit new write sets.
       * 
       * @see <a href="http://trac.blazegraph.com/ticket/973" >RWStore commit is
       *      not robust to internal failure.</a>
       */
public void test_commitStateIllegal() {
	final Journal store = (Journal) getStore();
          try {

          final RWStrategy bs = (RWStrategy) store.getBufferStrategy();
          	
          	final RWStore rws = bs.getStore();
          	
          	bs.write(randomData(78));
          	
          	rws.commit();
          	
          	try {
          		store.commit();
          		
          		fail("Expected failure");
          	} catch (Exception ise) {
          		if (InnerCause.isInnerCause(ise, IllegalStateException.class)) {
           		store.abort();
           		
           		store.commit();
          		} else {
          			fail("Unexpected Exception");
          		}
          	}
         	
          	
          } finally {
          	store.destroy();
          }
}
 
Example 3
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void testSimpleUnisolatedAllocationContextRecycling() {
	
	final Journal store = (Journal) getStore(0);

	try {

		final RWStrategy bufferStrategy = (RWStrategy) store.getBufferStrategy();

		final RWStore rw = bufferStrategy.getStore();
		
		final IAllocationContext cntxt = rw.newAllocationContext(false /*Isolated*/); // Unisolated context
		
		// allocate three global addresses of different sizes
		final int sze1 = 48; // 64 bytes allocator
		final int sze2 = 72; // 128	
		final int sze3 = 135; // 256
		
		final int addr1 = rw.alloc(sze1, cntxt);
		final int addr2 = rw.alloc(sze2, cntxt);
		final int addr3 = rw.alloc(sze3, cntxt);
		
		// Commit the addresses
		store.commit();
		
		showAddress(rw, addr1);
		showAddress(rw, addr2);
		showAddress(rw, addr3);
		
		// Now create some allocation contexts
		final IAllocationContext iso_cntxt = rw.newAllocationContext(true /*Isolated*/); // Isolated context
		
		// now allocate a new unisolated address
		rw.alloc(sze1, cntxt);
		// free the originall
		rw.free(addr1,  sze1, cntxt);
		// and ensure that allocator is 'owned' by an iso
		rw.alloc(sze1, iso_cntxt);
		
		// now grab a pristine allocator
		rw.alloc(sze2,  iso_cntxt);
		// and free the original address (with the unisolated context)
		rw.free(addr2, sze2, cntxt);				
		
		if (log.isInfoEnabled()) {
			final StringBuilder str = new StringBuilder();
			rw.showAllocators(str);
			
			log.info(str);
		}	
		
		store.abort();
		
		log.info("ABORT");
		showAddress(rw, addr1);
		showAddress(rw, addr2);
		showAddress(rw, addr3);
		
		// This is the point that the AllocationContext ends up setting the free bits, iff we have committed after the abort.				
		rw.detachContext(iso_cntxt);
		
		log.info("DETACH");
		showAddress(rw, addr1);
		showAddress(rw, addr2);
		showAddress(rw, addr3);
		
		store.commit();
		
		log.info("COMMIT");
		showAddress(rw, addr1);
		showAddress(rw, addr2);
		showAddress(rw, addr3);
		
	} finally {
		store.destroy();
	}
}
 
Example 4
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
       * Test verifies that a failure to retain the commit state in
       * {@link RWStore#commit()} will cause problems if the write set is
       * discarded by {@link RWStore#reset()} such that subsequent write sets
       * run into persistent addressing errors.
       * 
       * @see <a href="http://trac.blazegraph.com/ticket/973" >RWStore commit is
       *      not robust to internal failure.</a>
       */
public void test_commitStateError() {
	final Journal store = (Journal) getStore();
          try {

          	final RWStrategy bs = (RWStrategy) store.getBufferStrategy();
          	
          	final RWStore rws = bs.getStore();
          	
          	final long addr = bs.write(randomData(78));
          	
          	// do first half of the RWStore protocol.
          	rws.commit();

          /*
           * remove the commit state such that subsequent abort()/reset()
           * will fail to correctly restore the pre-commit state.
           */
          rws.clearCommitStateRef();

          // abort() succeeds because it is allowed even if commit() was
          // not called.
          	store.abort();
          	
          	assertFalse(bs.isCommitted(addr)); // rolled back
          	
          	try {
           	// now cycle standard commit to force an error from bad reset
           	for (int c = 0; c < 50; c++) {
           		bs.write(randomData(78));
           		store.commit();
           	}
           	fail("Expected failure");
          	} catch (Exception e) {
          		// expected
          		log.info("Expected!");
          	}
         	
          } finally {
          	store.destroy();
          }
}
 
Example 5
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * State5
 * 
 * Allocate - Commit - Free - Commit
 * 
 * Tracks writeCache state through allocation
 */
public void test_allocCommitFreeCommitAllocSessionWriteCache() {
	final Journal store = (Journal) getStore();
          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();
          	
          	IRawTx tx = bs.newTx();
          	
          	bs.delete(addr);
          	
          	// since data is committed, should be accessible from any new
          	// readCommitted transaction
          	assertTrue(bs.inWriteCache(addr));

          	store.commit();
          	
          	// Since transactions are around the cache will not have been
          	//	cleared (and cannot be re-allocated)
          	assertTrue(bs.inWriteCache(addr));
          	
          	tx.close(); // Release Session
          	
          	// Cache must have been cleared
          	assertFalse(bs.inWriteCache(addr));
          	
          	final long addr2 = bs.write(randomData(78));
          	
          	assertTrue(addr2 == addr);
          	
          	assertTrue(bs.inWriteCache(addr));
          	
          	store.abort(); // removes uncommitted data
          	
          	assertFalse(bs.inWriteCache(addr));

          } finally {
          	store.destroy();
          }
}