Get actor handle by ObjectRef

Is it possible to query an “actor handle” by ObjectRef of the data, held by in-process store?
Moreover, could we query somehow all the table of local in-process store objects and local node (not the whole cluster) shared objects store?

Hey, do you mind elaborating or providing an example of what you hope to achieve? There isn’t really a concept of “actor handle” for an object, since a task or the driver could create the object.

As for querying the local objects, you could do ray.objects() and filter based on the returned objects and their locations. You can get your current node id via ray.worker.global_worker.current_node_id.

Hi,
Doesn’t ray.objects() return the entire object table (both local and non-local objects)?

@Alex , just a friendly reminder!

Hey, yeah ray.objects returns the entire object table, thus the filtering by location.

What you want is something like filter(lambda obj:ray.worker.global_worker.current_node_id.hex() in obj["Locations"], ray.objects())

Btw, please do not use ray.worker.global_worker.current_node_id but ray.get_runtime_context().node_id.

@Alex, thanks a lot! Just a little fix required:

list(filter(lambda obj: ray.worker.global_worker.current_node_id.hex() in obj["Locations"], ray.objects().values()))

@sangcho , could you please say what issue of using ray.worker.global_worker.current_node_id?

worker.global_worker is an private attribute, and it is not supposed to be accessed directly by users.

1 Like

Got it, thanks! It makes sense to use ray.get_runtime_context().node_id then.

2 Likes