com.bigdata.journal.Journal Java Examples

The following examples show how to use com.bigdata.journal.Journal. 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: TestDistinctTermScanOp.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
* Create and populate relation in the {@link #namespace}.
* 
* FIXME The {@link DistinctTermAdvancer} is IV specific code. We need to
* use a R(elation) and E(lement) type that use IVs to write this test.
*/
  private void loadData(final Journal store) {

      // create the relation.
      final R rel = new R(store, namespace, ITx.UNISOLATED, new Properties());
      rel.create();

      // data to insert.
      final E[] a = {//
              new E("John", "Mary"),// 
              new E("Mary", "Paul"),// 
              new E("Paul", "Leon"),// 
              new E("Leon", "Paul"),// 
              new E("Mary", "John"),// 
      };

      // insert data (the records are not pre-sorted).
      rel.insert(new ChunkedArrayIterator<E>(a.length, a, null/* keyOrder */));

      // Do commit since not scale-out.
      store.commit();

  }
 
Example #2
Source File: TestPipelineJoin.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create and populate relation in the {@link #namespace}.
 */
private void loadData(final Journal store) {

    // create the relation.
    final R rel = new R(store, namespace, ITx.UNISOLATED, new Properties());
    rel.create();

    // data to insert.
    final E[] a = {//
            new E("John", "Mary"),// 
            new E("Mary", "Paul"),// 
            new E("Paul", "Leon"),// 
            new E("Leon", "Paul"),// 
            new E("Mary", "John"),// 
    };

    // insert data (the records are not pre-sorted).
    rel.insert(new ChunkedArrayIterator<E>(a.length, a, null/* keyOrder */));

    // Do commit since not scale-out.
    store.commit();

}
 
Example #3
Source File: AbstractBigdataGraphTestCase.java    From database with GNU General Public License v2.0 6 votes vote down vote up
protected Properties getProperties() {
        
        final Properties p = new Properties();

        p.setProperty(Journal.Options.BUFFER_MODE,
                BufferMode.MemStore.toString());
        
        /*
         * TODO Test both triples and quads.
         * 
         * Note: We need to use different data files for quads (trig). If we use
         * trig for a triples mode kb then we get errors (context bound, but not
         * quads mode).
         */
        p.setProperty(BigdataSail.Options.TRIPLES_MODE, "true");
//        p.setProperty(BigdataSail.Options.QUADS_MODE, "true");
        p.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE, "false");

        return p;
        
    }
 
Example #4
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * State1
 * 
 * Allocate - Commit - Free
 * 
 * assert that allocation remains committed
 */
public void test_allocCommitFree() {
	Journal store = (Journal) getStore();
          try {

          	RWStrategy bs = (RWStrategy) store.getBufferStrategy();
          	
          	final long addr = bs.write(randomData(78));
          	
          	store.commit();
          	
          	bs.delete(addr);
          	
          	assertTrue(bs.isCommitted(addr));
          } finally {
          	store.destroy();
          }
}
 
Example #5
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 6 votes vote down vote up
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();
			}
		}
 
Example #6
Source File: TestMemStore.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public void test_allocCommitFree() {
	final Journal store = getJournal(getProperties());
	try {

		MemStrategy bs = (MemStrategy) store.getBufferStrategy();
          	
          	final long addr = bs.write(randomData(78));
          	
          	store.commit();
          	
          	bs.delete(addr);
          	
          	assertTrue(bs.isCommitted(addr));
          } finally {
          	store.destroy();
          }
}
 
Example #7
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test low level RWStore add/removeAddress methods as used in HA
 * WriteCache replication to ensure Allocation consistency
 * 
 * @throws IOException
 */
public void testStressReplication() throws IOException {

	// Create a couple of stores with temp files
	final Journal store1 = (Journal) getStore();
	final Journal store2 = (Journal) getStore();
	try {		
		final RWStore rw1 = ((RWStrategy) store1.getBufferStrategy()).getStore();
		final RWStore rw2 = ((RWStrategy) store2.getBufferStrategy()).getStore();
	
		assertTrue(rw1 != rw2);
		
		final Random r = new Random();
		
		for (int i = 0; i < 100000; i++) {
			final int sze = 1 + r.nextInt(2000);
			final int addr = rw1.alloc(sze, null);
			rw2.addAddress(addr, sze);
		}
	} finally {
		store1.destroy();
		store2.destroy();
	}
}
 
