diff --git a/python/ray/includes/unique_ids.pxi b/python/ray/includes/unique_ids.pxi index edb280e68..872571b42 100644 --- a/python/ray/includes/unique_ids.pxi +++ b/python/ray/includes/unique_ids.pxi @@ -288,6 +288,7 @@ cdef class JobID(BaseID): @classmethod def from_int(cls, value): + assert value < 65536, "Maximum JobID integer is 65535." return cls(CJobID.FromInt(value).Binary()) @classmethod diff --git a/python/ray/worker.py b/python/ray/worker.py index 80d4844f0..79942fb3f 100644 --- a/python/ray/worker.py +++ b/python/ray/worker.py @@ -1111,9 +1111,8 @@ def connect(node, if setproctitle: setproctitle.setproctitle("ray::IDLE") elif mode is LOCAL_MODE: - # Code path of local mode if job_id is None: - job_id = JobID.from_int(random.randint(1, 100000)) + job_id = JobID.from_int(random.randint(1, 65535)) worker.worker_id = ray.utils.compute_driver_id_from_job( job_id).binary() else: diff --git a/src/ray/common/id.cc b/src/ray/common/id.cc index da819e191..cf3b9d678 100644 --- a/src/ray/common/id.cc +++ b/src/ray/common/id.cc @@ -360,7 +360,7 @@ ObjectID ObjectID::GenerateObjectId(const std::string &task_id_binary, return ret; } -JobID JobID::FromInt(uint32_t value) { +JobID JobID::FromInt(uint16_t value) { std::vector data(JobID::Size(), 0); std::memcpy(data.data(), &value, JobID::Size()); return JobID::FromBinary( diff --git a/src/ray/common/id.h b/src/ray/common/id.h index b95b88fd5..8005e2971 100644 --- a/src/ray/common/id.h +++ b/src/ray/common/id.h @@ -99,9 +99,9 @@ class UniqueID : public BaseID { class JobID : public BaseID { public: - static constexpr int64_t kLength = 4; + static constexpr int64_t kLength = 2; - static JobID FromInt(uint32_t value); + static JobID FromInt(uint16_t value); static size_t Size() { return kLength; } @@ -161,7 +161,7 @@ class ActorID : public BaseID { class TaskID : public BaseID { private: - static constexpr size_t kUniqueBytesLength = 6; + static constexpr size_t kUniqueBytesLength = 8; public: static constexpr size_t kLength = kUniqueBytesLength + ActorID::kLength; diff --git a/src/ray/design_docs/id_specification.md b/src/ray/design_docs/id_specification.md index 3ae9d5bb3..baf1aad61 100644 --- a/src/ray/design_docs/id_specification.md +++ b/src/ray/design_docs/id_specification.md @@ -5,17 +5,17 @@ Ray ID Specification high bits low bits <-------------------------------------------------------------------------------------------- - 4B + 2B +-----------------+ - | unique bytes | JobID 4B + | unique bytes | JobID 2B +-----------------+ - 4B 4B + 4B 2B +-----------------+-----------------+ - | unique bytes | JobID | ActorID 8B + | unique bytes | JobID | ActorID 6B +-----------------+-----------------+ - 6B 8B + 8B 6B +---------------------------+-----------------------------------+ | unique bytes | ActorID | TaskID 14B +---------------------------+-----------------------------------+ @@ -26,14 +26,14 @@ Ray ID Specification +---------------------------+---------------------------------------------------------------+ ``` -#### JobID (4 bytes) -`JobID` is generated by `GCS` to ensure uniqueness. Its length is 4 bytes. +#### JobID (2 bytes) +`JobID` is generated by `GCS` to ensure uniqueness. Its length is 2 bytes. #### ActorID (8 bytes) An `ActorID` contains two parts: 1) 4 unique bytes, and 2) its `JobID`. #### TaskID (14 bytes) -A `TaskID` contains two parts: 1) 6 unique bytes, and 2) its `ActorID`. +A `TaskID` contains two parts: 1) 8 unique bytes, and 2) its `ActorID`. If the task is a normal task or a driver task, the part 2 is its dummy actor id. The following table shows the layouts of all kinds of task id.