Ngone51 commented on a change in pull request #28444:
URL: https://github.com/apache/spark/pull/28444#discussion_r420906618
##########
File path: core/src/main/scala/org/apache/spark/status/AppStatusStore.scala
##########
@@ -35,8 +36,21 @@ private[spark] class AppStatusStore(
val store: KVStore,
val listener: Option[AppStatusListener] = None) {
+ /**
+ * This method contains an automatic retry logic and tries to get a valid
[[v1.ApplicationInfo]].
+ * See [SPARK-31632] The ApplicationInfo in KVStore may be accessed before
it's prepared
+ */
def applicationInfo(): v1.ApplicationInfo = {
- store.view(classOf[ApplicationInfoWrapper]).max(1).iterator().next().info
+ var iterator =
store.view(classOf[ApplicationInfoWrapper]).max(1).iterator()
+ val startTime = System.nanoTime()
+ while (!iterator.hasNext &&
+ System.nanoTime() - startTime < AppStatusStore.FETCH_APP_INFO_TIMEOUT) {
+ // Wait a while to see if the ApplicationInfo has been written to the
store.
+ Thread.sleep(200)
+ iterator = store.view(classOf[ApplicationInfoWrapper]).max(1).iterator()
+ }
+ // The next() call may still throw a NoSuchElement exception.
Review comment:
I think we should explicitly throw a SparkException here if the
`iterator` is still empty to say something like "No available ApplicationInfo
after waiting 5 seconds..."
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]