diff --git a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java index e344ab5..f8c0baa 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java @@ -1205,11 +1205,35 @@ private ReentrantLock tryAcquireCompileLock(boolean isParallelEnabled, long maxCompileLockWaitTime = HiveConf.getTimeVar( this.conf, ConfVars.HIVE_SERVER2_COMPILE_LOCK_TIMEOUT, TimeUnit.SECONDS); + + final String lockAcquiredMsg = "Acquired the compile lock."; + + // First shot without waiting. + try { + if (compileLock.tryLock(0, TimeUnit.SECONDS)) { + LOG.debug(lockAcquiredMsg); + return compileLock; + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + if (LOG.isDebugEnabled()) { + LOG.debug("Interrupted Exception ignored", e); + } + return null; + } + + // If the first shot fails, then we log the waiting messages. + if (LOG.isDebugEnabled()) { + LOG.debug("Waiting to acquire compile lock: " + command); + } + + OperationLog ol = OperationLog.getCurrentOperationLog(); + if (ol != null) { + ol.writeOperationLog(LoggingLevel.EXECUTION, "Waiting to acquire compile lock.\n"); + } + if (maxCompileLockWaitTime > 0) { - try { - if (LOG.isDebugEnabled()) { - LOG.debug("Waiting to acquire compile lock: " + command); - } + try { if(!compileLock.tryLock(maxCompileLockWaitTime, TimeUnit.SECONDS)) { errorMessage = ErrorMsg.COMPILE_LOCK_TIMED_OUT.getErrorCodedMsg(); LOG.error(errorMessage + ": " + command); @@ -1226,7 +1250,10 @@ private ReentrantLock tryAcquireCompileLock(boolean isParallelEnabled, compileLock.lock(); } - LOG.debug("Acquired the compile lock"); + LOG.debug(lockAcquiredMsg); + if (ol != null) { + ol.writeOperationLog(LoggingLevel.EXECUTION, lockAcquiredMsg + "\n"); + } return compileLock; }