[Core] fix named actor bug (#10550)

This commit is contained in:
Edward Oakes
2020-09-03 17:48:31 -07:00
committed by GitHub
parent 94374e1dd9
commit ead30ca655
3 changed files with 33 additions and 2 deletions
+23 -1
View File
@@ -11,7 +11,8 @@ import time
import ray
import ray.test_utils
import ray.cluster_utils
from ray.test_utils import run_string_as_driver, get_non_head_nodes
from ray.test_utils import (run_string_as_driver, get_non_head_nodes,
wait_for_condition)
from ray.experimental.internal_kv import _internal_kv_get, _internal_kv_put
@@ -646,6 +647,27 @@ assert ray.get(handle.ping.remote()) == "pong"
detached_actor = ray.get_actor("actor")
ray.get(detached_actor.ping.remote())
# Check that the names are reclaimed after actors die.
def check_name_available(name):
try:
ray.get_actor(name)
return False
except ValueError:
return True
@ray.remote
class A:
pass
a = A.options(name="my_actor_1").remote()
ray.kill(a, no_restart=True)
wait_for_condition(lambda: check_name_available("my_actor_1"))
b = A.options(name="my_actor_2").remote()
del b
wait_for_condition(lambda: check_name_available("my_actor_2"))
def test_detached_actor(ray_start_regular):
@ray.remote
@@ -569,6 +569,15 @@ void GcsActorManager::DestroyActor(const ActorID &actor_id) {
RemoveActorFromOwner(actor);
}
// Remove actor from `named_actors_` if its name is not empty.
if (!actor->GetName().empty()) {
auto it = named_actors_.find(actor->GetName());
if (it != named_actors_.end()) {
RAY_CHECK(it->second == actor->GetActorID());
named_actors_.erase(it);
}
}
// The actor is already dead, most likely due to process or node failure.
if (actor->GetState() == rpc::ActorTableData::DEAD) {
return;
+1 -1
View File
@@ -92,7 +92,7 @@ class GcsActor {
ActorID GetActorID() const;
/// Returns whether or not this is a detached actor.
bool IsDetached() const;
/// Get the name of this actor (only set if it's a detached actor).
/// Get the name of this actor.
std::string GetName() const;
/// Get the task specification of this actor.
TaskSpecification GetCreationTaskSpecification() const;