Skip to content

Commit

Permalink
[SPARK-13280] [streaming] Use a better logger name for FileBasedWrite…
Browse files Browse the repository at this point in the history
…AheadLog.

The new logger name is under the org.apache.spark namespace, and also
adds the caller tag after a ".", so that it's possible to disable all
possible instances of FileBasedWriteAheadLog with the same rule.

The detection of the caller name was also enhanced a bit to ignore
some common things that show up in the call stack.
  • Loading branch information
Marcelo Vanzin committed Feb 11, 2016
1 parent 719973b commit a83f2e0
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ private[streaming] class FileBasedWriteAheadLog(
import FileBasedWriteAheadLog._

private val pastLogs = new ArrayBuffer[LogInfo]
private val callerNameTag = getCallerName.map(c => s" for $c").getOrElse("")
private val callerName = getCallerName

private val threadpoolName = s"WriteAheadLogManager $callerNameTag"
private val threadpoolName = {
"WriteAheadLogManager" + callerName.map(c => s" for $c").getOrElse("")
}
private val threadpool = ThreadUtils.newDaemonCachedThreadPool(threadpoolName, 20)
private val executionContext = ExecutionContext.fromExecutorService(threadpool)
override protected val logName = s"WriteAheadLogManager $callerNameTag"

override protected def logName = {
getClass.getName.stripSuffix("$") +
callerName.map("_" + _).getOrElse("").replaceAll("[ ]", "_")
}

private var currentLogPath: Option[String] = None
private var currentLogWriter: FileBasedWriteAheadLogWriter = null
Expand Down Expand Up @@ -253,8 +259,12 @@ private[streaming] object FileBasedWriteAheadLog {
}

def getCallerName(): Option[String] = {
val stackTraceClasses = Thread.currentThread.getStackTrace().map(_.getClassName)
stackTraceClasses.find(!_.contains("WriteAheadLog")).flatMap(_.split("\\.").lastOption)
val blacklist = Seq("WriteAheadLog", "Logging", "java.lang", "scala.")
Thread.currentThread.getStackTrace()
.map(_.getClassName)
.find { c => !blacklist.exists(c.contains) }
.flatMap(_.split("\\.").lastOption)
.flatMap(_.split("\\$\\$").headOption)
}

/** Convert a sequence of files to a sequence of sorted LogInfo objects */
Expand Down

0 comments on commit a83f2e0

Please sign in to comment.