Implement internal kv in ray client (#13344)

* kv internal

* fix
This commit is contained in:
Eric Liang
2021-01-11 14:54:52 -08:00
committed by GitHub
parent fbb9795374
commit de5bc24c60
6 changed files with 131 additions and 4 deletions
+26
View File
@@ -8,6 +8,12 @@ if TYPE_CHECKING:
from ray.util.client.common import ClientObjectRef
def as_bytes(value):
if isinstance(value, str):
return value.encode("utf-8")
return value
class ClientAPI:
"""The Client-side methods corresponding to the ray API. Delegates
to the Client Worker that contains the connection to the ClientServer.
@@ -226,6 +232,26 @@ class ClientAPI:
return self.worker.get_cluster_info(
ray_client_pb2.ClusterInfoType.AVAILABLE_RESOURCES)
def _internal_kv_initialized(self) -> bool:
"""Hook for internal_kv._internal_kv_initialized."""
return self.is_initialized()
def _internal_kv_get(self, key: bytes) -> bytes:
"""Hook for internal_kv._internal_kv_get."""
return self.worker.internal_kv_get(as_bytes(key))
def _internal_kv_put(self, key: bytes, value: bytes) -> bool:
"""Hook for internal_kv._internal_kv_put."""
return self.worker.internal_kv_put(as_bytes(key), as_bytes(value))
def _internal_kv_del(self, key: bytes) -> None:
"""Hook for internal_kv._internal_kv_del."""
return self.worker.internal_kv_del(as_bytes(key))
def _internal_kv_list(self, prefix: bytes) -> bytes:
"""Hook for internal_kv._internal_kv_list."""
return self.worker.internal_kv_list(as_bytes(prefix))
def __getattr__(self, key: str):
if not key.startswith("_"):
raise NotImplementedError(