Search in sources :

Example 56 with XAException

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

the class TxManager method rollbackCommit.

private void rollbackCommit(Thread thread, TransactionImpl tx) throws HeuristicMixedException, RollbackException, SystemException {
    try {
        tx.doRollback();
    } catch (XAException e) {
        e.printStackTrace();
        log.severe("Unable to rollback marked transaction. " + "Some resources may be commited others not. " + "Neo4j kernel should be SHUTDOWN for " + "resource maintance and transaction recovery ---->");
        setTmNotOk();
        throw new HeuristicMixedException("Unable to rollback " + " ---> error code for rollback: " + e.errorCode);
    }
    tx.doAfterCompletion();
    txThreadMap.remove(thread);
    try {
        if (tx.isGlobalStartRecordWritten()) {
            getTxLog().txDone(tx.getGlobalId());
        }
    } catch (IOException e) {
        e.printStackTrace();
        log.severe("Error writing transaction log");
        setTmNotOk();
        throw new SystemException("TM encountered a problem, " + " error writing transaction log," + e);
    }
    tx.setStatus(Status.STATUS_NO_TRANSACTION);
    throw new RollbackException("Failed to commit, transaction rolledback");
}
Also used : XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) IOException(java.io.IOException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException)

Example 57 with XAException

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

the class WriteTransaction method doPrepare.

@Override
protected void doPrepare() throws XAException {
    if (committed) {
        throw new XAException("Cannot prepare committed transaction[" + getIdentifier() + "]");
    }
    if (prepared) {
        throw new XAException("Cannot prepare prepared transaction[" + getIdentifier() + "]");
    }
    // generate records then write to logical log via addCommand method
    prepared = true;
    for (RelationshipTypeRecord record : relTypeRecords.values()) {
        Command.RelationshipTypeCommand command = new Command.RelationshipTypeCommand(neoStore.getRelationshipTypeStore(), record);
        relTypeCommands.add(command);
        addCommand(command);
    }
    for (NodeRecord record : nodeRecords.values()) {
        if (!record.inUse() && record.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
            throw new InvalidRecordException("Node record " + record + " still has relationships");
        }
        Command.NodeCommand command = new Command.NodeCommand(neoStore.getNodeStore(), record);
        nodeCommands.add(command);
        if (!record.inUse()) {
            removeNodeFromCache(record.getId());
        }
        addCommand(command);
    }
    for (RelationshipRecord record : relRecords.values()) {
        Command.RelationshipCommand command = new Command.RelationshipCommand(neoStore.getRelationshipStore(), record);
        relCommands.add(command);
        if (!record.inUse()) {
            removeRelationshipFromCache(record.getId());
        }
        addCommand(command);
    }
    for (PropertyIndexRecord record : propIndexRecords.values()) {
        Command.PropertyIndexCommand command = new Command.PropertyIndexCommand(neoStore.getPropertyStore().getIndexStore(), record);
        propIndexCommands.add(command);
        addCommand(command);
    }
    for (PropertyRecord record : propertyRecords.values()) {
        Command.PropertyCommand command = new Command.PropertyCommand(neoStore.getPropertyStore(), record);
        propCommands.add(command);
        addCommand(command);
    }
}
Also used : XAException(javax.transaction.xa.XAException) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) RelationshipTypeRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) XaCommand(org.neo4j.kernel.impl.transaction.xaframework.XaCommand) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 58 with XAException

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

the class WriteTransaction method doCommit.

public void doCommit() throws XAException {
    if (!isRecovered() && !prepared) {
        throw new XAException("Cannot commit non prepared transaction[" + getIdentifier() + "]");
    }
    if (isRecovered()) {
        commitRecovered();
        return;
    }
    if (!isRecovered() && getCommitTxId() != neoStore.getLastCommittedTx() + 1) {
        throw new RuntimeException("Tx id: " + getCommitTxId() + " not next transaction (" + neoStore.getLastCommittedTx() + ")");
    }
    try {
        committed = true;
        CommandSorter sorter = new CommandSorter();
        // reltypes
        java.util.Collections.sort(relTypeCommands, sorter);
        for (Command.RelationshipTypeCommand command : relTypeCommands) {
            command.execute();
        }
        // nodes
        java.util.Collections.sort(nodeCommands, sorter);
        for (Command.NodeCommand command : nodeCommands) {
            command.execute();
        }
        // relationships
        java.util.Collections.sort(relCommands, sorter);
        for (Command.RelationshipCommand command : relCommands) {
            command.execute();
        }
        java.util.Collections.sort(propIndexCommands, sorter);
        for (Command.PropertyIndexCommand command : propIndexCommands) {
            command.execute();
        }
        // properties
        java.util.Collections.sort(propCommands, sorter);
        for (Command.PropertyCommand command : propCommands) {
            command.execute();
        }
        neoStore.setLastCommittedTx(getCommitTxId());
        if (!isRecovered()) {
            lockReleaser.commit();
        }
    } finally {
        nodeRecords.clear();
        propertyRecords.clear();
        relRecords.clear();
        relTypeRecords.clear();
        propIndexRecords.clear();
        nodeCommands.clear();
        propCommands.clear();
        propIndexCommands.clear();
        relCommands.clear();
        relTypeCommands.clear();
    }
}
Also used : XAException(javax.transaction.xa.XAException) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) XaCommand(org.neo4j.kernel.impl.transaction.xaframework.XaCommand) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand)

