use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class XATerminatorImple method doRecover.
/**
* Return a list of indoubt transactions. This may include those
* transactions that are currently in-flight and running 2PC and do not need
* recovery invoked on them.
*
* @param nodeName
* Only recover transactions for this node (unless set to NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES)
* @throws XAException
* thrown if any error occurs.
* @return a list of potentially indoubt transactions or <code>null</code>.
*/
public Xid[] doRecover(Xid xid, String parentNodeName) throws XAException {
/*
* Requires going through the objectstore for the states of imported
* transactions. Our own crash recovery takes care of transactions
* imported via CORBA, Web Services etc.
*/
Xid[] indoubt = null;
try {
RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
InputObjectState states = new InputObjectState();
if (recoveryStore.allObjUids(SubordinateAtomicAction.getType(), states) && (states.notempty())) {
Stack<Xid> values = new Stack<Xid>();
boolean finished = false;
do {
Uid uid = null;
try {
uid = UidHelper.unpackFrom(states);
} catch (IOException ex) {
ex.printStackTrace();
finished = true;
}
if (uid.notEquals(Uid.nullUid())) {
if (parentNodeName != null) {
SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
XidImple loadedXid = (XidImple) saa.getXid();
if (loadedXid != null && loadedXid.getFormatId() == XATxConverter.FORMAT_ID) {
String loadedXidSubordinateNodeName = XATxConverter.getSubordinateNodeName(loadedXid.getXID());
if ((loadedXidSubordinateNodeName == null && loadedXidSubordinateNodeName == TxControl.getXANodeName()) || loadedXidSubordinateNodeName.equals(TxControl.getXANodeName())) {
if (parentNodeName.equals(saa.getParentNodeName())) {
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("Found record for " + saa);
}
// TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
values.push(loadedXid);
}
}
}
} else if (xid == null) {
TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
if (tx != null)
values.push(tx.baseXid());
} else {
SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
XidImple loadedXid = (XidImple) saa.getXid();
if (loadedXid != null && loadedXid.getFormatId() == XATxConverter.FORMAT_ID) {
String loadedXidSubordinateNodeName = XATxConverter.getSubordinateNodeName(loadedXid.getXID());
if (XATxConverter.getSubordinateNodeName(new XidImple(xid).getXID()).equals(loadedXidSubordinateNodeName)) {
if (Arrays.equals(loadedXid.getGlobalTransactionId(), xid.getGlobalTransactionId())) {
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("Found record for " + saa);
}
TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
values.push(loadedXid);
}
}
}
}
} else
finished = true;
} while (!finished);
if (values.size() > 0) {
int index = 0;
indoubt = new Xid[values.size()];
while (!values.empty()) {
indoubt[index] = values.pop();
index++;
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return indoubt;
}
use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class TransactionImple method createXid.
@Override
protected Xid createXid(boolean branch, XAModifier theModifier, XAResource xaResource) throws IOException, ObjectStoreException {
Xid xid = baseXid();
// We can have subordinate XIDs that can be editted
if (xid.getFormatId() != XATxConverter.FORMAT_ID)
return xid;
Integer eisName = null;
if (branch) {
if (_xaResourceRecordWrappingPlugin != null) {
eisName = _xaResourceRecordWrappingPlugin.getEISName(xaResource);
}
}
xid = new XidImple(xid, branch, eisName);
if (theModifier != null) {
try {
xid = theModifier.createXid((XidImple) xid);
} catch (Exception e) {
e.printStackTrace();
}
}
return xid;
}
use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class ServerTransaction method restore_state.
public boolean restore_state(InputObjectState os, int ot) {
try {
_theXid = null;
boolean haveXid = os.unpackBoolean();
if (haveXid) {
_theXid = new XidImple();
_theXid.unpackFrom(os);
}
return super.restore_state(os, ot);
} catch (IOException ex) {
ex.printStackTrace();
}
return false;
}
use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class CommitMarkableResourceRecordRecoveryModule method delete.
private void delete(String jndiName, List<Xid> completedXids) {
int batchSize = jtaEnvironmentBean.getCommitMarkableResourceRecordDeleteBatchSize();
Integer integer = jtaEnvironmentBean.getCommitMarkableResourceRecordDeleteBatchSizeMap().get(jndiName);
if (integer != null) {
batchSize = integer;
}
try {
while (completedXids.size() > 0) {
int sendingSize = batchSize < 0 ? completedXids.size() : completedXids.size() < batchSize ? completedXids.size() : batchSize;
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < sendingSize; i++) {
buffer.append("?,");
}
if (buffer.length() > 0) {
Connection connection = null;
DataSource dataSource = (DataSource) context.lookup(jndiName);
try {
connection = dataSource.getConnection();
connection.setAutoCommit(false);
String tableName = commitMarkableResourceTableNameMap.get(jndiName);
if (tableName == null) {
tableName = defaultTableName;
}
String sql = "DELETE from " + tableName + " where xid in (" + buffer.substring(0, buffer.length() - 1) + ")";
if (tsLogger.logger.isTraceEnabled()) {
tsLogger.logger.trace("Attempting to delete number of entries: " + buffer.length());
}
PreparedStatement prepareStatement = connection.prepareStatement(sql);
List<Xid> deleted = new ArrayList<Xid>();
try {
for (int i = 0; i < sendingSize; i++) {
XidImple xid = (XidImple) completedXids.remove(0);
deleted.add(xid);
XID toSave = xid.getXID();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeInt(toSave.formatID);
dos.writeInt(toSave.gtrid_length);
dos.writeInt(toSave.bqual_length);
dos.writeInt(toSave.data.length);
dos.write(toSave.data);
dos.flush();
prepareStatement.setBytes(i + 1, baos.toByteArray());
}
int executeUpdate = prepareStatement.executeUpdate();
if (executeUpdate != sendingSize) {
tsLogger.logger.error("Update was not successful, expected: " + sendingSize + " actual:" + executeUpdate);
connection.rollback();
} else {
connection.commit();
committedXidsToJndiNames.keySet().removeAll(deleted);
}
} catch (IOException e) {
tsLogger.logger.warn("Could not generate prepareStatement paramaters", e);
} finally {
try {
prepareStatement.close();
} catch (SQLException e) {
tsLogger.logger.warn("Could not close the prepared statement", e);
}
}
} catch (SQLException e) {
tsLogger.logger.warn("Could not handle the connection", e);
// the connection is unavailable so try again later
break;
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
tsLogger.logger.warn("Could not close the connection", e);
}
}
}
}
}
} catch (NamingException e) {
tsLogger.logger.warn("Could not lookup commitMarkable: " + jndiName);
tsLogger.logger.debug("Could not lookup commitMarkable: " + jndiName, e);
} catch (IllegalStateException e) {
// Thrown when AS is shutting down and we attempt a lookup
tsLogger.logger.debug("Could not lookup datasource, AS is shutting down: " + e.getMessage(), e);
}
}
use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class RecoveryXids method remove.
public boolean remove(Xid xid) {
XidImple xidImple = new XidImple(xid);
if (_whenFirstSeen.containsKey(xidImple)) {
_whenFirstSeen.remove(xidImple);
if (tsLogger.logger.isTraceEnabled())
tsLogger.logger.trace("RecoveryXids _whenFirstSeen remove remove " + _xares + " " + _lastValidated + " " + xidImple);
_whenLastSeen.remove(xidImple);
return true;
} else {
return false;
}
}
Aggregations