Search in sources :

Example 6 with ComponentId

use of org.apache.jena.dboe.transaction.txn.ComponentId in project jena by apache.

the class Journal method _read.

// -- Journal write cycle.
// read one entry at the channel position.
// Move position to end of read.
private JournalEntry _read() {
    if (LOGGING) {
        log("read@%-3d >>", channel.position());
    }
    header.clear();
    int lenRead = channel.read(header);
    if (lenRead == -1) {
        // probably broken file.
        throw new TransactionException("Read off the end of a journal file");
    // return null;
    }
    if (lenRead != header.capacity())
        throw new TransactionException("Partial read of journal file");
    header.rewind();
    // Header: (length/4, crc/4, entry/4, component/16)
    int len = header.getInt();
    int checksum = header.getInt();
    header.putInt(posnCRC, 0);
    int entryType = header.getInt();
    byte[] bytes = new byte[ComponentId.SIZE];
    header.get(bytes);
    ComponentId component = ComponentId.create(null, bytes);
    Adler32 adler = new Adler32();
    adler.update(header.array());
    ByteBuffer bb = null;
    if (len > 0) {
        bb = ByteBuffer.allocate(len);
        lenRead = channel.read(bb);
        if (lenRead != len)
            throw new TransactionException("Failed to read the journal entry data: wanted " + len + " bytes, got " + lenRead);
        bb.rewind();
        adler.update(bb);
        bb.rewind();
    }
    int crc = (int) adler.getValue();
    if (checksum != crc)
        throw new TransactionException("Checksum error reading from the Journal. " + Integer.toHexString(checksum) + " / " + Integer.toHexString(crc));
    JournalEntryType type = JournalEntryType.type(entryType);
    JournalEntry entry = new JournalEntry(type, component, bb);
    if (LOGGING)
        log("read@%-3d >> %s", channel.position(), entry);
    return entry;
}
Also used : TransactionException(org.apache.jena.dboe.transaction.txn.TransactionException) ComponentId(org.apache.jena.dboe.transaction.txn.ComponentId) ByteBuffer(java.nio.ByteBuffer) Adler32(java.util.zip.Adler32)

Example 7 with ComponentId

use of org.apache.jena.dboe.transaction.txn.ComponentId 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 8 with ComponentId

use of org.apache.jena.dboe.transaction.txn.ComponentId in project jena by apache.

the class TestTransBinaryDataFileGeneral method createBinaryDataFile.

@Override
protected BinaryDataFile createBinaryDataFile() {
    // XXX Builder.
    journal = Journal.create(Location.mem());
    baseBinData = new BinaryDataFileMem();
    BufferChannel chan = FileFactory.createBufferChannelMem();
    ComponentId cid = ComponentId.allocLocal();
    transBinData = new TransBinaryDataFile(baseBinData, cid, chan);
    transBinData.open();
    transactional = TransactionalFactory.createTransactional(journal, transBinData);
    // Non-transactional usage of a disposed file.
    transactional.begin(ReadWrite.WRITE);
    return transBinData;
}
Also used : ComponentId(org.apache.jena.dboe.transaction.txn.ComponentId)

Example 9 with ComponentId

use of org.apache.jena.dboe.transaction.txn.ComponentId 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 10 with ComponentId

use of org.apache.jena.dboe.transaction.txn.ComponentId 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

ComponentId (org.apache.jena.dboe.transaction.txn.ComponentId)10 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)6 Journal (org.apache.jena.dboe.transaction.txn.journal.Journal)4 ByteBuffer (java.nio.ByteBuffer)3 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 Before (org.junit.Before)2 Adler32 (java.util.zip.Adler32)1 BlockMgr (org.apache.jena.dboe.base.block.BlockMgr)1 TransactionException (org.apache.jena.dboe.transaction.txn.TransactionException)1