dlmarion commented on a change in pull request #2467:
URL: https://github.com/apache/accumulo/pull/2467#discussion_r800936842
##########
File path: core/src/main/java/org/apache/accumulo/fate/Fate.java
##########
@@ -300,6 +335,55 @@ public TStatus waitForCompletion(long tid) {
return store.waitForStatusChange(tid, FINISHED_STATES);
}
+ /**
+ * Attempts to cancel a running Fate transaction
+ *
+ * @param tid
+ * transaction id
+ * @return true if transaction transitioned to a failed state or already in
a completed state,
+ * false otherwise
+ */
+ public boolean cancel(long tid) {
+ String tidStr = Long.toHexString(tid);
+ for (int retries = 0; retries < 5; retries++) {
+ if (store.tryReserve(tid)) {
+ try {
+ TStatus status = store.getStatus(tid);
+ if (status == NEW || status == SUBMITTED || status == IN_PROGRESS) {
+ store.setProperty(tid, EXCEPTION_PROP, new TApplicationException(
+ TApplicationException.INTERNAL_ERROR, "Fate transaction
cancelled by user"));
+ store.setStatus(tid, FAILED_IN_PROGRESS);
+ log.info(
+ "Updated status for Repo {} to FAILED_IN_PROGRESS because it
was cancelled by user",
+ tidStr);
+ return true;
+ } else {
+ log.info("Repo {} cancelled by user but already in finished
state", tidStr);
+ return true;
+ }
+ } finally {
+ store.unreserve(tid, 0);
+ }
+ } else {
+ // It's possible that the FateOp is being run by the TransactionRunner
+ Thread t = null;
+ synchronized (RUNNING_TRANSACTIONS) {
+ t = RUNNING_TRANSACTIONS.get(tid);
+ }
+ if (t != null) {
+ t.interrupt();
Review comment:
What if I moved lines 373 to 381 in the synchronized block? Then, it
should be guaranteed that if the transaction is in RUNNING_TRANSACTIONS, that
the Thread running it has not moved on to something else.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]