Service Fabric Actor 状态像队列一样激活



我有一个Actor方法,看起来像这样:

ConditionalValue<Command> result = await this.StateManager.TryGetStateAsync<Command>(key);
await this.StateManager.TryRemoveStateAsync(key);    
return result.Value;

当我从演员方法回来或调用这个时。SaveStateAsync(),它抛出以下异常:

System.Fabric.FabricException: The given key was not present. ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80071C13 at System.Fabric.Interop.NativeRuntime.IFabricKeyValueStoreReplica6.Remove

我花了一整天的时间,然后我想通了。

在同一参与者的另一种方法中,我们将在另一个方法调用中删除的项目排队。

通过查看 StateManager,我可以看到该值的 CheckStatus 为 Add,因此我将以下调用添加到 enqueue 方法中

await this.SaveStateAsync();

然后取消排队没有任何问题。

这可能是一种边缘情况,但不要在一种方法中执行 Add,在另一种方法中执行检索和删除,而不在两者之间保存状态。

让我想起了一点 EF 上下文。

最新更新