Service Fabric:存储在 IReliableDictionary 中的 ImmutableList 在应用程序升级时返回空
Service Fabric: ImmutableList stored in IReliableDictionary returning empty when application upgrades
我目前正在开发一个 Service Fabric 有状态服务,该服务保留多个 IReliableDictionary
对象。根据 this article 的建议,其中一些词典具有 ImmutableLists
作为值。
例如,我有一个 IReliableDictionary<string,ImmutableList<string>>
。字典的填充和检索非常好,但是当应用程序升级时,我所有的不可变列表都返回为空。所有其他数据都完好无损,如果我切换到 IReliableDictionary<string,List<string>>
,该集合会保留得很好。为了这个测试,我正在填充列表,增加服务版本号,并在我的本地集群上点击 "publish > upgrade"。我测试了 1 节点和 5 节点配置,效果相同。
ImmutableList
和 IReliableDictionary
是否存在一些我应该注意的兼容性问题?我该如何正确存储我的状态?我很乐意根据需要分享任何代码,但我不确定哪些部分是相关的。
在第一个 运行 上初始化并在随后的 运行 上检索:
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();
}
事实证明,由于对我来说仍然是个谜的原因,不能使用 ImmutableList
作为 IReliableDictionary
中的值。相反,必须使用 IEnumerable<T>
并在需要时将其设置为 .ToImmutableList()
。
我目前正在开发一个 Service Fabric 有状态服务,该服务保留多个 IReliableDictionary
对象。根据 this article 的建议,其中一些词典具有 ImmutableLists
作为值。
例如,我有一个 IReliableDictionary<string,ImmutableList<string>>
。字典的填充和检索非常好,但是当应用程序升级时,我所有的不可变列表都返回为空。所有其他数据都完好无损,如果我切换到 IReliableDictionary<string,List<string>>
,该集合会保留得很好。为了这个测试,我正在填充列表,增加服务版本号,并在我的本地集群上点击 "publish > upgrade"。我测试了 1 节点和 5 节点配置,效果相同。
ImmutableList
和 IReliableDictionary
是否存在一些我应该注意的兼容性问题?我该如何正确存储我的状态?我很乐意根据需要分享任何代码,但我不确定哪些部分是相关的。
在第一个 运行 上初始化并在随后的 运行 上检索:
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();
}
事实证明,由于对我来说仍然是个谜的原因,不能使用 ImmutableList
作为 IReliableDictionary
中的值。相反,必须使用 IEnumerable<T>
并在需要时将其设置为 .ToImmutableList()
。