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");
}
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);
}
}
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();
}
}
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();
}
}
}
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;
}
Aggregations