mirror of
https://github.com/wassname/ray.git
synced 2026-07-12 07:29:37 +08:00
[ID Refactor] Shorten the length of JobID to 4 bytes (#5110)
* WIP * Fix * Add jobid test * Fix * Add python part * Fix * Fix tes * Remove TODOs * Fix C++ tests * Lint * Fix * Fix exporting functions in multiple ray.init * Fix java test * Fix lint * Fix linting * Address comments. * FIx * Address and fix linting * Refine and fix * Fix * address * Address comments. * Fix linting * Fix * Address * Address comments. * Address * Address * Fix * Fix * Fix * Fix lint * Fix * Fix linting * Address comments. * Fix linting * Address comments. * Fix linting * address comments. * Fix
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from libcpp cimport bool as c_bool
|
||||
from libcpp.string cimport string as c_string
|
||||
from libc.stdint cimport uint8_t, int64_t
|
||||
from libc.stdint cimport uint8_t, uint32_t, int64_t
|
||||
|
||||
cdef extern from "ray/common/id.h" namespace "ray" nogil:
|
||||
cdef cppclass CBaseID[T]:
|
||||
@@ -78,11 +78,20 @@ cdef extern from "ray/common/id.h" namespace "ray" nogil:
|
||||
@staticmethod
|
||||
CFunctionID FromBinary(const c_string &binary)
|
||||
|
||||
cdef cppclass CJobID "ray::JobID"(CUniqueID):
|
||||
cdef cppclass CJobID "ray::JobID"(CBaseID[CJobID]):
|
||||
|
||||
@staticmethod
|
||||
CJobID FromBinary(const c_string &binary)
|
||||
|
||||
@staticmethod
|
||||
const CJobID Nil()
|
||||
|
||||
@staticmethod
|
||||
size_t Size()
|
||||
|
||||
@staticmethod
|
||||
CJobID FromInt(uint32_t value)
|
||||
|
||||
cdef cppclass CTaskID "ray::TaskID"(CBaseID[CTaskID]):
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -109,7 +109,6 @@ cdef class UniqueID(BaseID):
|
||||
def nil(cls):
|
||||
return cls(CUniqueID.Nil().Binary())
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_random(cls):
|
||||
return cls(os.urandom(CUniqueID.Size()))
|
||||
@@ -194,7 +193,7 @@ cdef class TaskID(BaseID):
|
||||
return cls(CTaskID.Nil().Binary())
|
||||
|
||||
@classmethod
|
||||
def size(cla):
|
||||
def size(cls):
|
||||
return CTaskID.Size()
|
||||
|
||||
@classmethod
|
||||
@@ -212,15 +211,43 @@ cdef class ClientID(UniqueID):
|
||||
return <CClientID>self.data
|
||||
|
||||
|
||||
cdef class JobID(UniqueID):
|
||||
cdef class JobID(BaseID):
|
||||
cdef CJobID data
|
||||
|
||||
def __init__(self, id):
|
||||
check_id(id)
|
||||
check_id(id, CJobID.Size())
|
||||
self.data = CJobID.FromBinary(<c_string>id)
|
||||
|
||||
cdef CJobID native(self):
|
||||
return <CJobID>self.data
|
||||
|
||||
@classmethod
|
||||
def from_int(cls, value):
|
||||
return cls(CJobID.FromInt(value).Binary())
|
||||
|
||||
@classmethod
|
||||
def nil(cls):
|
||||
return cls(CJobID.Nil().Binary())
|
||||
|
||||
@classmethod
|
||||
def size(cls):
|
||||
return CJobID.Size()
|
||||
|
||||
def binary(self):
|
||||
return self.data.Binary()
|
||||
|
||||
def hex(self):
|
||||
return decode(self.data.Hex())
|
||||
|
||||
def size(self):
|
||||
return CJobID.Size()
|
||||
|
||||
def is_nil(self):
|
||||
return self.data.IsNil()
|
||||
|
||||
cdef size_t hash(self):
|
||||
return self.data.Hash()
|
||||
|
||||
cdef class WorkerID(UniqueID):
|
||||
|
||||
def __init__(self, id):
|
||||
|
||||
Reference in New Issue
Block a user