-
Notifications
You must be signed in to change notification settings - Fork 29.2k
[SPARK-51688][PYTHON][FOLLOW-UP] Implement UDS in Accumulators #50587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,8 +39,9 @@ import org.apache.spark.api.python.PythonFunction.PythonAccumulator | |
| import org.apache.spark.broadcast.Broadcast | ||
| import org.apache.spark.input.PortableDataStream | ||
| import org.apache.spark.internal.{Logging, MDC} | ||
| import org.apache.spark.internal.LogKeys.{HOST, PORT} | ||
| import org.apache.spark.internal.LogKeys.{HOST, PORT, SOCKET_ADDRESS} | ||
| import org.apache.spark.internal.config.BUFFER_SIZE | ||
| import org.apache.spark.internal.config.Python.PYTHON_UNIX_DOMAIN_SOCKET_ENABLED | ||
| import org.apache.spark.network.util.JavaUtils | ||
| import org.apache.spark.rdd.RDD | ||
| import org.apache.spark.security.{SocketAuthHelper, SocketAuthServer, SocketFuncServer} | ||
|
|
@@ -717,35 +718,50 @@ class BytesToString extends org.apache.spark.api.java.function.Function[Array[By | |
| * collects a list of pickled strings that we pass to Python through a socket. | ||
| */ | ||
| private[spark] class PythonAccumulatorV2( | ||
| @transient private val serverHost: String, | ||
| private val serverPort: Int, | ||
| private val secretToken: String) | ||
| @transient private val serverHost: Option[String], | ||
| private val serverPort: Option[Int], | ||
| private val secretToken: Option[String], | ||
| @transient private val socketPath: Option[String]) | ||
| extends CollectionAccumulator[Array[Byte]] with Logging { | ||
|
|
||
| Utils.checkHost(serverHost) | ||
| // Unix domain socket | ||
| def this(socketPath: String) = this(None, None, None, Some(socketPath)) | ||
| // TPC socket | ||
| def this(serverHost: String, serverPort: Int, secretToken: String) = this( | ||
| Some(serverHost), Some(serverPort), Some(secretToken), None) | ||
|
|
||
| serverHost.foreach(Utils.checkHost) | ||
|
|
||
| val bufferSize = SparkEnv.get.conf.get(BUFFER_SIZE) | ||
| val isUnixDomainSock = SparkEnv.get.conf.get(PYTHON_UNIX_DOMAIN_SOCKET_ENABLED) | ||
|
|
||
| /** | ||
| * We try to reuse a single Socket to transfer accumulator updates, as they are all added | ||
| * by the DAGScheduler's single-threaded RpcEndpoint anyway. | ||
| */ | ||
| @transient private var socket: Socket = _ | ||
| @transient private var socket: SocketChannel = _ | ||
|
|
||
| private def openSocket(): Socket = synchronized { | ||
| if (socket == null || socket.isClosed) { | ||
| socket = new Socket(serverHost, serverPort) | ||
| logInfo(log"Connected to AccumulatorServer at host: ${MDC(HOST, serverHost)}" + | ||
| log" port: ${MDC(PORT, serverPort)}") | ||
| private def openSocket(): SocketChannel = synchronized { | ||
| if (socket == null || !socket.isOpen) { | ||
| if (isUnixDomainSock) { | ||
| socket = SocketChannel.open(UnixDomainSocketAddress.of(socketPath.get)) | ||
| logInfo(log"Connected to AccumulatorServer at socket: ${MDC(SOCKET_ADDRESS, serverHost)}") | ||
| } else { | ||
| socket = SocketChannel.open(new InetSocketAddress(serverHost.get, serverPort.get)) | ||
| logInfo(log"Connected to AccumulatorServer at host: ${MDC(HOST, serverHost)}" + | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. serverHost.get |
||
| log" port: ${MDC(PORT, serverPort)}") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. serverPort.get |
||
| } | ||
| // send the secret just for the initial authentication when opening a new connection | ||
| socket.getOutputStream.write(secretToken.getBytes(StandardCharsets.UTF_8)) | ||
| secretToken.foreach { token => | ||
| Channels.newOutputStream(socket).write(token.getBytes(StandardCharsets.UTF_8)) | ||
| } | ||
| } | ||
| socket | ||
| } | ||
|
|
||
| // Need to override so the types match with PythonFunction | ||
| override def copyAndReset(): PythonAccumulatorV2 = { | ||
| new PythonAccumulatorV2(serverHost, serverPort, secretToken) | ||
| new PythonAccumulatorV2(serverHost, serverPort, secretToken, socketPath) | ||
| } | ||
|
|
||
| override def merge(other: AccumulatorV2[Array[Byte], JList[Array[Byte]]]): Unit = synchronized { | ||
|
|
@@ -758,8 +774,9 @@ private[spark] class PythonAccumulatorV2( | |
| } else { | ||
| // This happens on the master, where we pass the updates to Python through a socket | ||
| val socket = openSocket() | ||
| val in = socket.getInputStream | ||
| val out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream, bufferSize)) | ||
| val in = Channels.newInputStream(socket) | ||
| val out = new DataOutputStream( | ||
| new BufferedOutputStream(Channels.newOutputStream(socket), bufferSize)) | ||
| val values = other.value | ||
| out.writeInt(values.size) | ||
| for (array <- values.asScala) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serverHost.get