Example #8
Source File: BigdataSail.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create or open a database instance configured using the specified
 * properties.
 * 
 * @see Options
 */
public BigdataSail(final Properties properties) {
    
    this(properties.getProperty(Options.NAMESPACE,Options.DEFAULT_NAMESPACE), new Journal(properties));

    closeOnShutdown = true;
    
    if(!exists()) {
        // Create iff it does not exist (backward compatibility, simple constructor mode).
        try {
            create(properties);
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }
                }

}
 
Example #9
Source File: TestConcurrentKBCreate.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
  * Verify that the named kb exists.
  * 
  * @throws SailException
  */
private void assertKBExists(final Journal jnl, final String namespace)
      throws RepositoryException, SailException {
   // Attempt to discover the KB instance.
   BigdataSailRepositoryConnection conn = null;
   try {
      // Request query connection.
      conn = getQueryConnection(jnl, namespace, ITx.READ_COMMITTED);
      // Verify KB exists.
      assertNotNull(namespace, conn);
   } finally {
      // Ensure connection is closed.
      if (conn != null)
         conn.close();
   }
}
 
Example #10
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public void test_snapshotData() throws IOException {
	final Journal journal = (Journal) getStore(0); // remember no history!

	try {
		for (int i = 0; i < 100; i++)
			commitSomeData(journal);

		final AtomicReference<IRootBlockView> rbv = new AtomicReference<IRootBlockView>();
		final Iterator<ISnapshotEntry> data = journal.snapshotAllocationData(rbv).entries();

		while (data.hasNext()) {
			final ISnapshotEntry e = data.next();
			
			log.info("Position: " + e.getAddress() + ", data size: "
					+ e.getData().length);
		}
	} finally {
		journal.destroy();
	}
}
 
Example #11
Source File: BasicRepositoryProvider.java    From tinkerpop3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Open and initialize a BigdataSailRepository using the supplied config
 * properties.  You must specify a journal file in the properties.
 * 
 * @param props
 *          config properties
 * @return
 *          an open and initialized repository
 */
public static BigdataSailRepository open(final Properties props) {
    if (props.getProperty(Journal.Options.FILE) == null) {
        throw new IllegalArgumentException();
    }
    
    final BigdataSail sail = new BigdataSail(props);
    final BigdataSailRepository repo = new BigdataSailRepository(sail);
    Code.wrapThrow(() -> repo.initialize());
    return repo;
}
 
Example #12
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * State3
 * 
 * Allocate - Commit - Free - Commit
 * 
 * Tracks writeCache state through allocation
 */
public void test_allocCommitFreeCommitWriteCache() {
	Journal store = (Journal) getStore();
          try {
          	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();
          	
          	// If no transactions are around (which they are not) then must
          	//	be released as may be re-allocated
          	assertFalse(bs.inWriteCache(addr));
          	
          } finally {
          	store.destroy();
          }
}
 
Example #13
Source File: TestServiceWhiteList.java    From database with GNU General Public License v2.0 5 votes vote down vote up
protected Properties getTripleStoreProperties() {
	 final Properties tripleStoreProperties = new Properties();
     {
         
         tripleStoreProperties.setProperty(BigdataSail.Options.TRIPLES_MODE,
                 "true");
         
         tripleStoreProperties.setProperty(Journal.Options.BUFFER_MODE,
                    BufferMode.MemStore.name());
         
      }
     
     return tripleStoreProperties;
}
 
