Source:
public boolean setEntryValid(CacheEntry cacheEntry, FetchWork fetchWork) { Path queryResultsPath = null; Path cachedResultsPath = null; try { assert(fetchWork.getFilesToFetch() != null ); boolean requiresCaching = true; queryResultsPath = fetchWork.getTblDir(); FileSystem resultsFs = queryResultsPath.getFileSystem(conf); long resultSize = 0; for(FileStatus fs:fetchWork.getFilesToFetch()) { if(resultsFs.exists(fs.getPath())) { resultSize += fs.getLen(); } else { requiresCaching = false; break; } } if (!shouldEntryBeAdded(cacheEntry, resultSize)) { return false; } synchronized (cacheEntry) { if (cacheEntry.getStatus() == CacheEntryStatus.INVALID) { return false; } if (requiresCaching) { cacheEntry.cachedResultPaths = new HashSet<>(); for(FileStatus fs:fetchWork.getFilesToFetch()) { cacheEntry.cachedResultPaths.add(fs); } } FetchWork fetchWorkForCache = new FetchWork(fetchWork.getTblDir(), fetchWork.getTblDesc(), fetchWork.getLimit()); fetchWorkForCache.setCachedResult(true); fetchWorkForCache.setFilesToFetch(fetchWork.getFilesToFetch()); cacheEntry.fetchWork = fetchWorkForCache; cacheEntry.size = resultSize; this.cacheSize += resultSize; cacheEntry.setStatus(CacheEntryStatus.VALID); cacheEntry.addReader(); scheduleEntryInvalidation(cacheEntry); cacheEntry.notifyAll(); } incrementMetric(MetricsConstant.QC_VALID_ENTRIES); incrementMetric(MetricsConstant.QC_TOTAL_ENTRIES_ADDED); } catch (Exception err) { String queryText = cacheEntry.getQueryText(); LOG.error("Failed to create cache entry for query results for query: " + queryText, err); cacheEntry.size = 0; cacheEntry.cachedResultsPath = null; cacheEntry.invalidate(); return false; } return true; }

Target:
public boolean setEntryValid(CacheEntry cacheEntry, FetchWork fetchWork) { Path queryResultsPath = null; Path cachedResultsPath = null; try { assert(fetchWork.getFilesToFetch() != null ); boolean requiresCaching = true; queryResultsPath = fetchWork.getTblDir(); FileSystem resultsFs = queryResultsPath.getFileSystem(conf); long resultSize = 0; for(FileStatus fs:fetchWork.getFilesToFetch()) { if(resultsFs.exists(fs.getPath())) { resultSize += fs.getLen(); } else { requiresCaching = false; break; } } if (!shouldEntryBeAdded(cacheEntry, resultSize)) { return false; } synchronized (cacheEntry) { if (cacheEntry.getStatus() == CacheEntryStatus.INVALID) { return false; } if (requiresCaching) { cacheEntry.cachedResultPaths = new HashSet<>(); for(FileStatus fs:fetchWork.getFilesToFetch()) { cacheEntry.cachedResultPaths.add(fs); } LOG.info("Cached query result paths located at (size {}) for query '{}'", queryResultsPath, resultSize, cacheEntry.getQueryText()); } FetchWork fetchWorkForCache = new FetchWork(fetchWork.getTblDir(), fetchWork.getTblDesc(), fetchWork.getLimit()); fetchWorkForCache.setCachedResult(true); fetchWorkForCache.setFilesToFetch(fetchWork.getFilesToFetch()); cacheEntry.fetchWork = fetchWorkForCache; cacheEntry.size = resultSize; this.cacheSize += resultSize; cacheEntry.setStatus(CacheEntryStatus.VALID); cacheEntry.addReader(); scheduleEntryInvalidation(cacheEntry); cacheEntry.notifyAll(); } incrementMetric(MetricsConstant.QC_VALID_ENTRIES); incrementMetric(MetricsConstant.QC_TOTAL_ENTRIES_ADDED); } catch (Exception err) { String queryText = cacheEntry.getQueryText(); LOG.error("Failed to create cache entry for query results for query: " + queryText, err); cacheEntry.size = 0; cacheEntry.cachedResultsPath = null; cacheEntry.invalidate(); return false; } return true; }