Search in sources :

Example 41 with XAException

use of javax.transaction.xa.XAException in project graphdb by neo4j-attic.

the class XaDataSourceManager method getBranchId.

synchronized byte[] getBranchId(XAResource xaResource) {
    if (xaResource instanceof XaResource) {
        byte[] branchId = ((XaResource) xaResource).getBranchId();
        if (branchId != null) {
            return branchId;
        }
    }
    Iterator<Map.Entry<String, XaDataSource>> itr = dataSources.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry<String, XaDataSource> entry = itr.next();
        XaDataSource dataSource = entry.getValue();
        XAResource resource = dataSource.getXaConnection().getXaResource();
        try {
            if (resource.isSameRM(xaResource)) {
                String name = entry.getKey();
                return sourceIdMapping.get(name);
            }
        } catch (XAException e) {
            throw new TransactionFailureException("Unable to check is same resource", e);
        }
    }
    throw new TransactionFailureException("Unable to find mapping for XAResource[" + xaResource + "]");
}
Also used : XAResource(javax.transaction.xa.XAResource) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) XAException(javax.transaction.xa.XAException) XaResource(org.neo4j.kernel.impl.transaction.xaframework.XaResource) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) Map(java.util.Map) HashMap(java.util.HashMap)

Example 42 with XAException

use of javax.transaction.xa.XAException in project graphdb by neo4j-attic.

the class XaLogicalLog method commitTwoPhase.

// [TX_2P_COMMIT][identifier]
public synchronized void commitTwoPhase(int identifier, long txId, int masterId) throws XAException {
    LogEntry.Start startEntry = xidIdentMap.get(identifier);
    assert startEntry != null;
    assert txId != -1;
    try {
        LogIoUtils.writeCommit(true, writeBuffer, identifier, txId, masterId);
        writeBuffer.force();
        cacheTxStartPosition(txId, masterId, startEntry);
    } catch (IOException e) {
        throw new XAException("Logical log unable to mark 2PC [" + identifier + "] " + e);
    }
}
Also used : XAException(javax.transaction.xa.XAException) IOException(java.io.IOException)

Example 43 with XAException

use of javax.transaction.xa.XAException in project graphdb by neo4j-attic.

the class XaLogicalLog method start.

// returns identifier for transaction
// [TX_START][xid[gid.length,bid.lengh,gid,bid]][identifier][format id]
public synchronized int start(Xid xid) throws XAException {
    if (backupSlave) {
        throw new XAException("Resource is configured as backup slave, " + "no new transactions can be started for " + fileName + "." + currentLog);
    }
    int xidIdent = getNextIdentifier();
    try {
        long position = writeBuffer.getFileChannelPosition();
        LogEntry.Start start = new LogEntry.Start(xid, xidIdent, position);
        LogIoUtils.writeStart(writeBuffer, xidIdent, xid);
        xidIdentMap.put(xidIdent, start);
    } catch (IOException e) {
        throw new XAException("Logical log couldn't start transaction: " + e);
    }
    return xidIdent;
}
Also used : XAException(javax.transaction.xa.XAException) IOException(java.io.IOException)

Example 44 with XAException

use of javax.transaction.xa.XAException in project graphdb by neo4j-attic.

the class XaLogicalLog method applyOnePhaseCommitEntry.

private void applyOnePhaseCommitEntry(LogEntry.OnePhaseCommit commit) throws IOException {
    int identifier = commit.getIdentifier();
    long txId = commit.getTxId();
    LogEntry.Start startEntry = xidIdentMap.get(identifier);
    if (startEntry == null) {
        throw new IOException("Unknown xid for identifier " + identifier);
    }
    Xid xid = startEntry.getXid();
    try {
        XaTransaction xaTx = xaRm.getXaTransaction(xid);
        xaTx.setCommitTxId(txId);
        xaRm.injectOnePhaseCommit(xid);
        msgLog.logMessage("Injected one phase commit, txId=" + commit.getTxId(), true);
    } catch (XAException e) {
        e.printStackTrace();
        throw new IOException(e.getMessage());
    }
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) IOException(java.io.IOException)