Example #14
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
		 * Test of blob allocation, does not check on read back, just the
		 * allocation
		 */
		public void test_blob_allocs() {
//			if (false) {
//				return;
//			}

			final Journal store = (Journal) getStore();

			try {

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

				final RWStore rw = bufferStrategy.getStore();
				final long numAllocs = rw.getTotalAllocations();
				final long startAllocations = rw.getTotalAllocationsSize();
				final int startBlob = 1024 * 256;
				final int endBlob = 1024 * 1256;
				final int[] faddrs = allocBatchBuffer(rw, 100, startBlob, endBlob);

                if (log.isInfoEnabled()) {
                    final StringBuilder str = new StringBuilder();
                    rw.showAllocators(str);
                    log.info(str);
				}
			} finally {

				store.destroy();

			}

		}
 
Example #15
Source File: TestMemStore.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Can be tested by removing RWStore call to journal.removeCommitRecordEntries
 * in freeDeferrals.
 * 
 * final int commitPointsRemoved = journal.removeCommitRecordEntries(fromKey, toKey);
 * 
 * replaced with
 * 
 * final int commitPointsRemoved = commitPointsRecycled;
 * 
 */
public void testVerifyCommitRecordIndex() {
          final Properties properties = new Properties(getProperties());

          properties.setProperty(
                  AbstractTransactionService.Options.MIN_RELEASE_AGE, "400");

	final Journal store = getJournal(properties);
          try {

          	MemStrategy bs = (MemStrategy) store.getBufferStrategy();
          	      	
       	for (int r = 0; r < 10; r++) {
        	ArrayList<Long> addrs = new ArrayList<Long>();
        	for (int i = 0; i < 100; i++) {
        		addrs.add(bs.write(randomData(45)));
        	}
        	store.commit();

        	for (long addr : addrs) {
        		bs.delete(addr);
        	}

           	store.commit();
           	
       	}
       	
       	// Age the history (of the deletes!)
       	Thread.currentThread().sleep(400);
       	
       	verifyCommitIndex(store, 20);
       	
       	store.close();
       	
         } catch (InterruptedException e) {
	} finally {
          	store.destroy();
          }
}
 
Example #16
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public void testResetHARootBlock() {
          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)));
        	}
        	store.commit();
        	
        	final StorageStats stats1 = rw.getStorageStats();
        	
        	rw.resetFromHARootBlock(store.getRootBlockView());
        	
        	final StorageStats stats2 = rw.getStorageStats();

        	// Now check that we can read all allocations after reset
        	for (long addr : addrs) {
        		store.read(addr);
        	}

       	}
       	
		final String fname = bs.getStore().getStoreFile().getAbsolutePath();
		
       	store.close();
       	
		} finally {
          	store.destroy();
          }
}
 
Example #17
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test low level RWStore add/removeAddress methods as used in HA
 * WriteCache replication to ensure Allocation consistency
 * 
 * @throws IOException
 */
public void testSimpleReplication() throws IOException {

	// Create a couple of stores with temp files
	Journal store1 = (Journal) getStore();
	Journal store2 = (Journal) getStore();
	
	final RWStore rw1 = ((RWStrategy) store1.getBufferStrategy()).getStore();
	final RWStore rw2 = ((RWStrategy) store2.getBufferStrategy()).getStore();

	assertTrue(rw1 != rw2);
	
	final int addr1 = rw1.alloc(123, null);
	rw2.addAddress(addr1, 123);
	assertTrue(rw1.physicalAddress(addr1) == rw2.physicalAddress(addr1));
	
	rw1.free(addr1, 123);
	rw2.removeAddress(addr1);
	
	// address will still be valid
	assertTrue(rw1.physicalAddress(addr1) == rw2.physicalAddress(addr1));
	
	// confirm address re-cycled
	assert(addr1 == rw1.alloc(123, null));
	
	// and can be "re-added"
	rw2.addAddress(addr1, 123);
}
 
Example #18
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Can be tested by removing RWStore call to journal.removeCommitRecordEntries
 * in freeDeferrals.
 * 
 * final int commitPointsRemoved = journal.removeCommitRecordEntries(fromKey, toKey);
 * 
 * replaced with
 * 
 * final int commitPointsRemoved = commitPointsRecycled;
 * 
 */
