删除 Reliable Actors 及其状态Delete Reliable Actors and their state

对已停用的执行组件进行垃圾回收只会清除该执行组件对象,但是存储在执行组件的状态管理器中的数据不会被删除。Garbage collection of deactivated actors only cleans up the actor object, but it does not remove data that is stored in an actor's State Manager. 重新激活执行组件后,可通过状态管理器再次使用其数据。When an actor is reactivated, its data is again made available to it through the State Manager. 如果执行组件将数据存储在状态管理器,并且已停用且始终不激活该执行组件,那么可能需要清理其数据。In cases where actors store data in State Manager and are deactivated but never reactivated, it may be necessary to clean up their data.

执行组件服务提供了一个函数,用于从远程调用方删除执行组件:The Actor Service provides a function for deleting actors from a remote caller:

ActorId actorToDelete = new ActorId(id);

IActorService myActorServiceProxy = ActorServiceProxy.Create(
    new Uri("fabric:/MyApp/MyService"), actorToDelete);

await myActorServiceProxy.DeleteActorAsync(actorToDelete, cancellationToken)
ActorId actorToDelete = new ActorId(id);

ActorService myActorServiceProxy = ActorServiceProxy.create(
    new Uri("fabric:/MyApp/MyService"), actorToDelete);

myActorServiceProxy.deleteActorAsync(actorToDelete);

删除一个执行组件将出现以下结果,具体取决于当前执行组件是否处于活动状态:Deleting an actor has the following effects depending on whether or not the actor is currently active:

  • 活动执行组件Active Actor
    • 执行组件从活动的执行组件列表中删除并停用。Actor is removed from active actors list and is deactivated.
    • 该执行组件的状态会被永久删除。Its state is deleted permanently.
  • 非活动执行组件Inactive Actor
    • 该执行组件的状态会被永久删除。Its state is deleted permanently.

执行组件无法使用其任何一个执行组件方法对其自身调用删除,因为在执行组件调用时执行删除将无法删除该执行组件,在此过程中,运行时已获取该执行组件的锁,用于强制实施单线程访问。An actor cannot call delete on itself from one of its actor methods because the actor cannot be deleted while executing within an actor call context, in which the runtime has obtained a lock around the actor call to enforce single-threaded access.

有关 Reliable Actors 的详细信息,请阅读以下内容:For more information on Reliable Actors, read the following: