+ if (request instanceof TransactionPurgeRequest) {
+ if (purgedTransactions.contains(ul)) {
+ // Retransmitted purge request: nothing to do
+ LOG.debug("{}: transaction {} already purged", persistenceId, id);
+ return new TransactionPurgeResponse(id, request.getSequence());
+ }
+
+ // We perform two lookups instead of a straight remove, because once the map becomes empty we switch it
+ // to an ImmutableMap, which does not allow remove().
+ if (closedTransactions.containsKey(ul)) {
+ tree.purgeTransaction(id, () -> {
+ closedTransactions.remove(ul);
+ if (closedTransactions.isEmpty()) {
+ closedTransactions = ImmutableMap.of();
+ }
+
+ purgedTransactions.add(Range.singleton(ul));
+ LOG.debug("{}: finished purging inherited transaction {}", persistenceId(), id);
+ envelope.sendSuccess(new TransactionPurgeResponse(id, request.getSequence()), readTime() - now);
+ });
+ return null;
+ }
+
+ final FrontendTransaction tx = transactions.get(id);
+ if (tx == null) {
+ // This should never happen because the purge callback removes the transaction and puts it into
+ // purged transactions in one go. If it does, we warn about the situation and
+ LOG.warn("{}: transaction {} not tracked in {}, but not present in active transactions", persistenceId,
+ id, purgedTransactions);
+ purgedTransactions.add(Range.singleton(ul));
+ return new TransactionPurgeResponse(id, request.getSequence());
+ }
+
+ tree.purgeTransaction(id, () -> {
+ purgedTransactions.add(Range.singleton(ul));
+ transactions.remove(id);
+ LOG.debug("{}: finished purging transaction {}", persistenceId(), id);
+ envelope.sendSuccess(new TransactionPurgeResponse(id, request.getSequence()), readTime() - now);
+ });
+ return null;
+ }
+
+ if (purgedTransactions.contains(ul)) {
+ LOG.warn("{}: Request {} is contained purged transactions {}", persistenceId, request, purgedTransactions);
+ throw new DeadTransactionException(purgedTransactions);
+ }
+ final Boolean closed = closedTransactions.get(ul);
+ if (closed != null) {
+ final boolean successful = closed.booleanValue();
+ LOG.debug("{}: Request {} refers to a {} transaction", persistenceId, request, successful ? "successful"
+ : "failed");
+ throw new ClosedTransactionException(successful);
+ }