public void testVerifyCommitRecordIndex() {
          final Properties properties = new Properties(getProperties());

          properties.setProperty(
                  AbstractTransactionService.Options.MIN_RELEASE_AGE, "100");

	final Journal store = (Journal) getStore(properties);
          try {

          	RWStrategy bs = (RWStrategy) store.getBufferStrategy();
          	      	
       	for (int r = 0; r < 10; r++) {
        	ArrayList<Long> addrs = new ArrayList<Long>();
        	for (int i = 0; i < 100; i++) {
        		addrs.add(bs.write(randomData(45)));
        	}
        	store.commit();

        	for (long addr : addrs) {
        		bs.delete(addr);
        	}

           	store.commit();
           	
        	// Age the history (of the deletes!)
        	Thread.currentThread().sleep(200);
       	}
       	
		final String fname = bs.getStore().getStoreFile().getAbsolutePath();
		
       	store.close();
       	
       	VerifyCommitRecordIndex.main(new String[]{fname});
      	
          } catch (InterruptedException e) {
	} finally {
          	store.destroy();
          }
}
 
Example #19
Source File: BigdataConnectionTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Overridden to destroy the backend database and its files on the disk.
     */
    @Override
    public void tearDown() throws Exception
    {

        final IIndexManager backend = testRepository == null ? null
                : ((BigdataSailRepository) testRepository).getSail()
                        .getIndexManager();

        /*
         * Note: The code in the block below was taken verbatim from
         * super.testDown() in order to explore a tear down issue in testOpen().
         */
        super.tearDown();
//        {
//            
//            testCon2.close();
//            testCon2 = null;
//
//            testCon.close();
//            testCon = null;
//
//            testRepository.shutDown();
//            testRepository = null;
//
//            vf = null;
//
//        }

        if (backend != null) {
            if(log.isInfoEnabled() && backend instanceof Journal)
                log.info(QueryEngineFactory.getInstance().getExistingQueryController((Journal)backend).getCounters());
            backend.destroy();
        }

    }
 
Example #20
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * State2
 * 
 * Allocate - Commit - Free - Commit
 * 
 * assert that allocation is no longer committed
 */
public void test_allocCommitFreeCommit() {
	Journal store = (Journal) getStore();
          try {

          	RWStrategy bs = (RWStrategy) store.getBufferStrategy();
          	
          	final long addr = bs.write(randomData(78));
          	
          	store.commit();
          	
          	bs.delete(addr);
          	
          	assertTrue(bs.isCommitted(addr));

          	store.commit();

          	assertFalse(bs.isCommitted(addr));
          } finally {
          	store.destroy();
          }
}
 
Example #21
Source File: TestNanoSparqlServer.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setUp() throws Exception {

        log.warn("Setting up test:" + getName());
        
        final Properties journalProperties = new Properties();
        {
            journalProperties.setProperty(Journal.Options.BUFFER_MODE,
                    BufferMode.MemStore.name());
        }

        // guaranteed distinct namespace for the KB instance.
        namespace = getName() + UUID.randomUUID();

        m_indexManager = new Journal(journalProperties);
        
        // Properties for the KB instance.  
        final Properties tripleStoreProperties = this.getTripleStoreProperties();

        // Create the triple store instance.
//        final AbstractTripleStore tripleStore = createTripleStore(m_indexManager,
//                namespace, tripleStoreProperties);
         AbstractApiTask.submitApiTask(m_indexManager,
               new CreateKBTask(namespace, tripleStoreProperties)).get();

        // Override namespace.  Do not create the default KB.
        final Map<String, String> initParams = new LinkedHashMap<String, String>();
        {

            initParams.put(ConfigParams.NAMESPACE, namespace);

            initParams.put(ConfigParams.CREATE, "false");
            
        }

        // Start server for that kb instance.
        m_fixture = NanoSparqlServer.newInstance(0/* port */,
                m_indexManager, initParams);

        m_fixture.start();

//        final WebAppContext wac = NanoSparqlServer.getWebApp(m_fixture);
//
//        wac.start();
//
//        for (Map.Entry<String, String> e : initParams.entrySet()) {
//
//            wac.setInitParameter(e.getKey(), e.getValue());
//
//        }

        final int port = NanoSparqlServer.getLocalPort(m_fixture);

        // log.info("Getting host address");

        final String hostAddr = NicUtil.getIpAddress("default.nic", "default",
                true/* loopbackOk */);

        if (hostAddr == null) {

            fail("Could not identify network address for this host.");

        }

        m_rootURL = new URL("http", hostAddr, port, ""/* contextPath */
        ).toExternalForm();

        m_serviceURL = new URL("http", hostAddr, port,
                BigdataStatics.getContextPath()).toExternalForm();

        if (log.isInfoEnabled())
            log.info("Setup done: \nname=" + getName() + "\nnamespace="
                    + namespace + "\nrootURL=" + m_rootURL + "\nserviceURL="
                    + m_serviceURL);

       	m_client = HttpClientConfigurator.getInstance().newInstance();
        
        m_repo = new RemoteRepositoryManager(m_serviceURL, m_client,
                m_indexManager.getExecutorService());

    }
 
