Skip to content

Commit 552955a

Browse files
committed
[SPARK-19748][SQL]refresh function has an wrong order to do cache invalidate and regenerate the inmemory var for InMemoryFileIndex with FileStatusCache
1 parent 9f8e392 commit 552955a

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/InMemoryFileIndex.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ class InMemoryFileIndex(
6666
}
6767

6868
override def refresh(): Unit = {
69-
refresh0()
7069
fileStatusCache.invalidateAll()
70+
refresh0()
7171
}
7272

7373
private def refresh0(): Unit = {

sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/FileIndexSuite.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,32 @@ class FileIndexSuite extends SharedSQLContext {
178178
assert(catalog2.allFiles().nonEmpty)
179179
}
180180
}
181+
182+
test("refresh for InMemoryFileIndex with FileStatusCache") {
183+
withTempDir { dir =>
184+
val fileStatusCache = FileStatusCache.getOrCreate(spark)
185+
val dirPath = new Path(dir.getCanonicalPath)
186+
val catalog = new InMemoryFileIndex(spark, Seq(dirPath), Map.empty,
187+
None, fileStatusCache) {
188+
def leafFilePaths: Seq[Path] = leafFiles.keys.toSeq
189+
def leafDirPaths: Seq[Path] = leafDirToChildrenFiles.keys.toSeq
190+
}
191+
192+
assert(catalog.leafDirPaths.isEmpty)
193+
assert(catalog.leafFilePaths.isEmpty)
194+
195+
val file = new File(dir, "text.txt")
196+
stringToFile(file, "text")
197+
198+
catalog.refresh()
199+
200+
val path = new Path(file.getCanonicalPath)
201+
assert(catalog.leafFilePaths.nonEmpty && catalog
202+
.leafFilePaths.forall(p => p.toString.startsWith("file:/")))
203+
assert(catalog.leafDirPaths.nonEmpty && catalog
204+
.leafDirPaths.forall(p => p.toString.startsWith("file:/")))
205+
}
206+
}
181207
}
182208

183209
class FakeParentPathFileSystem extends RawLocalFileSystem {

0 commit comments

Comments
 (0)