Example 45 with XAException

use of javax.transaction.xa.XAException in project graphdb by neo4j-attic.

the class XaLogicalLog method applyTransactionWithoutTxId.

public synchronized void applyTransactionWithoutTxId(ReadableByteChannel byteChannel, long nextTxId, int masterId) throws IOException {
    if (nextTxId != (xaTf.getLastCommittedTx() + 1)) {
        throw new IllegalStateException("Tried to apply tx " + nextTxId + " but expected transaction " + (xaTf.getCurrentVersion() + 1));
    }
    msgLog.logMessage("applyTxWithoutTxId log version: " + logVersion + ", committing tx=" + nextTxId + ") @ pos " + writeBuffer.getFileChannelPosition(), true);
    long logEntriesFound = 0;
    scanIsComplete = false;
    LogApplier logApplier = new LogApplier(byteChannel);
    int xidIdent = getNextIdentifier();
    long startEntryPosition = writeBuffer.getFileChannelPosition();
    while (logApplier.readAndWriteAndApplyEntry(xidIdent)) {
        logEntriesFound++;
    }
    byteChannel.close();
    LogEntry.Start startEntry = logApplier.startEntry;
    if (startEntry == null) {
        throw new IOException("Unable to find start entry");
    }
    startEntry.setStartPosition(startEntryPosition);
    //        System.out.println( "applyTxWithoutTxId#before 1PC @ pos: " + writeBuffer.getFileChannelPosition() );
    LogEntry.OnePhaseCommit commit = new LogEntry.OnePhaseCommit(xidIdent, nextTxId, masterId);
    LogIoUtils.writeLogEntry(commit, writeBuffer);
    Xid xid = startEntry.getXid();
    try {
        XaTransaction xaTx = xaRm.getXaTransaction(xid);
        xaTx.setCommitTxId(nextTxId);
        xaRm.commit(xid, true);
        LogEntry doneEntry = new LogEntry.Done(startEntry.getIdentifier());
        LogIoUtils.writeLogEntry(doneEntry, writeBuffer);
        xidIdentMap.remove(startEntry.getIdentifier());
        recoveredTxMap.remove(startEntry.getIdentifier());
        cacheTxStartPosition(nextTxId, masterId, startEntry);
    } catch (XAException e) {
        e.printStackTrace();
        throw new IOException(e.getMessage());
    }
    //        LogEntry.Done done = new LogEntry.Done( entry.getIdentifier() );
    //        LogIoUtils.writeLogEntry( done, writeBuffer );
    // xaTf.setLastCommittedTx( nextTxId ); // done in doCommit
    scanIsComplete = true;
    //        log.info( "Tx[" + nextTxId + "] " + " applied successfully." );
    msgLog.logMessage("Applied external tx and generated tx id=" + nextTxId, true);
//        System.out.println( "applyTxWithoutTxId#end @ pos: " + writeBuffer.getFileChannelPosition() );
}
Also used : XAException(javax.transaction.xa.XAException) IOException(java.io.IOException) Xid(javax.transaction.xa.Xid)

Aggregations

XAException (javax.transaction.xa.XAException)68 IOException (java.io.IOException)20 Xid (javax.transaction.xa.Xid)19 SystemException (javax.transaction.SystemException)14 TransactionContext (com.hazelcast.transaction.TransactionContext)12 RollbackException (javax.transaction.RollbackException)8 XAResource (javax.transaction.xa.XAResource)8 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)7 HeuristicMixedException (javax.transaction.HeuristicMixedException)6 Test (org.junit.Test)6 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)6 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 HashMap (java.util.HashMap)5 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)4 ArrayList (java.util.ArrayList)3 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)3 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)3 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)3 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)3