I am new to the service industry and started by reviewing MSDN related articles. I started by implementing the Hello World example here .
I changed the original implementation of RunAsync to:
var myDictionary = await this.StateManager.GetOrAddAsync<IReliableDictionary<int, DataObject>>("myDictionary"); while (!cancellationToken.IsCancellationRequested) { DataObject dataObject; using (var tx = this.StateManager.CreateTransaction()) { var result = await myDictionary.TryGetValueAsync(tx, 1); if (result.HasValue) dataObject = result.Value; else dataObject = new DataObject(); // dataObject.UpdateDate = DateTime.Now; // //ServiceEventSource.Current.ServiceMessage( // this, // "Current Counter Value: {0}", // result.HasValue ? result.Value.ToString() : "Value does not exist."); await myDictionary.AddOrUpdateAsync(tx, 1, dataObject, ((k, o) => dataObject)); await tx.CommitAsync(); } await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); }
I also introduced the DataObject type and set the UpdateDate property for this type.
[DataContract(Namespace = "http://www.contoso.com")] public class DataObject { [DataMember] public DateTime UpdateDate { get; set; } }
When I launch the application (F5 in visual studio 2015), the dataObject instance (with the key as 1) was not found in the dictionary, so I create it, install UpdateDate, add it to the dictionary and commit the transaction. During the next cycle, it finds dataObject (with the key as 1) and sets UpdateDate, updates the object in the dictionary and completes the transaction. Perfect.
Here is my question. When I stop and restart the service project (F5 in visual studio 2015), I would expect a dataObject (with a key like 1) to be found on my first RunAsync iteration, but that is not the case. I expect all states to be reset to his replica.
Do I need to do anything for the state service to clear my internal state to my main replica?
From what I read, it sounds as if all this is being processed by the service fabric and that a commit call (by transaction) is sufficient. If I find the main replica (in the Explorer of Fabric Explorer β Application View), I see that RemoteReplicator_xxx LastACKProcessedTimeUTC is updated after I complete the transaction (when going through it).
Any help is greatly appreciated.
Thanks!
-Mark