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;
}
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;
}
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;
}
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();
}
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);
}
Aggregations