I am currently working on a Service Fabric stateful service that keeps several IReliableDictionary
objects. Some of these dictionaries have ImmutableLists
as values, as recommended by this article.
For example, I have an IReliableDictionary<string,ImmutableList<string>>
. The dictionaries are populated and retrieved from perfectly fine, however when the application is upgraded, all of my immutable lists come back as empty. All other data is intact, and if I switch to IReliableDictionary<string,List<string>>
, the collection is retained just fine. For the sake of this test, I am populating the list, incrementing the service version number, and hitting "publish > upgrade" on my local cluster. I have tested both 1 and 5 node configuration to the same effect.
Is there some compatibility issue with ImmutableList
and IReliableDictionary
that I should be aware about? How do I properly store my state like this? I am happy to share any code as needed, but I am not sure what portions are relevant.
Initialisation on first run and retrieval on subsequent runs:
private readonly IReliableDictionary> itemData;
private readonly IReliableDictionary> buildHistory;
public ItemProcessor(IReliableStateManager stateManager, string itemDictionaryName, string historyDictionaryName)
{
itemData = stateManager.GetOrAddAsync<IReliableDictionary<string, ImmutableList<Item>>>(itemDictionaryName).GetAwaiter().GetResult();
buildHistory = stateManager.GetOrAddAsync<IReliableDictionary<DateTime, ImmutableList<long>>>(historyDictionaryName).GetAwaiter().GetResult();
}
It turns out that, for reasons still a mystery to me, one cannot use ImmutableList
as a value in IReliableDictionary
. Instead, one must use IEnumerable<T>
and set it .ToImmutableList()
whenever needed.