locations.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from typing import Any, Dict, List
  2. import ray
  3. from ray._raylet import ObjectRef
  4. def get_object_locations(
  5. obj_refs: List[ObjectRef], timeout_ms: int = -1
  6. ) -> Dict[ObjectRef, Dict[str, Any]]:
  7. """Lookup the locations for a list of objects.
  8. It returns a dict maps from an object to its location. The dict excludes
  9. those objects whose location lookup failed.
  10. Args:
  11. object_refs (List[ObjectRef]): List of object refs.
  12. timeout_ms: The maximum amount of time in micro seconds to wait
  13. before returning. Wait infinitely if it's negative.
  14. Returns:
  15. A dict maps from an object to its location. The dict excludes those
  16. objects whose location lookup failed.
  17. The location is stored as a dict with following attributes:
  18. - node_ids (List[str]): The hex IDs of the nodes that have a
  19. copy of this object. Objects less than 100KB will be in memory
  20. store not plasma store and therefore will have nodes_id = [].
  21. - object_size (int): The size of data + metadata in bytes. Can be None if the
  22. size is unknown yet (e.g. task not completed).
  23. Raises:
  24. RuntimeError: if the processes were not started by ray.init().
  25. ray.exceptions.GetTimeoutError: if it couldn't finish the
  26. request in time.
  27. """
  28. if not ray.is_initialized():
  29. raise RuntimeError("Ray hasn't been initialized.")
  30. return ray._private.worker.global_worker.core_worker.get_object_locations(
  31. obj_refs, timeout_ms
  32. )
  33. def get_local_object_locations(
  34. obj_refs: List[ObjectRef],
  35. ) -> Dict[ObjectRef, Dict[str, Any]]:
  36. """Lookup the locations for a list of objects *from the local core worker*. No RPCs
  37. are made in this method.
  38. It returns a dict maps from an object to its location. The dict excludes
  39. those objects whose location lookup failed.
  40. Args:
  41. object_refs (List[ObjectRef]): List of object refs.
  42. Returns:
  43. A dict maps from an object to its location. The dict excludes those
  44. objects whose location lookup failed.
  45. The location is stored as a dict with following attributes:
  46. - node_ids (List[str]): The hex IDs of the nodes that have a
  47. copy of this object. Objects less than 100KB will be in memory
  48. store not plasma store and therefore will have nodes_id = [].
  49. - object_size (int): The size of data + metadata in bytes. Can be None if the
  50. size is unknown yet (e.g. task not completed).
  51. Raises:
  52. RuntimeError: if the processes were not started by ray.init().
  53. """
  54. if not ray.is_initialized():
  55. raise RuntimeError("Ray hasn't been initialized.")
  56. core_worker = ray._private.worker.global_worker.core_worker
  57. return core_worker.get_local_object_locations(obj_refs)