Search in sources :

Example 11 with BufferChannel

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

the class BPlusTreeFactory method addTracking.

/**
 * Debugging
 */
public static BPlusTree addTracking(BPlusTree bpTree) {
    BufferChannel mgrRoot = null;
    BlockMgr mgr1 = bpTree.getNodeManager().getBlockMgr();
    BlockMgr mgr2 = bpTree.getRecordsMgr().getBlockMgr();
    mgr1 = BlockTracker.track(mgr1);
    mgr2 = BlockTracker.track(mgr2);
    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)

Example 12 with BufferChannel

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

the class BPlusTreeFactory method makeMem.

/**
 * (Testing mainly) Make an in-memory B+Tree, with copy-in, copy-out block managers
 */
public static BPlusTree makeMem(String name, int order, int minDataRecords, int keyLength, int valueLength) {
    if (name == null)
        name = "Mem";
    BPlusTreeParams params = new BPlusTreeParams(order, keyLength, valueLength);
    int blkSize;
    if (minDataRecords > 0) {
        int maxDataRecords = 2 * minDataRecords;
        // int rSize = RecordBufferPage.HEADER+(maxRecords*params.getRecordLength());
        blkSize = RecordBufferPage.calcBlockSize(params.getRecordFactory(), maxDataRecords);
    } else
        blkSize = params.getCalcBlockSize();
    // By FileSet
    BufferChannel chan = BufferChannelMem.create(name + "(root)");
    BlockMgr mgr1 = BlockMgrFactory.createMem(name + "(nodes)", params.getCalcBlockSize());
    BlockMgr mgr2 = BlockMgrFactory.createMem(name + "(records)", blkSize);
    ComponentId cid = ComponentId.allocLocal();
    BPlusTree bpTree = BPlusTreeFactory.create(cid, params, chan, mgr1, mgr2);
    return bpTree;
}
Also used : BlockMgr(org.apache.jena.dboe.base.block.BlockMgr) BufferChannel(org.apache.jena.dboe.base.file.BufferChannel) ComponentId(org.apache.jena.dboe.transaction.txn.ComponentId)

Example 13 with BufferChannel

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

the class BPlusTreeFactory method createBPTree.

/**
 * Knowing all the parameters, create a B+Tree
 */
public static BPlusTree createBPTree(ComponentId cid, FileSet fileset, int order, int blockSize, int readCacheSize, int writeCacheSize, RecordFactory factory) {
    // ---- Checking
    if (blockSize < 0 && order < 0)
        throw new IllegalArgumentException("Neither blocksize nor order specified");
    if (blockSize >= 0 && order < 0)
        order = BPlusTreeParams.calcOrder(blockSize, factory.recordLength());
    if (blockSize >= 0 && order >= 0) {
        int order2 = BPlusTreeParams.calcOrder(blockSize, factory.recordLength());
        if (order != order2)
            throw new IllegalArgumentException("Wrong order (" + order + "), calculated = " + order2);
    }
    // Iffy - does not allow for slop.
    if (blockSize < 0 && order >= 0) {
        // Only in-memory.
        blockSize = BPlusTreeParams.calcBlockSize(order, factory);
    }
    BPlusTreeParams params = new BPlusTreeParams(order, factory);
    BufferChannel bptState = FileFactory.createBufferChannel(fileset, Names.extBptState);
    BlockMgr blkMgrNodes = BlockMgrFactory.create(fileset, Names.extBptTree, blockSize, readCacheSize, writeCacheSize);
    BlockMgr blkMgrRecords = BlockMgrFactory.create(fileset, Names.extBptRecords, blockSize, readCacheSize, writeCacheSize);
    return BPlusTreeFactory.create(cid, params, bptState, blkMgrNodes, blkMgrRecords);
}
Also used : BlockMgr(org.apache.jena.dboe.base.block.BlockMgr) BufferChannel(org.apache.jena.dboe.base.file.BufferChannel)

Example 14 with BufferChannel

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

the class TestRecovery method recoverBlobFile_1.

// Fake journal recovery.
@Test
public void recoverBlobFile_1() throws Exception {
    String str = "Hello Journal";
    ComponentId cid = ComponentId.allocLocal();
    // ComponentIdRegistry registry = new ComponentIdRegistry();
    // registry.register(cid, "Blob", 1);
    // Write out a journal.
    {
        Journal journal = Journal.create(Location.create(dir.getRoot().getAbsolutePath()));
        journal.write(JournalEntryType.REDO, cid, IO.stringToByteBuffer(str));
        journal.writeJournal(JournalEntry.COMMIT);
        journal.close();
    }
    TransactionCoordinator coord = new TransactionCoordinator(Location.create(dir.getRoot().getAbsolutePath()));
    BufferChannel chan = BufferChannelFile.create(data);
    TransBlob tBlob = new TransBlob(cid, chan);
    coord.add(tBlob);
    coord.start();
    ByteBuffer blob = tBlob.getBlob();
    assertNotNull(blob);
    String s = IO.byteBufferToString(blob);
    assertEquals(str, s);
    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)

Example 15 with BufferChannel

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

the class TestTransBlob method before.

@Before
public void before() {
    journal = Journal.create(Location.mem());
    BufferChannel chan = BufferChannelMem.create("TestTransBlob");
    ComponentId cid = ComponentId.allocLocal();
    transBlob = new TransBlob(cid, chan);
    transactional = TransactionalFactory.createTransactional(journal, transBlob);
}
Also used : BufferChannel(org.apache.jena.dboe.base.file.BufferChannel) ComponentId(org.apache.jena.dboe.transaction.txn.ComponentId) Before(org.junit.Before)

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