Repository: hive
Updated Branches:
  refs/heads/branch-3 c8b167ff3 -> 0821efcad


HIVE-19138: Results cache: allow queries waiting on pending cache entries to 
check cache again if pending query fails (Jason Dere, reviewed by Deepak 
Jaiswal)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/0821efca
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/0821efca
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/0821efca

Branch: refs/heads/branch-3
Commit: 0821efcad500a5798ad9853320f5687c67b81372
Parents: c8b167f
Author: Jason Dere <jd...@hortonworks.com>
Authored: Tue Apr 10 19:09:28 2018 -0700
Committer: Jason Dere <jd...@hortonworks.com>
Committed: Tue Apr 10 19:10:29 2018 -0700

----------------------------------------------------------------------
 .../hadoop/hive/ql/parse/SemanticAnalyzer.java  | 56 +++++++++++---------
 1 file changed, 30 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/0821efca/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java 
b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
index 7f00108..10982dd 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
@@ -14640,39 +14640,43 @@ public class SemanticAnalyzer extends 
BaseSemanticAnalyzer {
     }
     // Don't increment the reader count for explain queries.
     boolean isExplainQuery = (ctx.getExplainConfig() != null);
-    QueryResultsCache.CacheEntry cacheEntry = 
QueryResultsCache.getInstance().lookup(lookupInfo);
-    if (cacheEntry != null) {
-      // Potentially wait on the cache entry if entry is in PENDING status
-      // Blocking here can potentially be dangerous - for example if the 
global compile lock
-      // is used this will block all subsequent queries that try to acquire 
the compile lock,
-      // so it should not be done unless parallel compilation is enabled.
-      // We might not want to block for explain queries as well.
-      if (cacheEntry.getStatus() == 
QueryResultsCache.CacheEntryStatus.PENDING) {
-        if (!isExplainQuery &&
-            
conf.getBoolVar(HiveConf.ConfVars.HIVE_QUERY_RESULTS_CACHE_WAIT_FOR_PENDING_RESULTS)
 &&
-            
conf.getBoolVar(HiveConf.ConfVars.HIVE_SERVER2_PARALLEL_COMPILATION)) {
-          if (!cacheEntry.waitForValidStatus()) {
-            LOG.info("Waiting on pending cacheEntry, but it failed to become 
valid");
+    do {
+      QueryResultsCache.CacheEntry cacheEntry = 
QueryResultsCache.getInstance().lookup(lookupInfo);
+      if (cacheEntry != null) {
+        // Potentially wait on the cache entry if entry is in PENDING status
+        // Blocking here can potentially be dangerous - for example if the 
global compile lock
+        // is used this will block all subsequent queries that try to acquire 
the compile lock,
+        // so it should not be done unless parallel compilation is enabled.
+        // We might not want to block for explain queries as well.
+        if (cacheEntry.getStatus() == 
QueryResultsCache.CacheEntryStatus.PENDING) {
+          if (!isExplainQuery &&
+              
conf.getBoolVar(HiveConf.ConfVars.HIVE_QUERY_RESULTS_CACHE_WAIT_FOR_PENDING_RESULTS)
 &&
+              
conf.getBoolVar(HiveConf.ConfVars.HIVE_SERVER2_PARALLEL_COMPILATION)) {
+            if (!cacheEntry.waitForValidStatus()) {
+              LOG.info("Waiting on pending cacheEntry, but it failed to become 
valid");
+              // The pending query we were waiting on failed, but there might 
still be another
+              // pending or completed entry in the cache that can satisfy this 
query. Lookup again.
+              continue;
+            }
+          } else {
+            LOG.info("Not waiting for pending cacheEntry");
             return false;
           }
-        } else {
-          LOG.info("Not waiting for pending cacheEntry");
-          return false;
         }
-      }
 
-      if (cacheEntry.getStatus() == QueryResultsCache.CacheEntryStatus.VALID) {
-        if (!isExplainQuery) {
-          if (!cacheEntry.addReader()) {
-            return false;
+        if (cacheEntry.getStatus() == 
QueryResultsCache.CacheEntryStatus.VALID) {
+          if (!isExplainQuery) {
+            if (!cacheEntry.addReader()) {
+              return false;
+            }
           }
+          // Use the cache rather than full query execution.
+          // At this point the caller should return from semantic analysis.
+          useCachedResult(cacheEntry);
+          return true;
         }
-        // Use the cache rather than full query execution.
-        // At this point the caller should return from semantic analysis.
-        useCachedResult(cacheEntry);
-        return true;
       }
-    }
+    } while (false);
     return false;
   }
 

Reply via email to