joelrobin18 commented on code in PR #59857:
URL: https://github.com/apache/spark/pull/59857#discussion_r4595619707


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/CacheManager.scala:
##########
@@ -618,58 +643,69 @@ class CacheManager extends Logging with 
AdaptiveSparkPlanHelper {
       fs: FileSystem,
       includeTimeTravel: Boolean): Unit = {
     val qualifiedPath = fs.makeQualified(resourcePath)
+    // Cache entries can share a file index, so each index is refreshed once 
per call. That is
+    // enough, because the condition runs for every entry before any matched 
entry is rebuilt.
+    // Indexes are compared by reference: InMemoryFileIndex equality compares 
root paths only.
+    val refreshedIndexes =
+      Collections.newSetFromMap(new IdentityHashMap[FileIndex, 
java.lang.Boolean])
     recacheByCondition(
       spark,
-      _.plan.exists(lookupAndRefresh(_, fs, qualifiedPath, includeTimeTravel)))
+      entry => lookupAndRefresh(entry.plan, fs, qualifiedPath, 
includeTimeTravel, refreshedIndexes))
   }
 
   /**
-   * Traverses a given `plan` and searches for the occurrences of 
`qualifiedPath` in the
-   * [[org.apache.spark.sql.execution.datasources.FileIndex]] of any 
[[HadoopFsRelation]] nodes
-   * in the plan. If found, we refresh the metadata and return true. 
Otherwise, this method returns
-   * false.
+   * Searches `plan`, including its subqueries, for the
+   * [[org.apache.spark.sql.execution.datasources.FileIndex]] of file-backed 
relations under
+   * `qualifiedPath`, refreshes each matching index that is not in 
`refreshedIndexes` yet, and
+   * returns whether any was found. Every match is refreshed because the 
rebuilt cache entry reuses
+   * these indexes. Each distinct index in `plan` is checked against the path 
at most once, and an
+   * index already in `refreshedIndexes` passed that check for an earlier 
entry of the same
+   * `recacheByPath` call.

Review Comment:
   Done. Updated the wording here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to