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

    https://github.com/apache/spark/pull/3065#discussion_r22266590
  
    --- Diff: 
core/src/main/scala/org/apache/spark/storage/BlockSerializer.scala ---
    @@ -0,0 +1,116 @@
    +/*
    + * 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.
    + */
    +
    +package org.apache.spark.storage
    +
    +import java.io.{ByteArrayOutputStream, BufferedOutputStream, InputStream, 
OutputStream}
    +import java.nio.ByteBuffer
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.io.CompressionCodec
    +import org.apache.spark.serializer.{SerializationStream, 
DeserializationStream, Serializer}
    +import org.apache.spark.util.ByteBufferInputStream
    +
    +class BlockSerializer(conf: SparkConf, serializer: Serializer) {
    +  // Whether to compress broadcast variables that are stored
    +  private val compressBroadcast = 
conf.getBoolean("spark.broadcast.compress", true)
    +  // Whether to compress shuffle output that are stored
    +  private val compressShuffle = conf.getBoolean("spark.shuffle.compress", 
true)
    +  // Whether to compress RDD partitions that are stored serialized
    +  private val compressRdds = conf.getBoolean("spark.rdd.compress", false)
    +  // Whether to compress shuffle output temporarily spilled to disk
    +  private val compressShuffleSpill = 
conf.getBoolean("spark.shuffle.spill.compress", true)
    +
    +  /* The compression codec to use. Note that the "lazy" val is necessary 
because we want to delay
    +   * the initialization of the compression codec until it is first used. 
The reason is that a Spark
    +   * program could be using a user-defined codec in a third party jar, 
which is loaded in
    +   * Executor.updateDependencies. When the BlockManager is initialized, 
user level jars hasn't been
    +   * loaded yet. */
    +  private lazy val compressionCodec: CompressionCodec = 
CompressionCodec.createCodec(conf)
    +
    +  private def shouldCompress(blockId: BlockId): Boolean = {
    +    blockId match {
    +      case _: ShuffleBlockId => compressShuffle
    +      case _: BroadcastBlockId => compressBroadcast
    +      case _: RDDBlockId => compressRdds
    +      case _: TempLocalBlockId => compressShuffleSpill
    +      case _: TempShuffleBlockId => compressShuffle
    +      case _ => false
    +    }
    +  }
    +
    +  /**
    +   * Wrap an output stream for compression if block compression is enabled 
for its block type
    +   */
    +  private def wrapForCompression(blockId: BlockId, s: OutputStream): 
OutputStream = {
    +    if (shouldCompress(blockId)) 
compressionCodec.compressedOutputStream(s) else s
    +  }
    +
    +  /**
    +   * Wrap an input stream for compression if block compression is enabled 
for its block type
    +   */
    +  private def wrapForCompression(blockId: BlockId, s: InputStream): 
InputStream = {
    +    if (shouldCompress(blockId)) compressionCodec.compressedInputStream(s) 
else s
    +  }
    +
    +  /** Serializes into a stream. */
    +  def dataSerializeStream(
    --- End diff --
    
    In fact, the names can be made more imperative (similar to 
`wrapForCompression`): `serializeToStream`, `deserializeFromStream`, etc. 


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to