Search in sources :

Example 1 with Transaction

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

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

the class TestTransactionLifecycle2 method txn_promote_thread_writer_3.

@Test
public void txn_promote_thread_writer_3() {
    Transaction txn1 = txnMgr.begin(TxnType.READ_PROMOTE);
    boolean b = txn1.promote();
    assertTrue(b);
    AtomicReference<Transaction> ref = new AtomicReference<>(txn1);
    ThreadLib.syncOtherThread(() -> {
        // Should fail.
        Transaction txn2 = txnMgr.begin(TxnType.WRITE, false);
        ref.set(txn2);
    });
    assertNull(ref.get());
    txn1.abort();
    txn1.end();
}
Also used : Transaction(org.apache.jena.dboe.transaction.txn.Transaction) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 3 with Transaction

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

the class TestTransactionLifecycle2 method txn_promote_thread_writer_2.

@Test
public void txn_promote_thread_writer_2() {
    Transaction txn1 = txnMgr.begin(TxnType.READ_PROMOTE);
    ThreadLib.syncOtherThread(() -> {
        Transaction txn2 = txnMgr.begin(TxnType.WRITE);
        txn2.abort();
        txn2.end();
    });
    boolean b = txn1.promote();
    assertTrue(b);
    // Now a writer.
    txn1.commit();
    txn1.end();
    checkClear();
}
Also used : Transaction(org.apache.jena.dboe.transaction.txn.Transaction) Test(org.junit.Test)

Example 4 with Transaction

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

the class TestTransactionLifecycle2 method txn_promote_thread_writer_1.

@Test
public void txn_promote_thread_writer_1() {
    Transaction txn1 = txnMgr.begin(TxnType.READ_PROMOTE);
    ThreadLib.syncOtherThread(() -> {
        Transaction txn2 = txnMgr.begin(TxnType.WRITE);
        txn2.commit();
        txn2.end();
    });
    boolean b = txn1.promote();
    assertFalse(b);
    txn1.end();
    checkClear();
}
Also used : Transaction(org.apache.jena.dboe.transaction.txn.Transaction) Test(org.junit.Test)

Example 5 with Transaction

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

the class TestTransactionLifecycle2 method txn_overlap_RR.

@Test
public void txn_overlap_RR() {
    Transaction txn1 = txnMgr.begin(TxnType.READ, false);
    assertNotNull(txn1);
    Transaction txn2 = txnMgr.begin(TxnType.READ, false);
    assertNotNull(txn2);
    txn1.commit();
    txn1.end();
    txn2.end();
    checkClear();
}
Also used : Transaction(org.apache.jena.dboe.transaction.txn.Transaction) Test(org.junit.Test)

Aggregations

Transaction (org.apache.jena.dboe.transaction.txn.Transaction)26 Test (org.junit.Test)21 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)2 TransactionCoordinator (org.apache.jena.dboe.transaction.txn.TransactionCoordinator)2 TransactionException (org.apache.jena.dboe.transaction.txn.TransactionException)2