diff --git a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/Worker.java b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/Worker.java index 2023292f4e..42467d0c41 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/Worker.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/Worker.java @@ -266,7 +266,7 @@ public Object run() throws Exception { LOG.error("Caught an exception in the main loop of compactor worker " + workerName + ", " + StringUtils.stringifyException(t)); } finally { - commitTxn(compactorTxnId); + commitTxnIfOpen(compactorTxnId); if (heartbeater != null) { heartbeater.cancel(); } @@ -284,8 +284,21 @@ public Object run() throws Exception { } while (!stop.get()); } - private void commitTxn(long compactorTxnId) { + private void commitTxnIfOpen(long compactorTxnId) { if (compactorTxnId != NOT_SET) { + + // if transaction is aborted already, don't try to commit + try { + if (msc.getValidTxns().isTxnAborted(compactorTxnId)) { + return; + } + } catch (TException e) { + LOG.error( + "Caught an exception while checking whether compaction is aborted or not in worker " + + workerName + ": " + StringUtils.stringifyException(e)); + } + + // commit try { if (msc != null) { msc.commitTxn(compactorTxnId);