LuciferYang commented on code in PR #36237:
URL: https://github.com/apache/spark/pull/36237#discussion_r852703387
##########
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala:
##########
@@ -325,12 +325,18 @@ private[history] class FsHistoryProvider(conf: SparkConf,
clock: Clock)
override def getListing(): Iterator[ApplicationInfo] = {
// Return the listing in end time descending order.
- listing.view(classOf[ApplicationInfoWrapper])
+ // SPARK-38896: tryWithResource cannot be used here
+ // because this method needs to return an `Iterator`.
+ val closeableIter = listing.view(classOf[ApplicationInfoWrapper])
.index("endTime")
.reverse()
- .iterator()
- .asScala
- .map(_.toApplicationInfo())
+ .closeableIterator()
+ val dataIter = closeableIter.asScala.map(_.toApplicationInfo())
+ new Iterator[ApplicationInfo] with Closeable {
+ override def hasNext: Boolean = dataIter.hasNext
+ override def next(): ApplicationInfo = dataIter.next()
+ override def close(): Unit = closeableIter.close()
+ }
Review Comment:
Or we can return
```
KVUtils.mapToSeq(listing.view(classOf[ApplicationInfoWrapper])
.index("endTime")
.reverse())(_.toApplicationInfo()).iterator
```
This seems simpler, and the caller doesn't need to care about closing
`LevelDB/RocksDBIterator`, but it may use more memory
--
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]