Search in sources :

Example 1 with TransactionException

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

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

the class StoragePrefixesTDB method ensureWriteTxn.

// private void requireTxn() {
// if ( ! txnSystem.isInTransaction() )
// throw new TransactionException("Not on a transaction");
// }
private void ensureWriteTxn() {
    Transaction txn = txnSystem.getThreadTransaction();
    if (txn == null)
        throw new TransactionException("Not in a transaction");
    txn.ensureWriteTxn();
}
Also used : TransactionException(org.apache.jena.dboe.transaction.txn.TransactionException) Transaction(org.apache.jena.dboe.transaction.txn.Transaction)

Example 3 with TransactionException

use of org.apache.jena.dboe.transaction.txn.TransactionException 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;
}
Also used : TransactionException(org.apache.jena.dboe.transaction.txn.TransactionException) ComponentId(org.apache.jena.dboe.transaction.txn.ComponentId) ByteBuffer(java.nio.ByteBuffer) Adler32(java.util.zip.Adler32)

Example 4 with TransactionException

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

the class NodeTableTRDF method writeNodeToTable.

@Override
protected NodeId writeNodeToTable(Node node) {
    RDF_Term term = ThriftConvert.convert(node, true);
    try {
        long x = diskFile.length();
        // Paired : [*]
        NodeId nid = NodeIdFactory.createPtr(x);
        term.write(protocol);
        // transport.flush();
        return nid;
    } catch (TransactionException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new TDBException("NodeTableThrift/Write", ex);
    }
}
Also used : TransactionException(org.apache.jena.dboe.transaction.txn.TransactionException) TDBException(org.apache.jena.tdb2.TDBException) NodeId(org.apache.jena.tdb2.store.NodeId) RDF_Term(org.apache.jena.riot.thrift.wire.RDF_Term) RiotThriftException(org.apache.jena.riot.thrift.RiotThriftException) TDBException(org.apache.jena.tdb2.TDBException) TException(org.apache.thrift.TException) TransactionException(org.apache.jena.dboe.transaction.txn.TransactionException)

Example 5 with TransactionException

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

the class StorageTDB method ensureWriteTxn.

// private void requireTxn() {
// if ( ! txnSystem.isInTransaction() )
// throw new TransactionException("Not on a transaction");
// }
private void ensureWriteTxn() {
    Transaction txn = txnSystem.getThreadTransaction();
    if (txn == null)
        throw new TransactionException("Not on a write transaction");
    txn.ensureWriteTxn();
}
Also used : TransactionException(org.apache.jena.dboe.transaction.txn.TransactionException) Transaction(org.apache.jena.dboe.transaction.txn.Transaction)

Aggregations

TransactionException (org.apache.jena.dboe.transaction.txn.TransactionException)5 Transaction (org.apache.jena.dboe.transaction.txn.Transaction)2 ByteBuffer (java.nio.ByteBuffer)1 Adler32 (java.util.zip.Adler32)1 ComponentId (org.apache.jena.dboe.transaction.txn.ComponentId)1 TransactionCoordinator (org.apache.jena.dboe.transaction.txn.TransactionCoordinator)1 RiotThriftException (org.apache.jena.riot.thrift.RiotThriftException)1 RDF_Term (org.apache.jena.riot.thrift.wire.RDF_Term)1 TDBException (org.apache.jena.tdb2.TDBException)1 NodeId (org.apache.jena.tdb2.store.NodeId)1 TException (org.apache.thrift.TException)1