Example #22
Source File: Node.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Visits the children (recursively) using post-order traversal, but does
 * NOT visit this node.
 */
@SuppressWarnings("unchecked")
private Iterator<AbstractNode> postOrderIterator2(final byte[] fromKey,
        final byte[] toKey) {

    /*
     * Iterator visits the direct children, expanding them in turn with a
     * recursive application of the post-order iterator.
     * 
     * When dirtyNodesOnly is true we use a child iterator that makes a best
     * effort to only visit dirty nodes. Especially, the iterator MUST NOT
     * force children to be loaded from disk if the are not resident since
     * dirty nodes are always resident.
     * 
     * The iterator must touch the node in order to guarentee that a node
     * will still be dirty by the time that the caller visits it. This
     * places the node onto the hard reference queue and increments its
     * reference counter. Evictions do NOT cause IO when the reference is
     * non-zero, so the node will not be made persistent as a result of
     * other node touches. However, the node can still be made persistent if
     * the caller explicitly writes the node onto the store.
     */

    // BTree.log.debug("node: " + this);
    return new Striterator(childIterator(fromKey, toKey))
            .addFilter(new Expander() {

                private static final long serialVersionUID = 1L;

                /*
                 * Expand each child in turn.
                 */
                protected Iterator expand(final Object childObj) {

                    /*
                     * A child of this node.
                     */

                    final AbstractNode child = (AbstractNode) childObj;

                    if (child instanceof Node) {

                        /*
                         * The child is a Node (has children).
                         * 
                         * Visit the children (recursive post-order
                         * traversal).
                         */

                        // BTree.log.debug("child is node: " + child);
                        final Striterator itr = new Striterator(
                                ((Node) child).postOrderIterator2(fromKey,
                                        toKey));

                        // append this node in post-order position.
                        itr.append(new SingleValueIterator(child));

                       /*
                        * Note: getReadExecutor() is not defined for IJournal. If
                        * we want to support the read executor pre-fetch pattern
                        * then the code needs to be updated to use IJournal and
                        * IJournal needs to expose getReadExecutor.
                        */
                        if ((btree.store instanceof Journal)
                                && (((Journal) btree.store)
                                        .getReadExecutor() != null)) {

                            /*
                             * Prefetch any child leaves we need to visit
                             * and prefetch the right sibling of the node we
                             * are about to visit if the iterator will span
                             * that node as well.
                             */
                            prefetchChildLeaves((Node) child, fromKey,
                                    toKey);

                        }

                        return itr;

                    } else {

                        /*
                         * The child is a leaf.
                         */

                        // BTree.log.debug("child is leaf: " + child);
                        
                        // Visit the leaf itself.
                        return new SingleValueIterator(child);

                    }
                }
            });

}
 
