mirror of
https://github.com/wassname/ray.git
synced 2026-08-14 12:40:23 +08:00
Expose function table to python global control state API (#542)
* expose function table to python global control state API * fix * fix linting * add test for function table
This commit is contained in:
committed by
Robert Nishihara
parent
5572561704
commit
28f0882387
@@ -20,6 +20,7 @@ OBJECT_INFO_PREFIX = "OI:"
|
||||
OBJECT_LOCATION_PREFIX = "OL:"
|
||||
OBJECT_SUBSCRIBE_PREFIX = "OS:"
|
||||
TASK_PREFIX = "TT:"
|
||||
FUNCTION_PREFIX = "RemoteFunction:"
|
||||
OBJECT_CHANNEL_PREFIX = "OC:"
|
||||
|
||||
# This mapping from integer to task state string must be kept up-to-date with
|
||||
@@ -194,6 +195,25 @@ class GlobalState(object):
|
||||
task_id_binary)
|
||||
return results
|
||||
|
||||
def function_table(self, function_id=None):
|
||||
"""Fetch and parse the function table.
|
||||
|
||||
Returns:
|
||||
A dictionary that maps function IDs to information about the function.
|
||||
"""
|
||||
self._check_connected()
|
||||
function_table_keys = self.redis_client.keys(FUNCTION_PREFIX + "*")
|
||||
results = {}
|
||||
for key in function_table_keys:
|
||||
info = self.redis_client.hgetall(key)
|
||||
function_info_parsed = {
|
||||
"DriverID": binary_to_hex(info[b"driver_id"]),
|
||||
"Module": decode(info[b"module"]),
|
||||
"Name": decode(info[b"name"])
|
||||
}
|
||||
results[binary_to_hex(info[b"function_id"])] = function_info_parsed
|
||||
return results
|
||||
|
||||
def client_table(self):
|
||||
"""Fetch and parse the Redis DB client table.
|
||||
|
||||
|
||||
+13
-6
@@ -1600,6 +1600,9 @@ class GlobalStateAPI(unittest.TestCase):
|
||||
with self.assertRaises(Exception):
|
||||
ray.global_state.client_table()
|
||||
|
||||
with self.assertRaises(Exception):
|
||||
ray.global_state.function_table()
|
||||
|
||||
ray.init()
|
||||
|
||||
self.assertEqual(ray.global_state.object_table(), dict())
|
||||
@@ -1654,12 +1657,16 @@ class GlobalStateAPI(unittest.TestCase):
|
||||
if task_table[task_id]["State"] == "DONE":
|
||||
break
|
||||
time.sleep(0.1)
|
||||
self.assertEqual(task_table[task_id]["TaskSpec"]["ActorID"],
|
||||
ID_SIZE * "ff")
|
||||
self.assertEqual(task_table[task_id]["TaskSpec"]["Args"], [1, "hi", x_id])
|
||||
self.assertEqual(task_table[task_id]["TaskSpec"]["DriverID"], driver_id)
|
||||
self.assertEqual(task_table[task_id]["TaskSpec"]["ReturnObjectIDs"],
|
||||
[result_id])
|
||||
function_table = ray.global_state.function_table()
|
||||
task_spec = task_table[task_id]["TaskSpec"]
|
||||
self.assertEqual(task_spec["ActorID"], ID_SIZE * "ff")
|
||||
self.assertEqual(task_spec["Args"], [1, "hi", x_id])
|
||||
self.assertEqual(task_spec["DriverID"], driver_id)
|
||||
self.assertEqual(task_spec["ReturnObjectIDs"], [result_id])
|
||||
function_table_entry = function_table[task_spec["FunctionID"]]
|
||||
self.assertEqual(function_table_entry["Name"], "__main__.f")
|
||||
self.assertEqual(function_table_entry["DriverID"], driver_id)
|
||||
self.assertEqual(function_table_entry["Module"], "__main__")
|
||||
|
||||
self.assertEqual(task_table[task_id], ray.global_state.task_table(task_id))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user