Search in sources :

Example 1 with TransactionalSystem

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

the class DatasetGraphStorage method isolate.

private <T> Iterator<T> isolate(Iterator<T> iterator) {
    if (txn.isInTransaction() && txn instanceof TransactionalSystem) {
        // Needs TxnId to track.
        TransactionalSystem txnSystem = (TransactionalSystem) txn;
        TxnId txnId = txnSystem.getThreadTransaction().getTxnId();
        // Add transaction protection.
        return new IteratorTxnTracker<>(iterator, txnSystem, txnId);
    }
    return Iter.iterator(iterator);
}
Also used : TxnId(org.apache.jena.dboe.transaction.txn.TxnId) TransactionalSystem(org.apache.jena.dboe.transaction.txn.TransactionalSystem) IteratorTxnTracker(org.apache.jena.dboe.transaction.txn.IteratorTxnTracker)

Example 2 with TransactionalSystem

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

TransactionalSystem (org.apache.jena.dboe.transaction.txn.TransactionalSystem)2 IteratorTxnTracker (org.apache.jena.dboe.transaction.txn.IteratorTxnTracker)1 TransactionCoordinator (org.apache.jena.dboe.transaction.txn.TransactionCoordinator)1 TxnId (org.apache.jena.dboe.transaction.txn.TxnId)1 TDBException (org.apache.jena.tdb2.TDBException)1 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)1