Stephen Price
Stephen Price

Reputation: 1649

When does Service Fabric restart/clear state

I've been reading up on Service Fabric and something I've not yet worked out is when is the state of stateful services initialised?

If I'm developing locally, I assume the state is "restarted" each time I run the application. (ie press F5 to debug). If I deploy the services to Azure I am imagining that the services will start up and next time I deploy it is treated as an upgrade. Meaning the services maintain their state during an upgrade. I might be wrong there, as what happens to state if the service or actor has changes to the state being stored?

Or am I wrong about that and will need to persist the state in an external store of some kind to ensure that user data is not lost. ie make the services and actors maintain a hot copy of the data and persist it when needed in case the whole system is restarted or redeployed.

Upvotes: 4

Views: 2301

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35134

By default, the state is persistent to disks (in addition to replication to 3 nodes), so it should survive the restarts.

When you press F5 in Visual Studio, the default behavior is to delete your old application and deploy the current version as a new application. To maintain the state on your dev cluster, you can tick a checkbox in project properties to do upgrades instead of clean deployments.

You have the same options when deploying to Azure - deploy a new app (and lose the state) or deploy an upgrade to persist the state. The old and new versions of your state class should be compatible, they are based on DataContract to make it a bit easier.

Of course, scenarios with external state storage are also possible.

Upvotes: 5

Related Questions