Example #23
Source File: Node.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
     * If the caller's <i>toKey</i> is GT the separator keys for the children of
     * this node then the iterator will need to visit the rightSibling of the
     * node and this method will schedule the memoization of the node's
     * rightSibling in order to reduce the IO latency when the iterator visit
     * that rightSibling (non-blocking).
     * 
     * @param node
     *            A node.
     * @param toKey
     *            The exclusive upper bound of some iterator.
     */
    protected void prefetchRightSibling(final Node node, final byte[] toKey) {
        
        final int nkeys = node.getKeyCount();

        final byte[] lastSeparatorKey = node.getKeys().get(nkeys - 1);

        if (BytesUtil.compareBytes(toKey, lastSeparatorKey) <= 0) {

            /*
             * Since the toKey is LTE to the lastSeparatorKey on this node the
             * last tuple to be visited by the iterator is spanned by this node
             * and we will not visit the node's rightSibling.
             * 
             * @todo This test could be optimized if IRaba exposed a method for
             * unsigned byte[] comparisons against the coded representation of
             * the keys.
             */

            return;

        }

        // The parent of this node.
        final Node p = node.parent.get();

//        /*
//         * Test to see if the rightSibling is already materialized.
//         */
//        
//        Note: Don't bother testing as we will test in the task below anyway.
//        
//        Node rightSibling = (Node) p.getRightSibling(node,
//                false/* materialize */);
//
//        if (rightSibling != null) {
//
//            /*
//             * The rightSibling is already materialized and getRightSibling()
//             * touches the rightSibling as a side-effect so it will be retained
//             * longer. Return now as there is nothing to do.
//             */
//
//            return;
//            
//        }

        /*
         * Submit a task which will materialize that right sibling.
         * 
         * Note: This task will only materialize a rightSibling of a common
         * parent. If [node] is the last child of the parent [p] then you would
         * need to ascend to the parent of [p] and then desend again, which is
         * not the specified behavior for getRightSibling(). Since this is just
         * an optimization for IO scheduling, I think that it is fine as it is.
         * 
         * Note: We do not track the future of this task. The task will have a
         * side effect on the parent/child weak references among the nodes in
         * the B+Tree, on the backing hard reference ring buffer, and on the
         * cache of materialized disk records. That side effect is all that we
         * are seeking.
         * 
         * Note: If the B+Tree is concurrently closed, then this task will error
         * out.  That is fine.
         */
        final Executor s = ((Journal) btree.store).getReadExecutor();

        s.execute(new Runnable() {

            public void run() {

                if (!p.btree.isOpen()) {

                    // No longer open.
                    return;
                    
                }

                // Materialize the right sibling.
                p.getRightSibling(node, true/* materialize */);

            }

        });

    }
 
Example #24
Source File: TestMultiTenancyAPI.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test verifies prepared properties 
 * do not contain blacklisted properties. 
 */
public void test_PropertiesBlackList() throws Exception {
	
	String namespace = "newNamespace";

    Properties properties = new Properties();

    properties.put(RemoteRepository.OPTION_CREATE_KB_NAMESPACE, namespace);

    assertTrue(MultiTenancyServlet.PROPERTIES_BLACK_LIST.contains(Journal.Options.FILE));

    properties.put(Journal.Options.FILE, Boolean.TRUE.toString());

    final Properties p = m_mgr.getPreparedProperties(namespace, properties);
    
    for (String property : MultiTenancyServlet.PROPERTIES_BLACK_LIST) {

    	assertFalse(p.containsKey(property));
    	
    }
           
}
 
Example #25
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 #26
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 #27
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Repeats the BlobBlobHeader of deferred frees, but also with blob data.
 */
