Skip to content

[SPARK-34125][CORE][2.4] Make EventLoggingListener.codecMap thread-safe #31194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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
Expand Up @@ -21,8 +21,9 @@ import java.io._
import java.net.URI
import java.nio.charset.StandardCharsets
import java.util.Locale
import java.util.concurrent.ConcurrentHashMap
import java.util.function.Function

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

import org.apache.hadoop.conf.Configuration
Expand Down Expand Up @@ -290,7 +291,7 @@ private[spark] object EventLoggingListener extends Logging {
private val LOG_FILE_PERMISSIONS = new FsPermission(Integer.parseInt("770", 8).toShort)

// A cache for compression codecs to avoid creating the same codec many times
private val codecMap = new mutable.HashMap[String, CompressionCodec]
private val codecMap = new ConcurrentHashMap[String, CompressionCodec]

/**
* Write metadata about an event log to the given stream.
Expand Down Expand Up @@ -357,7 +358,10 @@ private[spark] object EventLoggingListener extends Logging {
val in = new BufferedInputStream(fs.open(log))
try {
val codec = codecName(log).map { c =>
codecMap.getOrElseUpdate(c, CompressionCodec.createCodec(new SparkConf, c))
codecMap.computeIfAbsent(c, new Function[String, CompressionCodec] {
override def apply(key: String): CompressionCodec =
CompressionCodec.createCodec(new SparkConf, key)
})
}
codec.map(_.compressedInputStream(in)).getOrElse(in)
} catch {
Expand Down