Example 59 with XAException

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

the class WriteTransaction method doRollback.

public void doRollback() throws XAException {
    if (committed) {
        throw new XAException("Cannot rollback partialy commited " + "transaction[" + getIdentifier() + "]. Recover and " + "commit");
    }
    try {
        for (RelationshipTypeRecord record : relTypeRecords.values()) {
            if (record.isCreated()) {
                getRelationshipTypeStore().freeId(record.getId());
                for (DynamicRecord dynamicRecord : record.getTypeRecords()) {
                    if (dynamicRecord.isCreated()) {
                        getRelationshipTypeStore().freeBlockId((int) dynamicRecord.getId());
                    }
                }
            }
            removeRelationshipTypeFromCache(record.getId());
        }
        for (NodeRecord record : nodeRecords.values()) {
            if (record.isCreated()) {
                getNodeStore().freeId(record.getId());
            }
            removeNodeFromCache(record.getId());
        }
        for (RelationshipRecord record : relRecords.values()) {
            if (record.isCreated()) {
                getRelationshipStore().freeId(record.getId());
            }
            removeRelationshipFromCache(record.getId());
        }
        for (PropertyIndexRecord record : propIndexRecords.values()) {
            if (record.isCreated()) {
                getPropertyStore().getIndexStore().freeId(record.getId());
                for (DynamicRecord dynamicRecord : record.getKeyRecords()) {
                    if (dynamicRecord.isCreated()) {
                        getPropertyStore().getIndexStore().freeBlockId((int) dynamicRecord.getId());
                    }
                }
            }
        }
        for (PropertyRecord record : propertyRecords.values()) {
            if (record.getNodeId() != -1) {
                removeNodeFromCache(record.getNodeId());
            } else if (record.getRelId() != -1) {
                removeRelationshipFromCache(record.getRelId());
            }
            if (record.isCreated()) {
                getPropertyStore().freeId(record.getId());
                for (DynamicRecord dynamicRecord : record.getValueRecords()) {
                    if (dynamicRecord.isCreated()) {
                        if (dynamicRecord.getType() == PropertyType.STRING.intValue()) {
                            getPropertyStore().freeStringBlockId(dynamicRecord.getId());
                        } else if (dynamicRecord.getType() == PropertyType.ARRAY.intValue()) {
                            getPropertyStore().freeArrayBlockId(dynamicRecord.getId());
                        } else {
                            throw new InvalidRecordException("Unknown type on " + dynamicRecord);
                        }
                    }
                }
            }
        }
    } finally {
        nodeRecords.clear();
        propertyRecords.clear();
        relRecords.clear();
        relTypeRecords.clear();
        propIndexRecords.clear();
        nodeCommands.clear();
        propCommands.clear();
        propIndexCommands.clear();
        relCommands.clear();
        relTypeCommands.clear();
        if (!isRecovered()) {
            lockReleaser.rollback();
        }
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) XAException(javax.transaction.xa.XAException) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) RelationshipTypeRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 60 with XAException

use of javax.transaction.xa.XAException in project voltdb by VoltDB.

the class JDBCXAResource method end.

public void end(Xid xid, int flags) throws XAException {
    validateXid(xid);
    if (state != XA_STATE_STARTED) {
        throw new XAException("Invalid XAResource state");
    }
    try {
        // real/phys.
        connection.setAutoCommit(originalAutoCommitMode);
    } catch (SQLException se) {
        throw new XAException(se.getMessage());
    }
    state = XA_STATE_ENDED;
}
Also used : XAException(javax.transaction.xa.XAException) SQLException(java.sql.SQLException)

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