From b10871a1f53d2b94624a4c056dbc2ecff9aae4df Mon Sep 17 00:00:00 2001 From: "DK.Pino" Date: Sat, 31 Oct 2020 05:48:29 +0800 Subject: [PATCH] [Core]Fix get workrer table bug (#11516) * fix get_worker_table bug * fix lint * fix comment * remove actor table * fix comment * fix get alive worker * remove unused python import --- python/ray/__init__.py | 1 + python/ray/includes/global_state_accessor.pxi | 2 +- python/ray/state.py | 9 +++++++++ python/ray/tests/test_global_state.py | 8 ++++++++ src/ray/core_worker/core_worker.cc | 1 + 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/python/ray/__init__.py b/python/ray/__init__.py index d6550d83f..c6422f3bf 100644 --- a/python/ray/__init__.py +++ b/python/ray/__init__.py @@ -110,6 +110,7 @@ __all__ = [ "get_runtime_context", "actor", "actors", + "workers", "available_resources", "cancel", "cluster_resources", diff --git a/python/ray/includes/global_state_accessor.pxi b/python/ray/includes/global_state_accessor.pxi index f279463e0..25a88028b 100644 --- a/python/ray/includes/global_state_accessor.pxi +++ b/python/ray/includes/global_state_accessor.pxi @@ -112,7 +112,7 @@ cdef class GlobalStateAccessor: def get_worker_table(self): cdef c_vector[c_string] result with nogil: - self.inner.get().GetAllWorkerInfo() + result = self.inner.get().GetAllWorkerInfo() return result def get_worker_info(self, worker_id): diff --git a/python/ray/state.py b/python/ray/state.py index 086d7567b..c7ec20183 100644 --- a/python/ray/state.py +++ b/python/ray/state.py @@ -876,6 +876,15 @@ def nodes(): return state.node_table() +def workers(): + """Get a list of the workers in the cluster. + + Returns: + Information about the Ray workers in the cluster. + """ + return state.workers() + + def current_node_id(): """Return the node id of the current node. diff --git a/python/ray/tests/test_global_state.py b/python/ray/tests/test_global_state.py index ed6d8c71a..e5c90ee68 100644 --- a/python/ray/tests/test_global_state.py +++ b/python/ray/tests/test_global_state.py @@ -110,6 +110,14 @@ def test_global_state_actor_table(ray_start_regular): assert get_state() == dead_state +def test_global_state_worker_table(ray_start_regular): + + # Get worker table from gcs. + workers_data = ray.state.workers() + + assert len(workers_data) == 1 + + def test_global_state_actor_entry(ray_start_regular): @ray.remote class Actor: diff --git a/src/ray/core_worker/core_worker.cc b/src/ray/core_worker/core_worker.cc index ab9a6cf4a..5d4fef6e7 100644 --- a/src/ray/core_worker/core_worker.cc +++ b/src/ray/core_worker/core_worker.cc @@ -691,6 +691,7 @@ void CoreWorker::RegisterToGcs() { worker_data->mutable_worker_address()->set_worker_id(worker_id.Binary()); worker_data->set_worker_type(options_.worker_type); worker_data->mutable_worker_info()->insert(worker_info.begin(), worker_info.end()); + worker_data->set_is_alive(true); RAY_CHECK_OK(gcs_client_->Workers().AsyncAdd(worker_data, nullptr)); }