use of org.jboss.jbossts.xts11.recovery.participant.at.ATParticipantRecoveryRecord in project narayana by jbosstm.
the class ParticipantEngine method commitDecision.
/**
* Handle the commit decision event.
*
* Preparing -> PreparedSuccess (send Prepared)
* Committing -> null (send committed and forget)
*/
private void commitDecision() {
State current;
boolean rollbackRequired = false;
boolean deleteRequired = false;
synchronized (this) {
current = state;
}
if (current == State.STATE_PREPARING) {
// and send aborted.
if (participant instanceof Durable2PCParticipant) {
// write a durable participant recovery record to the persistent store
Durable2PCParticipant durableParticipant = (Durable2PCParticipant) participant;
ATParticipantRecoveryRecord recoveryRecord = new ATParticipantRecoveryRecord(id, durableParticipant, coordinator);
if (!XTSATRecoveryManager.getRecoveryManager().writeParticipantRecoveryRecord(recoveryRecord)) {
// we need to rollback and send aborted unless some other thread
// gets there first
rollbackRequired = true;
}
}
synchronized (this) {
current = state;
if (current == State.STATE_PREPARING) {
if (rollbackRequired) {
// if we change state to aborting then we are responsible for
// calling rollback and sending aborted but we have no log record
// to delete
state = State.STATE_ABORTING;
} else {
state = State.STATE_PREPARED_SUCCESS;
// this ensures any subsequent commit or rollback deletes the log record
// so we still have no log record to delete here
persisted = true;
}
} else if (!rollbackRequired) {
// an incoming rollback or readonly changed the state to aborted or null so
// it will already have performed a rollback if required but we need to
// delete the log record since the rollback/readonly thread did not know
// about it
deleteRequired = true;
}
}
if (rollbackRequired) {
// we need to do the rollback and send aborted
executeRollback();
sendAborted();
forget();
} else if (deleteRequired) {
if (!XTSATRecoveryManager.getRecoveryManager().deleteParticipantRecoveryRecord(id)) {
// hmm, could not delete entry log warning
WSTLogger.i18NLogger.warn_wst11_messaging_engines_ParticipantEngine_commitDecision_2(id);
}
} else {
// whew got through -- send a prepared
sendPrepared();
}
} else if (current == State.STATE_COMMITTING) {
if (persisted && participant instanceof Durable2PCParticipant) {
// remove any durable participant recovery record from the persistent store
Durable2PCParticipant durableParticipant = (Durable2PCParticipant) participant;
// here in the hope that we have better luck next time.
if (!XTSATRecoveryManager.getRecoveryManager().deleteParticipantRecoveryRecord(id)) {
// hmm, could not delete entry -- log a warning
WSTLogger.i18NLogger.warn_wst11_messaging_engines_ParticipantEngine_commitDecision_3(id);
synchronized (this) {
state = State.STATE_PREPARED_SUCCESS;
}
return;
}
}
sendCommitted();
forget();
}
}
Aggregations