dlmarion commented on a change in pull request #2467:
URL: https://github.com/apache/accumulo/pull/2467#discussion_r801090182
##########
File path: core/src/main/java/org/apache/accumulo/fate/Fate.java
##########
@@ -300,6 +331,68 @@ 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. Look up
+ // the thread that is running this transaction.
+ Thread t = null;
+ synchronized (RUNNING_TRANSACTIONS) {
+ t = RUNNING_TRANSACTIONS.get(tid);
+ }
+ if (t != null) {
+ Thread t2 = null;
+ synchronized (t) {
+ // Make sure that the transaction is still associated
+ // with this thread. If it is, then this thread is blocked
+ // from removing this transaction from the table and we can
+ // interrupt it and cause it to fail.
+ synchronized (RUNNING_TRANSACTIONS) {
+ t2 = RUNNING_TRANSACTIONS.get(tid);
+ }
+ if (t2 != null && t == t2) {
+ t.interrupt();
+ }
+ }
+ return true;
+ } else {
+ // reserved, but not in transaction table. It should transition to
+ // an end state or become unreserved in a short amount of time.
+ // Lets retry.
+ UtilWaitThread.sleep(500);
+ }
Review comment:
Incorporated this change into
[c49f55e](https://github.com/apache/accumulo/pull/2467/commits/c49f55ec90ed3ea883c9dbfd22dfac740b3e8b3d)
--
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]