Skip to content

Commit a50e8b1

Browse files
author
pgandhi
committed
[SPARK-24851] : Avoiding extra store lookup and adding href links
1 parent 3151a62 commit a50e8b1

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

core/src/main/scala/org/apache/spark/status/AppStatusStore.scala

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ private[spark] class AppStatusStore(
9494
}.toSeq
9595
}
9696

97-
def getJobIdsAssociatedWithStage(stageId: Int, stageAttemptId: Int): Seq[Int] = {
98-
val stageKey = Array(stageId, stageAttemptId)
99-
val jobIds = store.read(classOf[StageDataWrapper], stageKey).jobIds.toSeq
100-
jobIds
101-
}
102-
10397
def lastStageAttempt(stageId: Int): v1.StageData = {
10498
val it = store.view(classOf[StageDataWrapper])
10599
.index("stageId")
@@ -118,10 +112,13 @@ private[spark] class AppStatusStore(
118112
}
119113
}
120114

121-
def stageAttempt(stageId: Int, stageAttemptId: Int, details: Boolean = false): v1.StageData = {
115+
def stageAttempt(stageId: Int, stageAttemptId: Int, details: Boolean = false): StageDataWrapper = {
122116
val stageKey = Array(stageId, stageAttemptId)
123-
val stage = store.read(classOf[StageDataWrapper], stageKey).info
124-
if (details) stageWithDetails(stage) else stage
117+
val stageDataWrapper: StageDataWrapper = store.read(classOf[StageDataWrapper], stageKey)
118+
val stage = if (details) stageWithDetails(stageDataWrapper.info) else stageDataWrapper.info
119+
val jobIds = stageDataWrapper.jobIds
120+
val returnStageDataWrapper: StageDataWrapper = new StageDataWrapper(stage, jobIds, null)
121+
returnStageDataWrapper
125122
}
126123

127124
def taskCount(stageId: Int, stageAttemptId: Int): Long = {

core/src/main/scala/org/apache/spark/status/api/v1/StagesResource.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private[v1] class StagesResource extends BaseAppResource {
5656
@PathParam("stageAttemptId") stageAttemptId: Int,
5757
@QueryParam("details") @DefaultValue("true") details: Boolean): StageData = withUI { ui =>
5858
try {
59-
ui.store.stageAttempt(stageId, stageAttemptId, details = details)
59+
ui.store.stageAttempt(stageId, stageAttemptId, details = details).info
6060
} catch {
6161
case _: NoSuchElementException =>
6262
// Change the message depending on whether there are any attempts for the requested stage.

core/src/main/scala/org/apache/spark/ui/jobs/StagePage.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ private[ui] class StagePage(parent: StagesTab, store: AppStatusStore) extends We
105105
val stageAttemptId = parameterAttempt.toInt
106106

107107
val stageHeader = s"Details for Stage $stageId (Attempt $stageAttemptId)"
108+
val stageDataWrapper = parent.store.stageAttempt(stageId, stageAttemptId, details = false)
108109
val stageData = parent.store
109-
.asOption(parent.store.stageAttempt(stageId, stageAttemptId, details = false))
110+
.asOption(stageDataWrapper.info)
110111
.getOrElse {
111112
val content =
112113
<div id="no-info">
@@ -115,7 +116,7 @@ private[ui] class StagePage(parent: StagesTab, store: AppStatusStore) extends We
115116
return UIUtils.headerSparkPage(request, stageHeader, content, parent)
116117
}
117118

118-
val stageJobIds = parent.store.getJobIdsAssociatedWithStage(stageId, stageAttemptId)
119+
val stageJobIds = stageDataWrapper.jobIds.toSeq
119120

120121
val localitySummary = store.localitySummary(stageData.stageId, stageData.attemptId)
121122

@@ -187,7 +188,10 @@ private[ui] class StagePage(parent: StagesTab, store: AppStatusStore) extends We
187188
{if (!stageJobIds.isEmpty) {
188189
<li>
189190
<strong>Associated Job Ids: </strong>
190-
{stageJobIds}
191+
{for(jobId <- stageJobIds) yield {val detailUrl = "%s/jobs/job/?id=%s".format(
192+
UIUtils.prependBaseUri(request, parent.basePath), jobId)
193+
<a href={s"${detailUrl}"}>{s"${jobId}"} &nbsp;&nbsp;</a>
194+
}}
191195
</li>
192196
}}
193197
</ul>
@@ -1055,7 +1059,7 @@ private[ui] object ApiHelper {
10551059
}
10561060

10571061
def lastStageNameAndDescription(store: AppStatusStore, job: JobData): (String, String) = {
1058-
val stage = store.asOption(store.stageAttempt(job.stageIds.max, 0))
1062+
val stage = store.asOption(store.stageAttempt(job.stageIds.max, 0).info)
10591063
(stage.map(_.name).getOrElse(""), stage.flatMap(_.description).getOrElse(job.name))
10601064
}
10611065

0 commit comments

Comments
 (0)