1
votes

Is there any way to clone an actor and its state and create the exact same actor, with the same actor Id and its corresponding state in another application in Azure Service Fabric? I've looked at the backup and restore, but it doesn't seem to do what I need.
We have several instances of the same application type running actors in production. We need this functionality for 2 reasons: 1. We need to combine 2 of the applications into one, so all of the actors will need to be re-created in their current state with their current ID's in the other instance. 2 . We would like to be able to clone production into a QA environment, which is on a different Azure Server, so we can test upgrades and new code in the exact state production is in.

Any help with this is much appreciated!

2

2 Answers

0
votes

I don't think that there is built-in support for cloning. But I believe you can implement your own mechanism to do that - you can iterate over your actors to get their states and then pass it to another cluser. To iterate:

` 
        var cancellationToken = new CancellationToken();
        ContinuationToken continuationToken = null;
        var actorProxyFactory = new ActorProxyFactory();
        var actorServiceProxy = ActorServiceProxy.Create("fabric:/MyActorApp/MyActorService", partitionKey);

        do
        {
            var queryResult = await actorServiceProxy.GetActorsAsync(continuationToken, cancellationToken);
            foreach (var item in queryResult.Items)
            {
                var actor = actorProxyFactory.CreateActorProxy<IMyActor>("fabric:/MyActorApp/MyActorService", item.ActorId);
                var state = await actor.GetState();
            }

            continuationToken = queryResult.ContinuationToken;
        } while (continuationToken != null);
`

If you have a dynamic list of names for actor state, you can get all names using GetStateNamesAsync method:

IEnumerable<string> stateNames = await StateManager.GetStateNamesAsync();

Hope this will help.

0
votes

For #1, you need to use Alex's solution or similar.

For #2, you can use the existing backup & restore mechanism. The target partition of a service you are restoring doesn't need to be the source partition you created the backup of.