Source:
<code>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())) { <START> resultSize += fs.getLen(); <END> } 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; }</code><technical_language>new changes done in HIVE-21279, is this a file, this a directory? confirm FileStatus.getLen() correctly returns size of directory's contents, if this a directory</technical_language>

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; }