You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hive.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2022/04/06 11:28:00 UTC

[jira] [Work logged] (HIVE-26121) Hive transaction rollback should be thread-safe

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

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

                Author: ASF GitHub Bot
            Created on: 06/Apr/22 11:27
            Start Date: 06/Apr/22 11:27
    Worklog Time Spent: 10m 
      Work Description: deniskuzZ commented on code in PR #3181:
URL: https://github.com/apache/hive/pull/3181#discussion_r843829383


##########
ql/src/java/org/apache/hadoop/hive/ql/lockmgr/DbTxnManager.java:
##########
@@ -710,49 +691,32 @@ private Heartbeater startHeartbeat(long initialDelay) throws LockException {
     return task;
   }
 
-  private void stopHeartbeat() {
-    if (heartbeatTask == null) {
-      // avoid unnecessary locking if the field is null
-      return;
-    }
-
-    boolean isLockAcquired = false;
-    try {
-      // The lock should not be held by other thread trying to stop the heartbeat for more than 31 seconds
-      isLockAcquired = heartbeatTaskLock.tryLock(31000, TimeUnit.MILLISECONDS);
-    } catch (InterruptedException e) {
-      // safe to go on
-    }
-
-    try {
-      if (isLockAcquired && heartbeatTask != null) {
-        heartbeatTask.cancel(true);
-        long startTime = System.currentTimeMillis();
-        long sleepInterval = 100;
-        while (!heartbeatTask.isCancelled() && !heartbeatTask.isDone()) {
-          // We will wait for 30 seconds for the task to be cancelled.
-          // If it's still not cancelled (unlikely), we will just move on.
-          long now = System.currentTimeMillis();
-          if (now - startTime > 30000) {
-            LOG.warn("Heartbeat task cannot be cancelled for unknown reason. QueryId: " + queryId);
-            break;
-          }
-          try {
-            Thread.sleep(sleepInterval);
-          } catch (InterruptedException e) {
-          }
-          sleepInterval *= 2;
+  private synchronized void stopHeartbeat() {

Review Comment:
   added





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

            Worklog Id:     (was: 753311)
    Remaining Estimate: 0h
            Time Spent: 10m

> Hive transaction rollback should be thread-safe
> -----------------------------------------------
>
>                 Key: HIVE-26121
>                 URL: https://issues.apache.org/jira/browse/HIVE-26121
>             Project: Hive
>          Issue Type: Task
>            Reporter: Denys Kuzmenko
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> When Hive query is being interrupted via cancel request, both the background pool thread (HiveServer2-Background) executing the query and the HttpHandler thread (HiveServer2-Handler) running the HiveSession.cancelOperation logic will eventually trigger the below method:
> {code}
> DriverTxnHandler.endTransactionAndCleanup(boolean commit)
> {code}
> Since this method could be invoked concurrently we need to synchronize access to it, so that only 1 thread would attempt to abort the transaction and stop the heartbeat.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)