Github user tdas commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15285#discussion_r83811950
  
    --- Diff: core/src/main/scala/org/apache/spark/util/Utils.scala ---
    @@ -1448,14 +1452,70 @@ private[spark] object Utils extends Logging {
         CallSite(shortForm, longForm)
       }
     
    +  val UNCOMPRESSED_LOG_FILE_LENGTH_CACHE_SIZE = 
"spark.worker.ui.compressedLogFileLengthCacheSize"
    +  val DEFAULT_UNCOMPRESSED_LOG_FILE_LENGTH_CACHE_SIZE = 100
    +  private var compressedLogFileLengthCache: LoadingCache[String, 
java.lang.Long] = null
    +  private def getCompressedLogFileLengthCache(
    +      sparkConf: SparkConf): LoadingCache[String, java.lang.Long] = 
this.synchronized {
    +    if (compressedLogFileLengthCache == null) {
    +      val compressedLogFileLengthCacheSize = sparkConf.getInt(
    +        UNCOMPRESSED_LOG_FILE_LENGTH_CACHE_SIZE,
    +        DEFAULT_UNCOMPRESSED_LOG_FILE_LENGTH_CACHE_SIZE)
    +      compressedLogFileLengthCache = CacheBuilder.newBuilder()
    +        .maximumSize(compressedLogFileLengthCacheSize)
    +        .build[String, java.lang.Long](new CacheLoader[String, 
java.lang.Long]() {
    +        override def load(path: String): java.lang.Long = {
    +          Utils.getFileLength(new File(path))
    +        }
    +      })
    +    }
    +    compressedLogFileLengthCache
    +  }
    +
    +  def getFileLength(file: File, sparkConf: SparkConf): Long = {
    +    if (file.getName.endsWith(".gz")) {
    +      getCompressedLogFileLengthCache(sparkConf).get(file.getAbsolutePath)
    +    } else {
    +      getFileLength(file)
    +    }
    +  }
    +
    +  /** Return the file length, if the file is compressed it returns the 
uncompressed file length. */
    +  private[util] def getFileLength(file: File): Long = {
    +    try {
    +      // Uncompress .gz file to determine file size.
    +      if (file.getName.endsWith(".gz")) {
    +        var fileSize = 0L
    +        val gzInputStream = new GZIPInputStream(new FileInputStream(file))
    +        val bufSize = 1024
    +        val buf = new Array[Byte](bufSize)
    +        var numBytes = IOUtils.read(gzInputStream, buf)
    +        while (numBytes > 0) {
    +          fileSize += numBytes
    +          numBytes = IOUtils.read(gzInputStream, buf)
    +        }
    +        fileSize
    +      } else {
    +        file.length
    +      }
    +    } catch {
    +      case e: Throwable =>
    +        logWarning(s"Cannot get file length of ${file}", e)
    --- End diff --
    
    Actually, this is a critical error. Better to make this logError


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to