mirror of
https://github.com/wassname/ray.git
synced 2026-07-05 17:37:46 +08:00
[ID Refactor] Refactor ActorID, TaskID and ObjectID (#5286)
* Refactor ActorID, TaskID on the Java side. Left a TODO comment WIP for ObjectID ADD test Fix Add java part Fix Java test Fix Refine test. Enable test in CI * Extra a helper function. * Resolve TODOs * Fix Python CI * Fix Java lint * Update .travis.yml Co-Authored-By: Stephanie Wang <swang@cs.berkeley.edu> * Address some comments. Address some comments. Add id_specification.rst Reanme id_specification.rst to id_specification.md typo Address zhijun's comments. Fix test Address comments. Fix lint Address comments * Fix test * Address comments. * Fix build error * Update src/ray/design_docs/id_specification.md Co-Authored-By: Stephanie Wang <swang@cs.berkeley.edu> * Update src/ray/design_docs/id_specification.md Co-Authored-By: Stephanie Wang <swang@cs.berkeley.edu> * Update src/ray/design_docs/id_specification.md Co-Authored-By: Stephanie Wang <swang@cs.berkeley.edu> * Update src/ray/design_docs/id_specification.md Co-Authored-By: Stephanie Wang <swang@cs.berkeley.edu> * Update src/ray/design_docs/id_specification.md Co-Authored-By: Stephanie Wang <swang@cs.berkeley.edu> * Address comments * Update src/ray/common/id.h Co-Authored-By: Stephanie Wang <swang@cs.berkeley.edu> * Update src/ray/common/id.h Co-Authored-By: Stephanie Wang <swang@cs.berkeley.edu> * Update src/ray/common/id.h Co-Authored-By: Stephanie Wang <swang@cs.berkeley.edu> * Update src/ray/design_docs/id_specification.md Co-Authored-By: Hao Chen <chenh1024@gmail.com> * Update src/ray/design_docs/id_specification.md Co-Authored-By: Hao Chen <chenh1024@gmail.com> * Address comments. * Address comments. * Address comments. * Update C++ part to make sure task id is generated determantic * WIP * Fix core worker * Fix Java part * Fix comments. * Add Python side * Fix python * Address comments * Fix linting * Fix * Fix C++ linting * Add JobId() method to TaskID * Fix linting * Update src/ray/common/id.h Co-Authored-By: Hao Chen <chenh1024@gmail.com> * Update java/api/src/main/java/org/ray/api/id/TaskId.java Co-Authored-By: Hao Chen <chenh1024@gmail.com> * Update java/api/src/main/java/org/ray/api/id/TaskId.java Co-Authored-By: Hao Chen <chenh1024@gmail.com> * Update java/api/src/main/java/org/ray/api/id/ActorId.java Co-Authored-By: Hao Chen <chenh1024@gmail.com> * Address comments * Add DriverTaskId embeding job id * Fix tests * Add python dor_fake_driver_id * Address comments and fix linting * Fix CI
This commit is contained in:
@@ -36,7 +36,6 @@ def check_id(b, size=kUniqueIDSize):
|
||||
|
||||
cdef extern from "ray/common/constants.h" nogil:
|
||||
cdef int64_t kUniqueIDSize
|
||||
cdef int64_t kMaxTaskPuts
|
||||
|
||||
|
||||
cdef class BaseID:
|
||||
@@ -151,6 +150,9 @@ cdef class ObjectID(BaseID):
|
||||
def is_nil(self):
|
||||
return self.data.IsNil()
|
||||
|
||||
def task_id(self):
|
||||
return TaskID(self.data.TaskId().Binary())
|
||||
|
||||
cdef size_t hash(self):
|
||||
return self.data.Hash()
|
||||
|
||||
@@ -197,9 +199,35 @@ cdef class TaskID(BaseID):
|
||||
return CTaskID.Size()
|
||||
|
||||
@classmethod
|
||||
def from_random(cls):
|
||||
return cls(os.urandom(CTaskID.Size()))
|
||||
def for_fake_task(cls):
|
||||
return cls(CTaskID.ForFakeTask().Binary())
|
||||
|
||||
@classmethod
|
||||
def for_driver_task(cls, job_id):
|
||||
return cls(CTaskID.ForDriverTask(CJobID.FromBinary(job_id.binary())).Binary())
|
||||
|
||||
@classmethod
|
||||
def for_actor_creation_task(cls, actor_id):
|
||||
assert isinstance(actor_id, ActorID)
|
||||
return cls(CTaskID.ForActorCreationTask(CActorID.FromBinary(actor_id.binary())).Binary())
|
||||
|
||||
@classmethod
|
||||
def for_actor_task(cls, job_id, parent_task_id, parent_task_counter, actor_id):
|
||||
assert isinstance(job_id, JobID)
|
||||
assert isinstance(parent_task_id, TaskID)
|
||||
assert isinstance(actor_id, ActorID)
|
||||
return cls(CTaskID.ForActorTask(CJobID.FromBinary(job_id.binary()),
|
||||
CTaskID.FromBinary(parent_task_id.binary()),
|
||||
parent_task_counter,
|
||||
CActorID.FromBinary(actor_id.binary())).Binary())
|
||||
|
||||
@classmethod
|
||||
def for_normal_task(cls, job_id, parent_task_id, parent_task_counter):
|
||||
assert isinstance(job_id, JobID)
|
||||
assert isinstance(parent_task_id, TaskID)
|
||||
return cls(CTaskID.ForNormalTask(CJobID.FromBinary(job_id.binary()),
|
||||
CTaskID.FromBinary(parent_task_id.binary()),
|
||||
parent_task_counter).Binary())
|
||||
|
||||
cdef class ClientID(UniqueID):
|
||||
|
||||
@@ -257,15 +285,47 @@ cdef class WorkerID(UniqueID):
|
||||
cdef CWorkerID native(self):
|
||||
return <CWorkerID>self.data
|
||||
|
||||
cdef class ActorID(UniqueID):
|
||||
cdef class ActorID(BaseID):
|
||||
cdef CActorID data
|
||||
|
||||
def __init__(self, id):
|
||||
check_id(id)
|
||||
check_id(id, CActorID.Size())
|
||||
self.data = CActorID.FromBinary(<c_string>id)
|
||||
|
||||
cdef CActorID native(self):
|
||||
return <CActorID>self.data
|
||||
|
||||
@classmethod
|
||||
def of(cls, job_id, parent_task_id, parent_task_counter):
|
||||
assert isinstance(job_id, JobID)
|
||||
assert isinstance(parent_task_id, TaskID)
|
||||
return cls(CActorID.Of(CJobID.FromBinary(job_id.binary()),
|
||||
CTaskID.FromBinary(parent_task_id.binary()),
|
||||
parent_task_counter).Binary())
|
||||
|
||||
@classmethod
|
||||
def nil(cls):
|
||||
return cls(CActorID.Nil().Binary())
|
||||
|
||||
@classmethod
|
||||
def size(cls):
|
||||
return CActorID.Size()
|
||||
|
||||
def binary(self):
|
||||
return self.data.Binary()
|
||||
|
||||
def hex(self):
|
||||
return decode(self.data.Hex())
|
||||
|
||||
def size(self):
|
||||
return CActorID.Size()
|
||||
|
||||
def is_nil(self):
|
||||
return self.data.IsNil()
|
||||
|
||||
cdef size_t hash(self):
|
||||
return self.data.Hash()
|
||||
|
||||
|
||||
cdef class ActorHandleID(UniqueID):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user