Handling failures of WriteStateAsync #8050
-
Let's say the persistence layer (Azure Storage) is down. My understanding is that the in-memory state of the grain (the Name) will be left modified, even though an exception will be returned to the caller. I have hard time understanding how this could be desirable behaviour as now the persisted state and in-memory state are inconsistent. None of the samples I have seen address this issue in any manner. So how should one resolve the issue? What comes to mind is making the state immutable and reverting back to original state object if
Does this make sense? I find it extremely weird that none of the documentation/samples I have seen address this issue. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
What you're suggesting makes sense. One option is to copy the state before modification using This strange event sourcing toy uses the approach of deactivating the grain if it has a storage error: https://github.com/ReubenBond/OrleansEventJournal/blob/8fc000c469bb1aba58b9c9497877362093911e6c/EventJournal/JournaledActor.cs#L347 |
Beta Was this translation helpful? Give feedback.
What you're suggesting makes sense. One option is to copy the state before modification using
DeepCopier
/DeepCopier<T>
(which you can inject) so that you can restore it after a failed update attempt. A potentially cheaper alternative is to set adirty
flag and to ensure that state is reloaded from storage if the flag is set when necessary. You can implement that usingIIncomingGrainCallFilter
or by wrapping the state type in your own type which manages the flag.This strange event sourcing toy uses the approach of deactivating the grain if it has a storage error: https://github.com/ReubenBond/OrleansEventJournal/blob/8fc000c469bb1aba58b9c9497877362093911e6c/EventJournal/JournaledActor.cs#…