def make_function_table_key(key_type: bytes, job_id: JobID, key: Optional[bytes]): if key is None: return b":".join([key_type, job_id.hex().encode()]) else: return b":".join([key_type, job_id.hex().encode(), key])
import base64 import logging from collections import defaultdict from enum import Enum from typing import List import ray from ray._private.internal_api import node_stats from ray._raylet import ActorID, JobID, TaskID logger = logging.getLogger(__name__) # These values are used to calculate if objectRefs are actor handles. TASKID_BYTES_SIZE = TaskID.size() ACTORID_BYTES_SIZE = ActorID.size() JOBID_BYTES_SIZE = JobID.size() # We need to multiply 2 because we need bits size instead of bytes size. TASKID_RANDOM_BITS_SIZE = (TASKID_BYTES_SIZE - ACTORID_BYTES_SIZE) * 2 ACTORID_RANDOM_BITS_SIZE = (ACTORID_BYTES_SIZE - JOBID_BYTES_SIZE) * 2 def decode_object_ref_if_needed(object_ref: str) -> bytes: """Decode objectRef bytes string. gRPC reply contains an objectRef that is encodded by Base64. This function is used to decode the objectRef. Note that there are times that objectRef is already decoded as a hex string. In this case, just convert it to a binary number. """ if object_ref.endswith("="): # If the object ref ends with =, that means it is base64 encoded.
def make_exports_prefix(job_id: JobID) -> bytes: return b"IsolatedExports:" + job_id.hex().encode()