Search in sources :

Example 1 with TransactionCoordinator

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

the class Indexer method stageIndex.

private void stageIndex(BlockingQueue<List<Tuple<NodeId>>> pipe, TupleIndex idx) {
    TransactionCoordinator coordinator = CoLib.newCoordinator();
    CoLib.add(coordinator, idx);
    CoLib.start(coordinator);
    Transaction transaction = coordinator.begin(TxnType.WRITE);
    boolean workHasBeenDone;
    try {
        Destination<Tuple<NodeId>> loader = loadTuples(idx);
        for (; ; ) {
            List<Tuple<NodeId>> tuples = pipe.take();
            if (tuples.isEmpty())
                break;
            loader.deliver(tuples);
        }
        workHasBeenDone = !idx.isEmpty();
        transaction.commit();
    } catch (Exception ex) {
        Log.error(this, "Interrupted", ex);
        transaction.abort();
        workHasBeenDone = false;
    }
    CoLib.finish(coordinator);
    if (workHasBeenDone)
        output.print("Finish - index %s", idx.getName());
    termination.release();
}
Also used : Transaction(org.apache.jena.dboe.transaction.txn.Transaction) TransactionCoordinator(org.apache.jena.dboe.transaction.txn.TransactionCoordinator) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 2 with TransactionCoordinator

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

the class IndexerInline method startBulk.

@Override
public void startBulk() {
    TransactionCoordinator coordinator = CoLib.newCoordinator();
    Arrays.stream(indexes).forEach(idx -> CoLib.add(coordinator, idx));
    CoLib.start(coordinator);
    transaction = coordinator.begin(TxnType.WRITE);
}
Also used : TransactionCoordinator(org.apache.jena.dboe.transaction.txn.TransactionCoordinator)

Example 3 with TransactionCoordinator

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

Example 4 with TransactionCoordinator

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

the class TestTxnLib2 method setup.

@Before
public void setup() {
    TransactionCoordinator coord = new TransactionCoordinator(Location.mem());
    integer = new TransactionalInteger(coord, InitValue);
    coord.start();
}
Also used : TransactionCoordinator(org.apache.jena.dboe.transaction.txn.TransactionCoordinator) Before(org.junit.Before)

Example 5 with TransactionCoordinator

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

the class TestTransactionCoordinatorControl method init.

@Before
public void init() {
    txnMgr = new TransactionCoordinator(Location.mem());
    unit = new TransactionalBase(txnMgr);
    txnMgr.start();
}
Also used : TransactionalBase(org.apache.jena.dboe.transaction.txn.TransactionalBase) TransactionCoordinator(org.apache.jena.dboe.transaction.txn.TransactionCoordinator) Before(org.junit.Before)

Aggregations

TransactionCoordinator (org.apache.jena.dboe.transaction.txn.TransactionCoordinator)11 Before (org.junit.Before)4 Journal (org.apache.jena.dboe.transaction.txn.journal.Journal)3 ByteBuffer (java.nio.ByteBuffer)2 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)2 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)2 TransBlob (org.apache.jena.dboe.trans.data.TransBlob)2 ComponentId (org.apache.jena.dboe.transaction.txn.ComponentId)2 Transaction (org.apache.jena.dboe.transaction.txn.Transaction)2 TransactionException (org.apache.jena.dboe.transaction.txn.TransactionException)1 TransactionalBase (org.apache.jena.dboe.transaction.txn.TransactionalBase)1 TransactionalSystem (org.apache.jena.dboe.transaction.txn.TransactionalSystem)1 TDBException (org.apache.jena.tdb2.TDBException)1 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)1