Search in sources :

Example 1 with BufferChannel

use of org.apache.jena.dboe.base.file.BufferChannel in project jena by apache.

the class BPlusTreeFactory method addLogging.

/**
 * Debugging
 */
public static BPlusTree addLogging(BPlusTree bpTree) {
    BufferChannel mgrRoot = null;
    BlockMgr mgr1 = bpTree.getNodeManager().getBlockMgr();
    BlockMgr mgr2 = bpTree.getRecordsMgr().getBlockMgr();
    mgr1 = new BlockMgrLogger(mgr1, false);
    mgr2 = new BlockMgrLogger(mgr2, false);
    return BPlusTreeFactory.rebuild(bpTree, mgrRoot, mgr1, mgr2);
}
Also used : BlockMgr(org.apache.jena.dboe.base.block.BlockMgr) BufferChannel(org.apache.jena.dboe.base.file.BufferChannel) BlockMgrLogger(org.apache.jena.dboe.base.block.BlockMgrLogger)

Example 2 with BufferChannel

use of org.apache.jena.dboe.base.file.BufferChannel in project jena by apache.

the class TestBPlusTreeRewriterNonTxn method runOneTest.

public static void runOneTest(int order, int N, RecordFactory recordFactory, boolean debug) {
    BPlusTreeParams bptParams = new BPlusTreeParams(order, recordFactory);
    BPlusTreeRewriter.debug = debug;
    // ---- Test data
    List<Record> originaldata = TestBPlusTreeRewriterNonTxn.createData(N, recordFactory);
    if (debug)
        System.out.println("Test data: " + originaldata);
    FileSet destination = FileSet.mem();
    // ---- Rewrite
    BufferChannel rootState = FileFactory.createBufferChannel(destination, Names.extBptState);
    // Write leaves to ...
    BlockMgr blkMgr1 = BlockMgrFactory.create(destination, Names.extBptTree, bptParams.getCalcBlockSize(), 10, 10);
    // Write nodes to ...
    BlockMgr blkMgr2 = BlockMgrFactory.create(destination, Names.extBptTree, bptParams.getCalcBlockSize(), 10, 10);
    BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(originaldata.iterator(), bptParams, recordFactory, rootState, blkMgr1, blkMgr2);
    if (debug) {
        BPlusTreeRewriterUtils.divider();
        bpt2.dump();
    }
    // ---- Checking
    bpt2.check();
    scanComparision(originaldata, bpt2);
    findComparison(originaldata, bpt2);
    sizeComparison(originaldata, bpt2);
}
Also used : BPlusTreeParams(org.apache.jena.dboe.trans.bplustree.BPlusTreeParams) FileSet(org.apache.jena.dboe.base.file.FileSet) BlockMgr(org.apache.jena.dboe.base.block.BlockMgr) BufferChannel(org.apache.jena.dboe.base.file.BufferChannel) Record(org.apache.jena.dboe.base.record.Record) BPlusTree(org.apache.jena.dboe.trans.bplustree.BPlusTree)

Example 3 with BufferChannel

use of org.apache.jena.dboe.base.file.BufferChannel in project jena by apache.

the class TestTransBlobPersistent method transBlobFile_1.

@Test
public void transBlobFile_1() throws Exception {
    Journal journal = Journal.create(Location.create(DIR));
    BufferChannel chan = BufferChannelFile.create(DATA);
    ComponentId cid = ComponentId.allocLocal();
    TransBlob transBlob = new TransBlob(cid, chan);
    Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob);
    String str = "Hello";
    TestTransBlob.write(transactional, transBlob, str);
    chan.close();
    journal.close();
    String s = FileUtils.readWholeFileAsUTF8(DATA);
    assertEquals(str, s);
}
Also used : BufferChannel(org.apache.jena.dboe.base.file.BufferChannel) Journal(org.apache.jena.dboe.transaction.txn.journal.Journal) ComponentId(org.apache.jena.dboe.transaction.txn.ComponentId) Transactional(org.apache.jena.dboe.transaction.Transactional)

Example 4 with BufferChannel

use of org.apache.jena.dboe.base.file.BufferChannel in project jena by apache.

the class TestTransBlobPersistent method transBlobFile_2.

