I am attempting to create a Custom state persistence service. The following are a few issues / doubts that I have related to the task.
1. I have never come across a situation where the LoadCompletedContextActivity and SaveCompletedContextActivity methods are executed, leading to a doubt whether there is any need to override these methods in the custom state persistence service that I am creating.
2. The purpose of UnlockWorkflowInstanceState method is defined as unlocking a workflow instance state which may have been locked when multiple runtimes share instance persistence (source: http://weblogs.asp.net/gsusx/archive/2005/10/05/426699.aspx - code snippet) . Is there is any particular field in the database that stores this locking state. If not, how is this supposed to be handled
3. In the InstanceState table (persistence schema), what is the importance of activationComplete field
4. Using SQL Profiler, I have noticed that every time a runtime instance is started, the stored procedure RetrieveNonblockingInstanceStateIds is called which loads the instances whose blocked flag is '0'. What are the scenarios when the blocked flag is set to '0'
Please provide answers to the above list of questions. Thanks in advance!!!

Custom persistence service creation - issues
rauhanlinnake
Thank you sonali for this very usefull information. I am able to use both methods now. I also want to thank you for that nice multiple host application which demonstrates ownershiptimeout parameter. You been very greate help to me in all my problems related to sqlPersistence and Custompersistence. There is still bit confusion regarding the bool unlock parameter. But i think i will manage that one.
Thanks a lot
kaushal.
Mister2zx3
1. Methods you have mentioned are invoked if there are activities which spawn multiple contexts in the workflow and they contain a compensatable activity. CAG, Replicator, Parallel, While are the activities which will spawn such contexts. Placing transactionscope inside one of these activities will invoke the Save method. After the successful completion of compensatable activitiy if there is an exception thrown in the workflow, compensation will be triggered and it will invoke the Load method.
2. "unlock" flag is used to enable the scenario where multiple hosts are pointing to the same persistence store. If workflow is running in one host, no other host should be able to load the same workflow and run it. However if the workflow is idle and unloaded from memory, in that case any other host can claim and start executing the instance. unlock flag is used by the workflow runtime to manage locking and unlocking of the workflow instances. Sql persistence service uses Ownershiptimeout with the unlock flag to enable the instance locking mechanism . So usage of ownershiptimout and unlock will depend on your instance locking logic in the custom persistence service.
You can get more information about custom persistence services here
http://msdn2.microsoft.com/en-us/library/ms734700.aspx
http://msdn2.microsoft.com/en-us/library/ms734764.aspx
Check these posts for more information on persistence service
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=781699&SiteID=1
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=371851&SiteID=1
Here is post about implementing custom persistence service but it does not implement the instance locking mechanism
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=473602&SiteID=1
Hope this helps
Bjoern Graf
Hi Sai,
1) These methods are used during compensation. So if you have a transactional scope which has completed execution and later due to some error you want to do some cleanup logic in compensation, the state of the scope will be saved and retrieved using this method.
2) If you are using Beta2 bits please use OwnershipTimeoutSeconds parameter when creating a persistence service. The field in the database is "ActivationComplete".
3) The naming is confusing and has been changed for future releases. This field is the Unlocked flag denoting if the instance is in use by any host.The field has been renamed to "Unlocked".
4) The Blocked field is a flag denoting wether the instance is waiting for some external event to continue execution say for a timeout event. So, when the host starts the instances with blocked=0 are loaded essentially means the host is trying to resume execution of instance which is not waiting for any external event.
You will see the blocked=0 if you kill the host exe immediately after a persist point like after the completion of a transactional activity.
Thanks,
Srikanth.
JaredJ
Hi srikanth,
As you mentioned i added one compensatable transaction scope activity in my project to see if LoadCompletedContextActivity and SaveCompletedContextActivity gets invoked or not. But during exectuion it is not being invoked by framework at any point. The only methods which gets invoked by the framework are SaveWorkflowInstanceState and LoadWorkflowInstanceState. Also i am trying to figure out how to use SaveWorkflowInstanceState(Activity rootActivity, bool unlock) bool unlock parameter. how it gets set how we can utilize it most importantly how to enable OwnershipTimeoutSeconds parameter in custom persistence service i am not able to find any answers on the net. Since there is no detailed information available in winsdk it self. I was just wondering if you can help me with this issue i would be very glad.
Thanks,
kpthekiller