[Placement group] Check if placement group bundle index is valid (#10194)

* add part code

* rebase master

* add java testcase

* fix review comments

* fix lint error

* rebase master

* fix lint error

Co-authored-by: 灵洵 <fengbin.ffb@antfin.com>
This commit is contained in:
fangfengbin
2020-08-21 11:04:56 -07:00
committed by GitHub
co-authored by 灵洵
parent 17f801dc69
commit 36c6c4b298
5 changed files with 177 additions and 60 deletions
+12 -4
View File
@@ -8,6 +8,9 @@ import ray.ray_constants as ray_constants
import ray._raylet
import ray.signature as signature
import ray.worker
from ray.experimental.placement_group import PlacementGroup, \
check_placement_group_index
from ray import ActorClassID, Language
from ray._raylet import PythonFunctionDescriptor
from ray import cross_language
@@ -412,7 +415,7 @@ class ActorClass:
max_task_retries=None,
name=None,
detached=False,
placement_group_id=None,
placement_group=None,
placement_group_bundle_index=-1):
"""Create an actor.
@@ -438,7 +441,7 @@ class ActorClass:
guaranteed when max_concurrency > 1.
name: The globally unique name for the actor.
detached: DEPRECATED.
placement_group_id: the placement group this actor belongs to,
placement_group: the placement group this actor belongs to,
or None if it doesn't belong to any group.
placement_group_bundle_index: the index of the bundle
if the actor belongs to a placement group, which may be -1 to
@@ -504,6 +507,12 @@ class ActorClass:
else:
detached = False
if placement_group is None:
placement_group = PlacementGroup(ray.PlacementGroupID.nil(), -1)
check_placement_group_index(placement_group,
placement_group_bundle_index)
# Set the actor's default resources if not already set. First three
# conditions are to check that no resources were specified in the
# decorator. Last three conditions are to check that no resources were
@@ -574,8 +583,7 @@ class ActorClass:
detached,
name if name is not None else "",
is_asyncio,
placement_group_id
if placement_group_id is not None else ray.PlacementGroupID.nil(),
placement_group.id,
placement_group_bundle_index,
# Store actor_method_cpu in actor handle's extension data.
extension_data=str(actor_method_cpu))