@Test
public void transBlobFile_2() throws Exception {
    Journal journal = Journal.create(Location.create(DIR));
    BufferChannel chan = BufferChannelFile.create(DATA);
    ComponentId cid = ComponentId.allocLocal();
    TransBlob transBlob = new TransBlob(cid, chan);
    Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob);
    String str = "Hello1";
    Txn.executeWrite(transactional, () -> {
        transBlob.setString("one");
    });
    Txn.executeWrite(transactional, () -> {
        transBlob.setString("two");
    });
    chan.close();
    journal.close();
    String s = FileUtils.readWholeFileAsUTF8(DATA);
    assertEquals("two", s);
}
Also used : BufferChannel(org.apache.jena.dboe.base.file.BufferChannel) Journal(org.apache.jena.dboe.transaction.txn.journal.Journal) ComponentId(org.apache.jena.dboe.transaction.txn.ComponentId) Transactional(org.apache.jena.dboe.transaction.Transactional)

Example 5 with BufferChannel

use of org.apache.jena.dboe.base.file.BufferChannel in project jena by apache.

the class TestRecovery method recoverBlobFile_2.

@Test
public void recoverBlobFile_2() throws Exception {
    String str1 = "Recovery One";
    String str2 = "Recovery Two";
    ComponentId cid1 = ComponentId.allocLocal();
    ComponentId cid2 = ComponentId.allocLocal();
    // Write out a journal for two components.
    {
        Journal journal = Journal.create(Location.create(dir.getRoot().getAbsolutePath()));
        journal.write(JournalEntryType.REDO, cid1, IO.stringToByteBuffer(str1));
        journal.write(JournalEntryType.REDO, cid2, IO.stringToByteBuffer(str2));
        journal.writeJournal(JournalEntry.COMMIT);
        journal.close();
    }
    Journal journal = Journal.create(Location.create(dir.getRoot().getAbsolutePath()));
    BufferChannel chan = BufferChannelFile.create(data);
    TransBlob tBlob1 = new TransBlob(cid1, chan);
    TransBlob tBlob2 = new TransBlob(cid2, chan);
    TransactionCoordinator coord = new TransactionCoordinator(journal, Arrays.asList(tBlob1, tBlob2));
    coord.start();
    ByteBuffer blob1 = tBlob1.getBlob();
    assertNotNull(blob1);
    String s1 = IO.byteBufferToString(blob1);
    assertEquals(str1, s1);
    ByteBuffer blob2 = tBlob2.getBlob();
    assertNotNull(blob2);
    String s2 = IO.byteBufferToString(blob2);
    assertEquals(str2, s2);
    assertNotEquals(str1, str2);
    coord.shutdown();
}
Also used : TransBlob(org.apache.jena.dboe.trans.data.TransBlob) BufferChannel(org.apache.jena.dboe.base.file.BufferChannel) TransactionCoordinator(org.apache.jena.dboe.transaction.txn.TransactionCoordinator) Journal(org.apache.jena.dboe.transaction.txn.journal.Journal) ComponentId(org.apache.jena.dboe.transaction.txn.ComponentId) ByteBuffer(java.nio.ByteBuffer)

Aggregations

BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)15 BlockMgr (org.apache.jena.dboe.base.block.BlockMgr)6 ComponentId (org.apache.jena.dboe.transaction.txn.ComponentId)6 ByteBuffer (java.nio.ByteBuffer)5 Journal (org.apache.jena.dboe.transaction.txn.journal.Journal)4 FileSet (org.apache.jena.dboe.base.file.FileSet)3 Record (org.apache.jena.dboe.base.record.Record)3 BPlusTree (org.apache.jena.dboe.trans.bplustree.BPlusTree)3 BPlusTreeParams (org.apache.jena.dboe.trans.bplustree.BPlusTreeParams)3 StateMgrDataIdx (org.apache.jena.dboe.transaction.txn.StateMgrDataIdx)3 Test (org.junit.Test)3 RecordFactory (org.apache.jena.dboe.base.record.RecordFactory)2 TransBlob (org.apache.jena.dboe.trans.data.TransBlob)2 Transactional (org.apache.jena.dboe.transaction.Transactional)2 TransactionCoordinator (org.apache.jena.dboe.transaction.txn.TransactionCoordinator)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1