public void test_stressBlobBlobHeaderBlobDataDeferredFrees() {

          final Properties properties = new Properties(getProperties());

          properties.setProperty(
                  AbstractTransactionService.Options.MIN_RELEASE_AGE, "4000");

          final int maxFixed = 3; // 192 bytes (3 * 64)
          properties.setProperty(RWStore.Options.ALLOCATION_SIZES,
          		"1,2," + maxFixed);
          
          final int maxAlloc = maxFixed * 64;
          final int leafEntries = maxAlloc / 8;
          final int headerEntries = maxAlloc / 4;
          final int threshold = headerEntries * leafEntries;
          
          final int nallocs = threshold << 3; // 8 times greater than allocation threshold

	Journal store = (Journal) getStore(properties);
          try {

          	RWStrategy bs = (RWStrategy) store.getBufferStrategy();
          	
          	ArrayList<Long> addrs = new ArrayList<Long>();
          	for (int i = 0; i < nallocs; i++) {
          		addrs.add(bs.write(randomData(1024))); // mostly blob data
          	}
          	store.commit();

          	for (long addr : addrs) {
          		bs.delete(addr);
          	}
              for (int i = 0; i < nallocs; i++) {
                  if(!bs.isCommitted(addrs.get(i))) {
                      fail("i="+i+", addr="+addrs.get(i));
                  }
              }

             	store.commit();
             	
          	// Age the history (of the deletes!)
          	Thread.currentThread().sleep(6000);
          	
          	// modify store but do not allocate similar size block
          	// as that we want to see has been removed
             	final long addr2 = bs.write(randomData(1024)); // modify store
          	
          	store.commit();
          	bs.delete(addr2); // modify store
             	store.commit();
          	
             	// delete is actioned
          	for (int i = 0; i < nallocs; i++) {
                 	assertFalse(bs.isCommitted(addrs.get(i)));
          	}
            } catch (InterruptedException e) {
	} finally {
          	store.destroy();
          }
}
 
Example #28
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 4 votes vote down vote up
void doBlobDeferredFrees(final int cAddrs) {

			final Properties properties = new Properties(getProperties());

            properties.setProperty(
                    AbstractTransactionService.Options.MIN_RELEASE_AGE, "4000");

            properties.setProperty(RWStore.Options.ALLOCATION_SIZES,
                    "1,2,3,5,8,12,16"); // 1K

			final Journal store = (Journal) getStore(properties);
            try {

            	final RWStrategy bs = (RWStrategy) store.getBufferStrategy();
            	
            	final ArrayList<Long> addrs = new ArrayList<Long>();
            	for (int i = 0; i < cAddrs; i++) {
            		addrs.add(bs.write(randomData(45)));
            	}
            	store.commit();

            	for (long addr : addrs) {
            		bs.delete(addr);
            	}
                for (int i = 0; i < cAddrs; i++) {
                    if(!bs.isCommitted(addrs.get(i))) {
                        fail("i="+i+", addr="+addrs.get(i));
                    }
                }

               	store.commit();
               	
            	// Age the history (of the deletes!)
            	Thread.currentThread().sleep(6000);
            	
            	// modify store but do not allocate similar size block
            	// as that we want to see has been removed
               	final long addr2 = bs.write(randomData(220)); // modify store
            	
            	store.commit();
            	bs.delete(addr2); // modify store
               	store.commit();
            	
               	// delete is actioned
            	for (int i = 0; i < 4000; i++) {
                   	assertFalse(bs.isCommitted(addrs.get(i)));
            	}
              } catch (InterruptedException e) {
			} finally {
            	store.destroy();
            }
		}
 
Example #29
Source File: TestRWJournal.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This test releases over a blobs worth of deferred frees where the
 * blob requires a blob header.
 * 
 * To test this we use a max fixed alloc of 192 bytes, so 24 8 bytes addresses can be stored
 * in each "leaf" and 48 leaves can be addressed in a standard blob header.
 * 
 * This should set the allocation threshold at 48 * 24 = 1152 deferred addresses
 * 
 * Anything greater than that requires that the blob header itself is a blob and this is
 * what we need to test.
 */
