File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
core/src/main/scala/org/apache/spark/io Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -149,12 +149,7 @@ class LZFCompressionCodec(conf: SparkConf) extends CompressionCodec {
149149 */
150150@ DeveloperApi
151151class SnappyCompressionCodec (conf : SparkConf ) extends CompressionCodec {
152-
153- try {
154- Snappy .getNativeLibraryVersion
155- } catch {
156- case e : Error => throw new IllegalArgumentException (e)
157- }
152+ val version = SnappyCompressionCodec .version
158153
159154 override def compressedOutputStream (s : OutputStream ): OutputStream = {
160155 val blockSize = conf.getSizeAsBytes(" spark.io.compression.snappy.blockSize" , " 32k" ).toInt
@@ -164,6 +159,19 @@ class SnappyCompressionCodec(conf: SparkConf) extends CompressionCodec {
164159 override def compressedInputStream (s : InputStream ): InputStream = new SnappyInputStream (s)
165160}
166161
162+ /**
163+ * Object guards against memory leak bug in snappy-java library:
164+ * (https://github.com/xerial/snappy-java/issues/131).
165+ * Before a new version of the library, we only call the method once and cache the result.
166+ */
167+ private final object SnappyCompressionCodec {
168+ private lazy val version : String = try {
169+ Snappy .getNativeLibraryVersion
170+ } catch {
171+ case e : Error => throw new IllegalArgumentException (e)
172+ }
173+ }
174+
167175/**
168176 * Wrapper over [[SnappyOutputStream ]] which guards against write-after-close and double-close
169177 * issues. See SPARK-7660 for more details. This wrapping can be removed if we upgrade to a version
You can’t perform that action at this time.
0 commit comments