[ 
https://issues.apache.org/jira/browse/HIVE-26804?focusedWorklogId=839568&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-839568
 ]

ASF GitHub Bot logged work on HIVE-26804:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 17/Jan/23 10:18
            Start Date: 17/Jan/23 10:18
    Worklog Time Spent: 10m 
      Work Description: rkirtir commented on code in PR #3880:
URL: https://github.com/apache/hive/pull/3880#discussion_r1072022879


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java:
##########
@@ -6242,4 +6246,86 @@ public boolean isWrapperFor(Class<?> iface) throws 
SQLException {
     }
   }
 
+  @Override
+  @RetrySemantics.SafeToRetry
+  public AbortCompactResponse abortCompactions(AbortCompactionRequest reqst) 
throws MetaException, NoSuchCompactionException {
+    AbortCompactResponse response = new AbortCompactResponse(new 
ArrayList<>());
+    List<Long> requestedCompId = reqst.getCompactionIds();
+    if (requestedCompId.isEmpty()) {
+      LOG.info("Compaction ids missing in request. No compactions to abort");
+      throw new NoSuchCompactionException("ompaction ids missing in request. 
No compactions to abort");
+    }
+    List<AbortCompactionResponseElement> abortCompactionResponseElementList = 
new ArrayList<>();
+    for (int i = 0; i < requestedCompId.size(); i++) {
+      AbortCompactionResponseElement responseEle = 
abortCompaction(requestedCompId.get(i));
+      abortCompactionResponseElementList.add(responseEle);
+    }
+    response.setAbortedcompacts(abortCompactionResponseElementList);
+    return response;
+  }
+
+  @RetrySemantics.SafeToRetry
+  public AbortCompactionResponseElement abortCompaction(Long compId) throws 
MetaException {
+    try {
+      AbortCompactionResponseElement responseEle = new 
AbortCompactionResponseElement();
+      responseEle.setCompactionIds(compId);
+      try (Connection dbConn = 
getDbConn(Connection.TRANSACTION_READ_COMMITTED, connPoolMutex)) {
+        Optional<CompactionInfo> compactionInfo = 
getCompactionByCompId(dbConn, compId);
+        if (compactionInfo.isPresent()) {
+          try (PreparedStatement pStmt = 
dbConn.prepareStatement(TxnQueries.INSERT_INTO_COMPLETED_COMPACTION)) {
+            CompactionInfo ci = compactionInfo.get();
+            ci.errorMessage = "Compaction aborted by user";
+            ci.state = TxnStore.ABORTED_STATE;
+            CompactionInfo.insertIntoCompletedCompactions(pStmt, ci, 
getDbTime(dbConn));
+            int updCount = pStmt.executeUpdate();
+            if (updCount != 1) {
+              LOG.error("Unable to update compaction record: {}. updCnt={}", 
ci, updCount);
+              dbConn.rollback();
+            }
+            LOG.debug("Inserted {} entries into COMPLETED_COMPACTIONS", 
updCount);
+            try (PreparedStatement stmt = dbConn.prepareStatement("DELETE FROM 
\"COMPACTION_QUEUE\" WHERE \"CQ_ID\" = ?")) {
+              stmt.setLong(1, ci.id);
+              LOG.debug("Going to execute update on COMPACTION_QUEUE <{}>");
+              updCount = stmt.executeUpdate();
+              if (updCount != 1) {
+                LOG.error("Unable to update compaction record: {}. updCnt={}", 
ci, updCount);
+                dbConn.rollback();
+              } else {
+                responseEle.setMessage("Successfully Aborted Compaction ");
+                responseEle.setStatus("Success");
+                dbConn.commit();
+              }
+            }
+          }
+        } else {
+          responseEle.setMessage("Compaction element not eligible for 
cancellation");
+          responseEle.setStatus("Error");
+        }
+      } catch (SQLException e) {
+        LOG.error("Failed to abort compaction request");
+        checkRetryable(e, "abortCompaction(" + compId + ")");
+        responseEle.setMessage("Error while aborting compaction");
+        responseEle.setStatus("Error");
+      }
+      return responseEle;
+    } catch (RetryException e) {
+      return abortCompaction(compId);
+    }
+
+  }
+
+  private Optional<CompactionInfo> getCompactionByCompId(Connection dbConn, 
Long compId) throws SQLException, MetaException {

Review Comment:
   fixed.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 839568)
    Time Spent: 1h 10m  (was: 1h)

> Cancel Compactions in initiated state
> -------------------------------------
>
>                 Key: HIVE-26804
>                 URL: https://issues.apache.org/jira/browse/HIVE-26804
>             Project: Hive
>          Issue Type: New Feature
>          Components: Hive
>            Reporter: KIRTI RUGE
>            Assignee: KIRTI RUGE
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1h 10m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to