Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

$(document).ready(function() {
if ($('#last-updated').length) {
var lastUpdatedMillis = Number($('#last-updated').text());
var updatedDate = new Date(lastUpdatedMillis);
$('#last-updated').text(updatedDate.toLocaleDateString()+", "+updatedDate.toLocaleTimeString())
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ private[history] case class LoadedAppUI(

private[history] abstract class ApplicationHistoryProvider {

/**
* Returns the count of application event logs that the provider is currently still processing.
* History Server UI can use this to indicate to a user that the application listing on the UI
* can be expected to list additional known applications once the processing of these
* application event logs completes.
*
* A History Provider that does not have a notion of count of event logs that may be pending
* for processing need not override this method.
*
* @return Count of application event logs that are currently under process
*/
def getEventLogsUnderProcess(): Int = {
return 0;
}

/**
* Returns the time the history provider last updated the application history information
*
* @return 0 if this is undefined or unsupported, otherwise the last updated time in millis
*/
def getLastUpdatedTime(): Long = {
return 0;
}

/**
* Returns a list of applications available for the history server to show.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.apache.spark.deploy.history

import java.io.{FileNotFoundException, IOException, OutputStream}
import java.util.UUID
import java.util.concurrent.{Executors, ExecutorService, TimeUnit}
import java.util.concurrent.{Executors, ExecutorService, Future, TimeUnit}
import java.util.zip.{ZipEntry, ZipOutputStream}

import scala.collection.mutable
Expand Down Expand Up @@ -108,7 +108,7 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)

// The modification time of the newest log detected during the last scan. Currently only
// used for logging msgs (logs are re-scanned based on file size, rather than modtime)
private var lastScanTime = -1L
private val lastScanTime = new java.util.concurrent.atomic.AtomicLong(-1)

// Mapping of application IDs to their metadata, in descending end time order. Apps are inserted
// into the map in order, so the LinkedHashMap maintains the correct ordering.
Expand All @@ -120,6 +120,8 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
// List of application logs to be deleted by event log cleaner.
private var attemptsToClean = new mutable.ListBuffer[FsApplicationAttemptInfo]

private val pendingReplayTasksCount = new java.util.concurrent.atomic.AtomicInteger(0)

/**
* Return a runnable that performs the given operation on the event logs.
* This operation is expected to be executed periodically.
Expand Down Expand Up @@ -226,6 +228,10 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
applications.get(appId)
}

override def getEventLogsUnderProcess(): Int = pendingReplayTasksCount.get()

override def getLastUpdatedTime(): Long = lastScanTime.get()

override def getAppUI(appId: String, attemptId: Option[String]): Option[LoadedAppUI] = {
try {
applications.get(appId).flatMap { appInfo =>
Expand Down Expand Up @@ -329,26 +335,43 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
if (logInfos.nonEmpty) {
logDebug(s"New/updated attempts found: ${logInfos.size} ${logInfos.map(_.getPath)}")
}
logInfos.map { file =>
replayExecutor.submit(new Runnable {

var tasks = mutable.ListBuffer[Future[_]]()

try {
for (file <- logInfos) {
tasks += replayExecutor.submit(new Runnable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need for this step? Why can't we just pendingReplayTasksCount.addAndGet(logInfos.size) below and only have to add the finally code block. This seems like a lot of unnecessary code change.

Copy link
Contributor Author

@vijoshi vijoshi Oct 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the replayExecutor.submit can raise an exception resulting in fewer logInfos getting queued for replay. although one can argue that the underlying ExecutorService implementation used today will probably not do this, but I did not feel comfortable leaving this possibility out. note that - if there were to be an exception on the replayExecutor. submit( ) it would break not only the counting logic (assuming we'd already done a pendingReplayTasksCount.addAndGet(logInfos.size) instead of only adding as many as got successfully submitted) but also the older one of preventing a new thread getting scheduled for "checkForLogs( )" while there are tasks already running in replayExecutor.

however if there's a thought that we can completely ignore the possibility of exceptions on replayExecutor.submit( ), I can optimise the code on those lines. Let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding the catch at the end of checkForLogs would stop any current issue, but without it your new counting code would break, so with the addition of the counting code this change makes sense.

override def run(): Unit = mergeApplicationListing(file)
})
}
.foreach { task =>
try {
// Wait for all tasks to finish. This makes sure that checkForLogs
// is not scheduled again while some tasks are already running in
// the replayExecutor.
task.get()
} catch {
case e: InterruptedException =>
throw e
case e: Exception =>
logError("Exception while merging application listings", e)
}
} catch {
// let the iteration over logInfos break, since an exception on
// replayExecutor.submit (..) indicates the ExecutorService is unable
// to take any more submissions at this time

case e: Exception =>
logError(s"Exception while submitting event log for replay", e)
}

pendingReplayTasksCount.addAndGet(tasks.size)

tasks.foreach { task =>
try {
// Wait for all tasks to finish. This makes sure that checkForLogs
// is not scheduled again while some tasks are already running in
// the replayExecutor.
task.get()
} catch {
case e: InterruptedException =>
throw e
case e: Exception =>
logError("Exception while merging application listings", e)
} finally {
pendingReplayTasksCount.decrementAndGet()
}
}

lastScanTime = newLastScanTime
lastScanTime.set(newLastScanTime)
} catch {
case e: Exception => logError("Exception in checking for event log updates", e)
}
Expand All @@ -365,7 +388,7 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
} catch {
case e: Exception =>
logError("Exception encountered when attempting to update last scan time", e)
lastScanTime
lastScanTime.get()
} finally {
if (!fs.delete(path, true)) {
logWarning(s"Error deleting ${path}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,30 @@ private[history] class HistoryPage(parent: HistoryServer) extends WebUIPage("")
Option(request.getParameter("showIncomplete")).getOrElse("false").toBoolean

val allAppsSize = parent.getApplicationList().count(_.completed != requestedIncomplete)
val eventLogsUnderProcessCount = parent.getEventLogsUnderProcess()
val lastUpdatedTime = parent.getLastUpdatedTime()
val providerConfig = parent.getProviderConfig()
val content =
<script src={UIUtils.prependBaseUri("/static/historypage-common.js")}></script>
<div>
<div class="span12">
<ul class="unstyled">
{providerConfig.map { case (k, v) => <li><strong>{k}:</strong> {v}</li> }}
</ul>
{
if (eventLogsUnderProcessCount > 0) {
<p>There are {eventLogsUnderProcessCount} event log(s) currently being
processed which may result in additional applications getting listed on this page.
Refresh the page to view updates. </p>
}
}

{
if (lastUpdatedTime > 0) {
<p>Last updated: <span id="last-updated">{lastUpdatedTime}</span></p>
}
}

{
if (allAppsSize > 0) {
<script src={UIUtils.prependBaseUri("/static/dataTables.rowsGroup.js")}></script> ++
Expand All @@ -46,6 +63,8 @@ private[history] class HistoryPage(parent: HistoryServer) extends WebUIPage("")
<script>setAppLimit({parent.maxApplications})</script>
} else if (requestedIncomplete) {
<h4>No incomplete applications found!</h4>
} else if (eventLogsUnderProcessCount > 0) {
<h4>No completed applications found!</h4>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to rebase your code and see if this is still the cleanest way of doing this. The code below this was recently changed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, think it looks ok with the latest changes merged as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else {
<h4>No completed applications found!</h4> ++ parent.emptyListingHtml
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ class HistoryServer(
provider.getListing()
}

def getEventLogsUnderProcess(): Int = {
provider.getEventLogsUnderProcess()
}

def getLastUpdatedTime(): Long = {
provider.getLastUpdatedTime()
}

def getApplicationInfoList: Iterator[ApplicationInfo] = {
getApplicationList().map(ApplicationsListResource.appHistoryInfoToPublicAppInfo)
}
Expand Down