I am running a local 5 node service fabric cluster.
In order to have finer control over long running actors, I want to delete the actors when required.
Referring to the documentation for deleting actors and enumerating actors I came up with the following code
//create actor ID, get instance and call a method on the actor
ActorId id = ActorId.CreateRandom();
IActor1 myActor = ActorProxy.Create<IActor1>(id, new Uri(URI));
Console.WriteLine(myActor.GetCountAsync().GetAwaiter().GetResult() + "ActorID:" + id.GetPartitionKey());
IActorService myActorServiceProxy = ActorServiceProxy.Create(new Uri(URI), id);
//delete actor from Actor service
myActorServiceProxy.DeleteActorAsync(id, new CancellationToken()).GetAwaiter().GetResult();
IActorService actorServiceProxy = ActorServiceProxy.Create(new Uri(URI), id.GetPartitionKey());
ContinuationToken continuationToken = null;
List<ActorInformation> activeActors = new List<ActorInformation>();
PagedResult<ActorInformation> page = actorServiceProxy
.GetActorsAsync(continuationToken, new CancellationToken()).GetAwaiter().GetResult();
activeActors.AddRange(page.Items.Where(x => x.IsActive));
continuationToken = page.ContinuationToken;
while (continuationToken != null);
foreach(ActorInformation info in activeActors)
Console.WriteLine("INFO:" + info.ActorId + ":" + info.IsActive);
//call the method again
Console.WriteLine(myActor.GetCountAsync().GetAwaiter().GetResult() + "ActorID:" + id.GetLongId());
[...] how did my second call to the actor method succeed if the actor was deleted? Was it recreated?
Yes, it was re-created.
You should read this article, it provides details of actor life cycle management. Here's a quote from that article:
When a call comes for an actor and one is not already active, a new actor is created.
This is what your program does:
Define an instance of an actor by generating a unique actor identifier.
Invoke the identified actor. It does not exist, so a new instance is activated.
Delete that instance.
Enumerate all actors. Nothing is returned.
Invoke the identified actor again. It does not exist (since it was deleted), so a new instance is activated.