mirror of
https://github.com/wassname/ray.git
synced 2026-07-12 04:40:55 +08:00
Remove ray.tasks() from API. (#7807)
This commit is contained in:
+1
-71
@@ -10,8 +10,7 @@ from ray.autoscaler.autoscaler import LoadMetrics, StandardAutoscaler
|
||||
import ray.gcs_utils
|
||||
import ray.utils
|
||||
import ray.ray_constants as ray_constants
|
||||
from ray.utils import (binary_to_hex, binary_to_object_id, binary_to_task_id,
|
||||
hex_to_binary, setup_logger)
|
||||
from ray.utils import binary_to_hex, setup_logger
|
||||
from ray.autoscaler.commands import teardown_cluster
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -99,74 +98,6 @@ class Monitor:
|
||||
"Monitor: "
|
||||
"could not find ip for client {}".format(client_id))
|
||||
|
||||
def _xray_clean_up_entries_for_job(self, job_id):
|
||||
"""Remove this job's object/task entries from redis.
|
||||
|
||||
Removes control-state entries of all tasks and task return
|
||||
objects belonging to the driver.
|
||||
|
||||
Args:
|
||||
job_id: The job id.
|
||||
"""
|
||||
|
||||
xray_task_table_prefix = (
|
||||
ray.gcs_utils.TablePrefix_RAYLET_TASK_string.encode("ascii"))
|
||||
xray_object_table_prefix = (
|
||||
ray.gcs_utils.TablePrefix_OBJECT_string.encode("ascii"))
|
||||
|
||||
task_table_objects = ray.tasks()
|
||||
job_id_hex = binary_to_hex(job_id)
|
||||
job_task_id_bins = set()
|
||||
for task_id_hex, task_info in task_table_objects.items():
|
||||
task_table_object = task_info["TaskSpec"]
|
||||
task_job_id_hex = task_table_object["JobID"]
|
||||
if job_id_hex != task_job_id_hex:
|
||||
# Ignore tasks that aren't from this driver.
|
||||
continue
|
||||
job_task_id_bins.add(hex_to_binary(task_id_hex))
|
||||
|
||||
# Get objects associated with the driver.
|
||||
object_table_objects = ray.objects()
|
||||
job_object_id_bins = set()
|
||||
for object_id, _ in object_table_objects.items():
|
||||
task_id_bin = ray._raylet.compute_task_id(object_id).binary()
|
||||
if task_id_bin in job_task_id_bins:
|
||||
job_object_id_bins.add(object_id.binary())
|
||||
|
||||
def to_shard_index(id_bin):
|
||||
if len(id_bin) == ray.TaskID.size():
|
||||
return binary_to_task_id(id_bin).redis_shard_hash() % len(
|
||||
ray.state.state.redis_clients)
|
||||
else:
|
||||
return binary_to_object_id(id_bin).redis_shard_hash() % len(
|
||||
ray.state.state.redis_clients)
|
||||
|
||||
# Form the redis keys to delete.
|
||||
sharded_keys = [[] for _ in range(len(ray.state.state.redis_clients))]
|
||||
for task_id_bin in job_task_id_bins:
|
||||
sharded_keys[to_shard_index(task_id_bin)].append(
|
||||
xray_task_table_prefix + task_id_bin)
|
||||
for object_id_bin in job_object_id_bins:
|
||||
sharded_keys[to_shard_index(object_id_bin)].append(
|
||||
xray_object_table_prefix + object_id_bin)
|
||||
|
||||
# Remove with best effort.
|
||||
for shard_index in range(len(sharded_keys)):
|
||||
keys = sharded_keys[shard_index]
|
||||
if len(keys) == 0:
|
||||
continue
|
||||
redis = ray.state.state.redis_clients[shard_index]
|
||||
num_deleted = redis.delete(*keys)
|
||||
logger.info("Monitor: "
|
||||
"Removed {} dead redis entries of the "
|
||||
"driver from redis shard {}.".format(
|
||||
num_deleted, shard_index))
|
||||
if num_deleted != len(keys):
|
||||
logger.warning("Monitor: "
|
||||
"Failed to remove {} relevant redis "
|
||||
"entries from redis shard {}.".format(
|
||||
len(keys) - num_deleted, shard_index))
|
||||
|
||||
def xray_job_notification_handler(self, unused_channel, data):
|
||||
"""Handle a notification that a job has been added or removed.
|
||||
|
||||
@@ -182,7 +113,6 @@ class Monitor:
|
||||
logger.info("Monitor: "
|
||||
"XRay Driver {} has been removed.".format(
|
||||
binary_to_hex(job_id)))
|
||||
self._xray_clean_up_entries_for_job(job_id)
|
||||
|
||||
def autoscaler_resource_request_handler(self, _, data):
|
||||
"""Handle a notification of a resource request for the autoscaler.
|
||||
|
||||
Reference in New Issue
Block a user