Search in sources :

Example 6 with TransactionCoordinator

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

the class StoreConnection method internalExpel.

/**
 * Use via {@link TDBInternal#expel} wherever possible.
 * <p>
 * Stop managing a location.<br/>
 * Use with great care (testing only).
 */
public static synchronized void internalExpel(Location location, boolean force) {
    StoreConnection sConn = cache.get(location);
    if (sConn == null)
        return;
    TransactionCoordinator txnCoord = sConn.getDatasetGraphTDB().getTxnSystem().getTxnMgr();
    if (!force && txnCoord.countActive() > 0)
        throw new TransactionException("Can't expel: Active transactions for location: " + location);
    // No transactions at this point
    // (or we don't care and are clearing up forcefully.)
    sConn.getDatasetGraphTDB().shutdown();
    // Done by DatasetGraphTDB()
    // txnCoord.shutdown();
    sConn.isValid = false;
    cache.remove(location);
    // Release the lock after the cache is emptied.
    if (SystemTDB.DiskLocationMultiJvmUsagePrevention && !location.isMem()) {
        if (!sConn.lock.isLockedHere())
            SystemTDB.errlog.warn("Location " + location.getDirectoryPath() + " was not locked by this process.");
        sConn.lock.unlock();
        ProcessFileLock.release(sConn.lock);
    }
}
Also used : TransactionException(org.apache.jena.dboe.transaction.txn.TransactionException) TransactionCoordinator(org.apache.jena.dboe.transaction.txn.TransactionCoordinator)

Example 7 with TransactionCoordinator

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

the class TestThreadingTransactions method init.

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

Example 8 with TransactionCoordinator

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

the class TestTransactionLifecycle2 method setup.

@Before
public void setup() {
    Journal jrnl = Journal.create(Location.mem());
    txnMgr = new TransactionCoordinator(jrnl);
    txnMgr.start();
}
Also used : TransactionCoordinator(org.apache.jena.dboe.transaction.txn.TransactionCoordinator) Journal(org.apache.jena.dboe.transaction.txn.journal.Journal) Before(org.junit.Before)

Example 9 with TransactionCoordinator

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

the class LoaderMain method indexPhase.

private static void indexPhase(List<BulkStartFinish> processes, TupleIndex srcIdx, TupleIndex[] indexes, MonitorOutput output) {
    String indexSetLabel = PhasedOps.indexMappings(indexes);
    output.print("Index set:  %s => %s", srcIdx.getName(), indexSetLabel);
    Indexer indexer = new Indexer(output, indexes);
    Destination<Tuple<NodeId>> dest = indexer.index();
    indexer.startBulk();
    TransactionCoordinator coordinator = CoLib.newCoordinator();
    CoLib.add(coordinator, srcIdx);
    CoLib.start(coordinator);
    // READ transaction.
    Transaction transaction = coordinator.begin(TxnType.READ);
    // Add to processes - we can wait later if we do not touched indexes being built.
    processes.add(indexer);
    PhasedOps.ReplayResult result = PhasedOps.replay(srcIdx, dest, output);
    // End read transaction on srcIdx
    transaction.end();
    String timeStr = "---";
    if (result.elapsed != 0) {
        double time = result.elapsed / 1000.0;
        // long AvgRate = (result.items * 1000L) / result.elapsed;
        timeStr = String.format("%,.1f", time);
    }
    output.print("Index set:  %s => %s [%,d items, %s seconds]", srcIdx.getName(), indexSetLabel, result.items, timeStr);
}
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 10 with TransactionCoordinator

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

the class DatabaseOps method compact.

// XXX Later - switch in a recording dataset, not block writers, and reply after
// switch over before releasing the new dataset to the container.
// Maybe copy indexes and switch the DSG over (drop switchable).
/**
 * Copy the latest version from one location to another.
 */
private static void compact(DatasetGraphSwitchable container, Location loc1, Location loc2) {
    if (loc1.isMem() || loc2.isMem())
        throw new TDBException("Compact involves a memory location: " + loc1 + " : " + loc2);
    copyFiles(loc1, loc2);
    StoreConnection srcConn = StoreConnection.connectExisting(loc1);
    if (srcConn == null)
        throw new TDBException("No database at location : " + loc1);
    if (!(container.get() instanceof DatasetGraphTDB))
        throw new TDBException("Not a TDB2 database in DatasetGraphSwitchable");
    DatasetGraphTDB dsgCurrent = (DatasetGraphTDB) container.get();
    if (!dsgCurrent.getLocation().equals(loc1))
        throw new TDBException("Inconsistent locations for base : " + dsgCurrent.getLocation() + " , " + dsgCurrent.getLocation());
    DatasetGraphTDB dsgBase = srcConn.getDatasetGraphTDB();
    if (dsgBase != dsgCurrent)
        throw new TDBException("Inconsistent datasets : " + dsgCurrent.getLocation() + " , " + dsgBase.getLocation());
    TransactionalSystem txnSystem = dsgBase.getTxnSystem();
    TransactionCoordinator txnMgr = dsgBase.getTxnSystem().getTxnMgr();
    // Stop update.  On exit there are no writers and none will start until switched over.
    txnMgr.tryBlockWriters();
    // txnMgr.begin(WRITE, false) will now bounce.
    // Copy the latest generation.
    DatasetGraphTDB dsgCompact = StoreConnection.connectCreate(loc2).getDatasetGraphTDB();
    CopyDSG.copy(dsgBase, dsgCompact);
    TransactionCoordinator txnMgr2 = dsgCompact.getTxnSystem().getTxnMgr();
    txnMgr2.startExclusiveMode();
    txnMgr.startExclusiveMode();
    // Switch.
    if (!container.change(dsgCurrent, dsgCompact)) {
        Log.warn(DatabaseOps.class, "Inconistent: old datasetgraph not as expected");
        container.set(dsgCompact);
    }
    txnMgr2.finishExclusiveMode();
    // New database running.
    // Clean-up.
    // txnMgr.finishExclusiveMode();
    // Don't call : txnMgr.startWriters();
    StoreConnection.release(dsgBase.getLocation());
}
Also used : TDBException(org.apache.jena.tdb2.TDBException) TransactionalSystem(org.apache.jena.dboe.transaction.txn.TransactionalSystem) TransactionCoordinator(org.apache.jena.dboe.transaction.txn.TransactionCoordinator) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

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