cloud-fan commented on code in PR #59857:
URL: https://github.com/apache/spark/pull/59857#discussion_r4595597924
##########
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:
**Nit (P3):** This scaladoc names only the path as what decides which
indexes the method finds and what each one is checked against. The method also
applies the `includeTimeTravel` rule. Unless `includeTimeTravel` is true,
`fileIndexOf` drops a V2 `FileTable` relation that has a `timeTravelSpec`
(lines 677-679), and `needToRefresh` rejects an index whose `isTimeTravel` is
true (line 705).
By the code, with write-driven invalidation (`includeTimeTravel = false`,
which `InsertIntoHadoopFsRelationCommand` passes), take a cached plan whose
only relation under the path reads a pinned version. That plan has a
file-backed relation under `qualifiedPath`, yet the method returns false and
refreshes nothing. Someone reading only this scaladoc would expect that index
to be found and refreshed. There is no runtime effect, so this is a wording fix
only.
A possible rewording follows. It keeps the at-most-once check scoped to one
entry's plan, because only an index that passes the check joins
`refreshedIndexes`, so an index that fails it for one entry is checked again
for the next entry:
```suggestion
* 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. Unless `includeTimeTravel` is true,
relations pinned to a
* time-travel version are neither found nor refreshed. Every match is
refreshed because the
* rebuilt cache entry reuses these indexes. Each distinct index in `plan`
is checked against
* the path and the time-travel rule at most once, and an index already in
`refreshedIndexes`
* passed that check for an earlier entry of the same `recacheByPath` call.
```
**Verification:**
- **Inspection:** The lookupAndRefresh scaladoc in CacheManager.scala names
both conditions the method applies before it counts an index as found and
refreshes it: one of the index's root paths is under qualifiedPath, and either
includeTimeTravel is true or the relation is not pinned to a time-travel
version. It still limits the at-most-once check to the distinct indexes of one
entry's plan, and the method's code is unchanged.
--
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]