public void test_stressBlobBlobHeaderDeferredFrees() {

          final Properties properties = new Properties(getProperties());

          properties.setProperty(
                  AbstractTransactionService.Options.MIN_RELEASE_AGE, "4000");

          final int maxFixed = 3; // 192 bytes (3 * 64)
          properties.setProperty(RWStore.Options.ALLOCATION_SIZES,
          		"1,2," + maxFixed);
          
          final int maxAlloc = maxFixed * 64;
          final int leafEntries = maxAlloc / 8;
          final int headerEntries = maxAlloc / 4;
          final int threshold = headerEntries * leafEntries;
          
          final int nallocs = threshold << 3; // 8 times greater than allocation threshold

	Journal store = (Journal) getStore(properties);
          try {

          	RWStrategy bs = (RWStrategy) store.getBufferStrategy();
          	
          	ArrayList<Long> addrs = new ArrayList<Long>();
          	for (int i = 0; i < nallocs; i++) {
          		addrs.add(bs.write(randomData(45)));
          	}
          	store.commit();

          	for (long addr : addrs) {
          		bs.delete(addr);
          	}
              for (int i = 0; i < nallocs; i++) {
                  if(!bs.isCommitted(addrs.get(i))) {
                      fail("i="+i+", addr="+addrs.get(i));
                  }
              }

             	store.commit();
             	
          	// Age the history (of the deletes!)
          	Thread.currentThread().sleep(6000);
          	
          	// modify store but do not allocate similar size block
          	// as that we want to see has been removed
             	final long addr2 = bs.write(randomData(220)); // modify store
          	
          	store.commit();
          	bs.delete(addr2); // modify store
             	store.commit();
          	
             	// delete is actioned
          	for (int i = 0; i < nallocs; i++) {
                 	assertFalse(bs.isCommitted(addrs.get(i)));
          	}
            } catch (InterruptedException e) {
	} finally {
          	store.destroy();
          }
}
 
Example #30
Source File: TestNativeDistinctFilter.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public JoinSetup(final String kbNamespace) {

            if (kbNamespace == null)
                throw new IllegalArgumentException();
            
            final Properties properties = new Properties();

            properties.setProperty(Journal.Options.BUFFER_MODE,
                    BufferMode.Transient.toString());
            
            jnl = new Journal(properties);

            // create the kb.
            final AbstractTripleStore kb = new LocalTripleStore(jnl,
                    kbNamespace, ITx.UNISOLATED, properties);

            kb.create();

            this.spoNamespace = kb.getSPORelation().getNamespace();

            // Setup the vocabulary.
            {
                final BigdataValueFactory vf = kb.getValueFactory();
                final String uriString = "http://bigdata.com/";
                final BigdataURI _knows = vf.asValue(FOAFVocabularyDecl.knows);
                final BigdataURI _brad = vf.createURI(uriString+"brad");
                final BigdataURI _john = vf.createURI(uriString+"john");
                final BigdataURI _fred = vf.createURI(uriString+"fred");
                final BigdataURI _mary = vf.createURI(uriString+"mary");
                final BigdataURI _paul = vf.createURI(uriString+"paul");
                final BigdataURI _leon = vf.createURI(uriString+"leon");
                final BigdataURI _luke = vf.createURI(uriString+"luke");

                final BigdataValue[] a = new BigdataValue[] {
                      _knows,//
                      _brad,
                      _john,
                      _fred,
                      _mary,
                      _paul,
                      _leon,
                      _luke
                };

                kb.getLexiconRelation()
                        .addTerms(a, a.length, false/* readOnly */);

                knows = _knows.getIV();
                brad = _brad.getIV();
                john = _john.getIV();
                fred = _fred.getIV();
                mary = _mary.getIV();
                paul = _paul.getIV();
                leon = _leon.getIV();
                luke = _luke.getIV();

            }

//            // data to insert (in key order for convenience).
//            final SPO[] a = {//
//                    new SPO(paul, knows, mary, StatementEnum.Explicit),// [0]
//                    new SPO(paul, knows, brad, StatementEnum.Explicit),// [1]
//                    
//                    new SPO(john, knows, mary, StatementEnum.Explicit),// [2]
//                    new SPO(john, knows, brad, StatementEnum.Explicit),// [3]
//                    
//                    new SPO(mary, knows, brad, StatementEnum.Explicit),// [4]
//                    
//                    new SPO(brad, knows, fred, StatementEnum.Explicit),// [5]
//                    new SPO(brad, knows, leon, StatementEnum.Explicit),// [6]
//            };
//
//            // insert data (the records are not pre-sorted).
//            kb.addStatements(a, a.length);
//
//            // Do commit since not scale-out.
//            jnl.commit();

        }