juliuszsompolski commented on code in PR #41315: URL: https://github.com/apache/spark/pull/41315#discussion_r1260974008
########## connector/connect/server/src/main/scala/org/apache/spark/sql/connect/execution/ExecutePlanResponseSender.scala: ########## @@ -0,0 +1,113 @@ +/* + * 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.sql.connect.execution + +import io.grpc.stub.StreamObserver + +import org.apache.spark.connect.proto.ExecutePlanResponse +import org.apache.spark.internal.Logging + +/** + * ExecutePlanResponseSender sends responses to the GRPC stream. + * It runs on the RPC thread, and gets notified by ExecutePlanResponseObserver about available + * responses. + * It notifies the ExecutePlanResponseObserver back about cached responses that can be removed + * after being sent out. + * @param responseObserver the GRPC request StreamObserver + */ +private[connect] class ExecutePlanResponseSender( + grpcObserver: StreamObserver[ExecutePlanResponse]) extends Logging { + + private var detached = false + + /** Detach this sender from executionObserver. + * Called only from executionObserver that this sender is attached to. + * executionObserver holds lock, and needs to notify after this call. */ + def detach(): Unit = { + if (detached == true) { + throw new IllegalStateException("ExecutePlanResponseSender already detached!") + } + detached = true + } + + /** + * Receive responses from executionObserver and send them to grpcObserver. + * @param lastSentIndex Start sending the stream from response after this. + * @return true if the execution was detached before stream completed. + * The caller needs to finish the grpcObserver stream + * false if stream was finished. In this case, grpcObserver stream is already completed. + */ + def run(executionObserver: ExecutePlanResponseObserver, lastSentIndex: Long): Boolean = { Review Comment: Yes. the name of the class ResponseSender is supposed to mean that it pushes messages to the grpc observer. In this instance it pushes all message. With reattaching, it will get added options to finish sooner (time based, size based, number of responses based...) -- 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]
