mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 17:50:55 +08:00
[xlang] Cross language serialization for ActorHandle (#10335)
This commit is contained in:
@@ -297,7 +297,8 @@ cdef prepare_args(
|
||||
if language != Language.PYTHON:
|
||||
if metadata not in [
|
||||
ray_constants.OBJECT_METADATA_TYPE_CROSS_LANGUAGE,
|
||||
ray_constants.OBJECT_METADATA_TYPE_RAW]:
|
||||
ray_constants.OBJECT_METADATA_TYPE_RAW,
|
||||
ray_constants.OBJECT_METADATA_TYPE_ACTOR_HANDLE]:
|
||||
raise Exception("Can't transfer {} data to {}".format(
|
||||
metadata, language))
|
||||
size = serialized_arg.total_bytes
|
||||
|
||||
@@ -436,15 +436,14 @@ cdef class MessagePackSerializedObject(SerializedObject):
|
||||
const uint8_t *msgpack_header_ptr
|
||||
const uint8_t *msgpack_data_ptr
|
||||
|
||||
def __init__(self, metadata, msgpack_data,
|
||||
def __init__(self, metadata, msgpack_data, contained_object_refs,
|
||||
SerializedObject nest_serialized_object=None):
|
||||
if nest_serialized_object:
|
||||
contained_object_refs = (
|
||||
contained_object_refs.extend(
|
||||
nest_serialized_object.contained_object_refs
|
||||
)
|
||||
total_bytes = nest_serialized_object.total_bytes
|
||||
else:
|
||||
contained_object_refs = []
|
||||
total_bytes = 0
|
||||
super(MessagePackSerializedObject, self).__init__(
|
||||
metadata,
|
||||
|
||||
@@ -193,6 +193,13 @@ OBJECT_METADATA_TYPE_PYTHON = b"PYTHON"
|
||||
# A constant used as object metadata to indicate the object is raw bytes.
|
||||
OBJECT_METADATA_TYPE_RAW = b"RAW"
|
||||
|
||||
# A constant used as object metadata to indicate the object is an actor handle.
|
||||
# This value should be synchronized with the Java definition in
|
||||
# ObjectSerializer.java
|
||||
# TODO(fyrestone): Serialize the ActorHandle via the custom type feature
|
||||
# of XLANG.
|
||||
OBJECT_METADATA_TYPE_ACTOR_HANDLE = b"ACTOR_HANDLE"
|
||||
|
||||
AUTOSCALER_RESOURCE_REQUEST_CHANNEL = b"autoscaler_resource_request"
|
||||
|
||||
# The default password to prevent redis port scanning attack.
|
||||
|
||||
@@ -250,6 +250,9 @@ class SerializationContext:
|
||||
if data is None:
|
||||
return b""
|
||||
return data.to_pybytes()
|
||||
elif metadata == ray_constants.OBJECT_METADATA_TYPE_ACTOR_HANDLE:
|
||||
obj = self._deserialize_msgpack_data(data, metadata)
|
||||
return actor_handle_deserializer(obj)
|
||||
# Otherwise, return an exception object based on
|
||||
# the error type.
|
||||
try:
|
||||
@@ -349,10 +352,20 @@ class SerializationContext:
|
||||
def _serialize_to_msgpack(self, value):
|
||||
# Only RayTaskError is possible to be serialized here. We don't
|
||||
# need to deal with other exception types here.
|
||||
contained_object_refs = []
|
||||
|
||||
if isinstance(value, RayTaskError):
|
||||
metadata = str(
|
||||
ErrorType.Value("TASK_EXECUTION_EXCEPTION")).encode("ascii")
|
||||
value = value.to_bytes()
|
||||
elif isinstance(value, ray.actor.ActorHandle):
|
||||
# TODO(fyresone): ActorHandle should be serialized via the
|
||||
# custom type feature of cross-language.
|
||||
serialized, actor_handle_id = value._serialization_helper()
|
||||
contained_object_refs.append(actor_handle_id)
|
||||
# Update ref counting for the actor handle
|
||||
metadata = ray_constants.OBJECT_METADATA_TYPE_ACTOR_HANDLE
|
||||
value = serialized
|
||||
else:
|
||||
metadata = ray_constants.OBJECT_METADATA_TYPE_CROSS_LANGUAGE
|
||||
|
||||
@@ -373,6 +386,7 @@ class SerializationContext:
|
||||
pickle5_serialized_object = None
|
||||
|
||||
return MessagePackSerializedObject(metadata, msgpack_data,
|
||||
contained_object_refs,
|
||||
pickle5_serialized_object)
|
||||
|
||||
def serialize(self, value):
|
||||
|
||||
Reference in New Issue
Block a user