-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-50341][SS][PYTHON] Use UDS for JVM and Python worker communication #48884
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1449,7 +1449,7 @@ def mapper(_, it): | |
| def read_udfs(pickleSer, infile, eval_type): | ||
| runner_conf = {} | ||
|
|
||
| state_server_port = None | ||
| state_server_id = None | ||
|
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. Why do we need this change? |
||
| key_schema = None | ||
| if eval_type in ( | ||
| PythonEvalType.SQL_ARROW_BATCHED_UDF, | ||
|
|
@@ -1481,7 +1481,7 @@ def read_udfs(pickleSer, infile, eval_type): | |
| eval_type == PythonEvalType.SQL_TRANSFORM_WITH_STATE_PANDAS_UDF | ||
| or eval_type == PythonEvalType.SQL_TRANSFORM_WITH_STATE_PANDAS_INIT_STATE_UDF | ||
| ): | ||
| state_server_port = read_int(infile) | ||
| state_server_id = read_int(infile) | ||
| key_schema = StructType.fromJson(json.loads(utf8_deserializer.loads(infile))) | ||
|
|
||
| # NOTE: if timezone is set here, that implies respectSessionTimeZone is True | ||
|
|
@@ -1695,7 +1695,7 @@ def mapper(a): | |
| ) | ||
| parsed_offsets = extract_key_value_indexes(arg_offsets) | ||
| ser.key_offsets = parsed_offsets[0][0] | ||
| stateful_processor_api_client = StatefulProcessorApiClient(state_server_port, key_schema) | ||
| stateful_processor_api_client = StatefulProcessorApiClient(state_server_id, key_schema) | ||
|
|
||
| # Create function like this: | ||
| # mapper a: f([a[0]], [a[0], a[1]]) | ||
|
|
@@ -1728,7 +1728,7 @@ def values_gen(): | |
| parsed_offsets = extract_key_value_indexes(arg_offsets) | ||
| ser.key_offsets = parsed_offsets[0][0] | ||
| ser.init_key_offsets = parsed_offsets[1][0] | ||
| stateful_processor_api_client = StatefulProcessorApiClient(state_server_port, key_schema) | ||
| stateful_processor_api_client = StatefulProcessorApiClient(state_server_id, key_schema) | ||
|
|
||
| def mapper(a): | ||
| key = a[0] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,6 +252,11 @@ | |
| <artifactId>htmlunit3-driver</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
|
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.
Member
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. For non-ASF ones, we will include their licenses in our licenses-binary directory and LICENSE-binary file, and also update the NOTICE-binary document for any applicable notices. |
||
| <groupId>com.github.jnr</groupId> | ||
| <artifactId>jnr-unixsocket</artifactId> | ||
| <version>0.38.18</version> | ||
| </dependency> | ||
| <!-- Explicit declaration of bouncy-castle dependencies are | ||
| needed for maven test builds on later hadoop releases.--> | ||
| <dependency> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,13 +17,14 @@ | |
|
|
||
| package org.apache.spark.sql.execution.python | ||
|
|
||
| import java.io.{BufferedInputStream, BufferedOutputStream, DataInputStream, DataOutputStream, EOFException} | ||
| import java.net.ServerSocket | ||
| import java.io.{DataInputStream, DataOutputStream, EOFException} | ||
| import java.nio.channels.Channels | ||
| import java.time.Duration | ||
|
|
||
| import scala.collection.mutable | ||
|
|
||
| import com.google.protobuf.ByteString | ||
| import jnr.unixsocket.UnixServerSocketChannel | ||
| import org.apache.arrow.vector.VectorSchemaRoot | ||
| import org.apache.arrow.vector.ipc.ArrowStreamWriter | ||
|
|
||
|
|
@@ -51,7 +52,7 @@ import org.apache.spark.util.Utils | |
| * - Requests for managing state variables (e.g. valueState). | ||
| */ | ||
| class TransformWithStateInPandasStateServer( | ||
| stateServerSocket: ServerSocket, | ||
| serverChannel: UnixServerSocketChannel, | ||
| statefulProcessorHandle: StatefulProcessorHandleImpl, | ||
| groupingKeySchema: StructType, | ||
| timeZoneId: String, | ||
|
|
@@ -134,14 +135,15 @@ class TransformWithStateInPandasStateServer( | |
| } else new mutable.HashMap[String, Iterator[Long]]() | ||
|
|
||
| def run(): Unit = { | ||
| val listeningSocket = stateServerSocket.accept() | ||
| val channel = serverChannel.accept() | ||
| inputStream = new DataInputStream( | ||
| new BufferedInputStream(listeningSocket.getInputStream)) | ||
| Channels.newInputStream(channel) | ||
| ) | ||
| outputStream = new DataOutputStream( | ||
| new BufferedOutputStream(listeningSocket.getOutputStream) | ||
| Channels.newOutputStream(channel) | ||
| ) | ||
|
|
||
| while (listeningSocket.isConnected && | ||
| while (channel.isConnected && | ||
| statefulProcessorHandle.getHandleState != StatefulProcessorHandleState.CLOSED) { | ||
| try { | ||
| val version = inputStream.readInt() | ||
|
|
@@ -758,3 +760,12 @@ case class MapStateInfo( | |
| keySerializer: ExpressionEncoder.Serializer[Row], | ||
| valueDeserializer: ExpressionEncoder.Deserializer[Row], | ||
| valueSerializer: ExpressionEncoder.Serializer[Row]) | ||
|
|
||
| object TransformWithStateInPandasStateServer { | ||
| @volatile private var id = 0 | ||
|
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. IIUC,
Contributor
Author
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. There's no much difference comparing to TCP socket. For UDS, we create socket files (we use different ports for TCP) for each server thread connection, and the files are named with different |
||
|
|
||
| def allocateServerId(): Int = synchronized { | ||
| id = id + 1 | ||
| return id | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Spark master branch is currently using
asmversion 9.7.1, and I think we should unify to version 9.7.1 because this involves support for Java versions, asm 9.2 does not support Java 19+