jerrypeng commented on code in PR #56878: URL: https://github.com/apache/spark/pull/56878#discussion_r3531761567
########## core/src/main/scala/org/apache/spark/shuffle/streaming/StreamingShuffleWriter.scala: ########## @@ -0,0 +1,454 @@ +/* + * 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.shuffle.streaming + +import java.util.concurrent.{CancellationException, CompletableFuture, CountDownLatch, LinkedBlockingDeque, Semaphore, TimeUnit} +import java.util.concurrent.atomic.{AtomicBoolean, AtomicLong, AtomicReference} +import javax.annotation.concurrent.NotThreadSafe + +import scala.util.Try + +import io.netty.buffer.{ByteBuf, ByteBufOutputStream, CompositeByteBuf, Unpooled} +import io.netty.channel.{ChannelFuture, ChannelOption} + +import org.apache.spark.{SparkContext, SparkEnv, StreamingShuffleTaskLocation, TaskContext} +import org.apache.spark.internal.LogKeys +import org.apache.spark.internal.config.{EXECUTOR_ID, STREAMING_SHUFFLE_CHECKSUM_ENABLED, STREAMING_SHUFFLE_NETWORK_BUFFER_MAX_WAIT_TIME_MS, STREAMING_SHUFFLE_NETWORK_BUFFER_SIZE, STREAMING_SHUFFLE_WRITER_MAX_MEMORY} +import org.apache.spark.internal.config.Network.RPC_IO_THREADS +import org.apache.spark.memory.{MemoryConsumer, MemoryMode} +import org.apache.spark.network.TransportContext +import org.apache.spark.network.client.TransportClient +import org.apache.spark.network.netty.SparkTransportConf +import org.apache.spark.network.server.TransportServer +import org.apache.spark.network.shuffle.streaming.{DataMessage, ShuffleChecksum, StreamingShuffleMessage, StreamingShuffleMessageType, TerminationControlMessage} +import org.apache.spark.scheduler.MapStatus +import org.apache.spark.serializer.{JavaSerializerInstance, SerializationStream} +import org.apache.spark.shuffle.{ShuffleHandle, ShuffleWriter} +import org.apache.spark.util.{ErrorNotifier, Utils} + +class StreamingShuffleWriter[K, V]( + handle: ShuffleHandle, + mapId: Long, + val context: TaskContext, + serverHandler: Option[StreamingShuffleServerHandler] = None, + private[streaming] val errorNotifier: ErrorNotifier = new ErrorNotifier()) + extends ShuffleWriter[K, V] with TaskContextAwareLogging { + assert(SparkEnv.get.streamingShuffleOutputTracker.isDefined) + // Spark params. + private val conf = SparkEnv.get.conf + private val SEND_BUFFER_SIZE: Integer = 32 << 10 // 32 KB + private val RECV_BUFFER_SIZE: Integer = 512 + // The target network buffer size + private val BUFFER_SIZE: Integer = conf.get(STREAMING_SHUFFLE_NETWORK_BUFFER_SIZE) + // The interval at which we flush pending messages. + private val MAX_BUFFERING_TIME_MS = conf.get(STREAMING_SHUFFLE_NETWORK_BUFFER_MAX_WAIT_TIME_MS) + + // Shuffle details. + private val streamingShuffleHandle = handle.asInstanceOf[StreamingShuffleHandle[K, V, _]] + private val serializerInstance = streamingShuffleHandle.dependency.serializer.newInstance() + private val partitioner = streamingShuffleHandle.dependency.partitioner + private val numPartitions = partitioner.numPartitions + private val shuffleWriterId = context.partitionId() + // Total size of TCP buffers. Use Long math to avoid 32-bit overflow when numPartitions + // is large (numPartitions * buffer sizes can exceed Int.MaxValue). + private val TOTAL_TCPBUF_BYTES: Long = + numPartitions.toLong * (SEND_BUFFER_SIZE + RECV_BUFFER_SIZE) + // Total allowed memory for buffered rows, excluding TCP buffers. + private val MAX_BUFFER_BYTES: Long = math.max(numPartitions.toLong * BUFFER_SIZE * 2, Review Comment: Yup, will add logging to bubble this information up. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
