}
}
+ /**
+ * Retired state, needed to catch and suppress callbacks after we have removed associated state.
+ */
+ private static final class Retired extends State {
+ private final String prevStateString;
+
+ Retired(final State prevState) {
+ prevStateString = prevState.toString();
+ }
+
+ @Override
+ public String toString() {
+ return "RETIRED (in " + prevStateString + ")";
+ }
+ }
+
private static final Logger LOG = LoggerFactory.getLogger(FrontendReadWriteTransaction.class);
private static final State ABORTED = new State() {
@Override
}
}
+ @Override
+ void retire() {
+ state = new Retired(state);
+ }
+
private void handleTransactionPreCommit(final TransactionPreCommitRequest request,
final RequestEnvelope envelope, final long now) throws RequestException {
throwIfFailed();
ready.readyCohort.preCommit(new FutureCallback<DataTreeCandidate>() {
@Override
public void onSuccess(final DataTreeCandidate result) {
- LOG.debug("{}: Transaction {} completed preCommit", persistenceId(), getIdentifier());
- recordAndSendSuccess(envelope, now, new TransactionPreCommitSuccess(getIdentifier(),
- request.getSequence()));
- ready.stage = CommitStage.PRE_COMMIT_COMPLETE;
+ successfulPreCommit(envelope, now);
}
@Override
}
}
- private void failTransaction(final RequestEnvelope envelope, final long now, final RuntimeRequestException cause) {
+ void successfulPreCommit(final RequestEnvelope envelope, final long startTime) {
+ if (state instanceof Retired) {
+ LOG.debug("{}: Suppressing successful preCommit of retired transaction {}", persistenceId(),
+ getIdentifier());
+ return;
+ }
+
+ final Ready ready = checkReady();
+ LOG.debug("{}: Transaction {} completed preCommit", persistenceId(), getIdentifier());
+ recordAndSendSuccess(envelope, startTime, new TransactionPreCommitSuccess(getIdentifier(),
+ envelope.getMessage().getSequence()));
+ ready.stage = CommitStage.PRE_COMMIT_COMPLETE;
+ }
+
+ void failTransaction(final RequestEnvelope envelope, final long now, final RuntimeRequestException cause) {
+ if (state instanceof Retired) {
+ LOG.debug("{}: Suppressing failure of retired transaction {}", persistenceId(), getIdentifier(), cause);
+ return;
+ }
+
recordAndSendFailure(envelope, now, cause);
state = new Failed(cause);
LOG.debug("{}: Transaction {} failed", persistenceId(), getIdentifier(), cause);
checkReady().readyCohort.canCommit(new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
- recordAndSendSuccess(envelope, now, new TransactionCanCommitSuccess(getIdentifier(),
- envelope.getMessage().getSequence()));
- ready.stage = CommitStage.CAN_COMMIT_COMPLETE;
- LOG.debug("{}: Transaction {} completed canCommit", persistenceId(), getIdentifier());
+ successfulCanCommit(envelope, now);
}
@Override
}
}
+ void successfulCanCommit(final RequestEnvelope envelope, final long startTime) {
+ if (state instanceof Retired) {
+ LOG.debug("{}: Suppressing successful canCommit of retired transaction {}", persistenceId(),
+ getIdentifier());
+ return;
+ }
+
+ final Ready ready = checkReady();
+ recordAndSendSuccess(envelope, startTime, new TransactionCanCommitSuccess(getIdentifier(),
+ envelope.getMessage().getSequence()));
+ ready.stage = CommitStage.CAN_COMMIT_COMPLETE;
+ LOG.debug("{}: Transaction {} completed canCommit", persistenceId(), getIdentifier());
+ }
+
private void directCommit(final RequestEnvelope envelope, final long now) throws RequestException {
throwIfFailed();
}
void successfulDirectCanCommit(final RequestEnvelope envelope, final long startTime) {
+ if (state instanceof Retired) {
+ LOG.debug("{}: Suppressing direct canCommit of retired transaction {}", persistenceId(), getIdentifier());
+ return;
+ }
+
final Ready ready = checkReady();
ready.stage = CommitStage.PRE_COMMIT_PENDING;
LOG.debug("{}: Transaction {} initiating direct preCommit", persistenceId(), getIdentifier());
}
void successfulDirectPreCommit(final RequestEnvelope envelope, final long startTime) {
+ if (state instanceof Retired) {
+ LOG.debug("{}: Suppressing direct commit of retired transaction {}", persistenceId(), getIdentifier());
+ return;
+ }
+
final Ready ready = checkReady();
ready.stage = CommitStage.COMMIT_PENDING;
LOG.debug("{}: Transaction {} initiating direct commit", persistenceId(), getIdentifier());
}
void successfulCommit(final RequestEnvelope envelope, final long startTime) {
+ if (state instanceof Retired) {
+ LOG.debug("{}: Suppressing commit response on retired transaction {}", persistenceId(), getIdentifier());
+ return;
+ }
+
recordAndSendSuccess(envelope, startTime, new TransactionCommitSuccess(getIdentifier(),
envelope.getMessage().getSequence()));
state = COMMITTED;