zozo123 commented on code in PR #59232: URL: https://github.com/apache/spark/pull/59232#discussion_r4231135658
########## udf/worker/grpc/src/test/scala/org/apache/spark/udf/worker/grpc/testing/ForwardingWorkerMain.scala: ########## @@ -0,0 +1,98 @@ +/* + * 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.udf.worker.grpc.testing + +import java.io.IOException +import java.net.{StandardProtocolFamily, UnixDomainSocketAddress} +import java.nio.ByteBuffer +import java.nio.channels.{ServerSocketChannel, SocketChannel} +import java.nio.file.{Files, Paths} +import java.util.concurrent.TimeUnit + +import scala.jdk.CollectionConverters._ +import scala.util.control.NonFatal + +/** + * Test-only launcher that stands in for a sandbox or container launcher. It + * receives the engine's `--id` and `--connection`, starts the real worker on a + * different socket, and forwards each engine connection to it. This is the + * shape a launcher has when the worker cannot bind the engine's socket itself: + * + * java -cp <classpath> ...ForwardingWorkerMain <worker command...> + * --id <id> --connection <uds-path> + * + * `SIGTERM` stops the inner worker with `SIGTERM` and waits for it. + */ +object ForwardingWorkerMain { + + def main(args: Array[String]): Unit = { + val connection = args.indexOf("--connection") + require(connection >= 0 && connection + 1 < args.length, "--connection is required") + val socketPath = args(connection + 1) + val innerPath = socketPath + ".inner" + val workerCommand = + args.take(connection) ++ args.drop(connection + 2) ++ Seq("--connection", innerPath) + + Files.deleteIfExists(Paths.get(innerPath)) + val worker = new ProcessBuilder(workerCommand.toSeq.asJava).inheritIO().start() + // This standalone test-worker main has no Spark on its classpath, so it + // cannot use Spark's ShutdownHookManager and registers directly. + // scalastyle:off runtimeaddshutdownhook + Runtime.getRuntime.addShutdownHook(new Thread(() => { Review Comment: Done in `acb3771b`, and that Build is green. `EchoGrpcWorkerMain` records its parent before `awaitTermination` and runs cleanup when that parent exits. `ForwardingWorkerMain` waits 2 seconds on SIGTERM before `destroyForcibly`. The new test records the inner pid, SIGKILLs the launcher with no SIGTERM, and checks the inner worker is gone. -- 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]
