Volatile Grain State (Orleans 7) #9191
Replies: 1 comment 1 reply
-
Hi @hendrik-sqrsoftware-com, welcome and thank you for your question. Both requests and response values are copied when making grain calls unless you tell the runtime that they are immutable (using the
The entire object is copied before the grain ever sees it. It's copied by the caller because the caller might modify it before the grain sees it, which would be incorrect: the grain should see the object in the state it was in when the call was made, not when it is executed. Let me know if that answers your question or if you have a follow up (eg with a code sample). |
Beta Was this translation helpful? Give feedback.
-
I am a beginner with Orleans, although I have some Actor Model experience, so please forgive the elementary level of the question:
I understand the built-in persistence mechanisms to write and read persisted state from a data store. I am more interested in how volatile state that is not persisted should be managed.
According to the principles of the Actor Model, an actor's state should generally not be modifiable from outside the actor. As far as I can tell, that is not enforced in Orleans. In other words, to maintain some volatile state inside a grain, one would simply use private (possibly readonly) properties, and there is no way to annotate them as needing to be protected from modification from outside the grain, as far as I can tell.
What is baffling to me is that it seems to me that there is some lack of consistency in this regard.
It seems that when a grain method returns a private property (readonly or not), Orleans does a deep copy of the property object before returning it, so the internal state remains protected. However, it also seems to me that if a grain method sets a private property (it cannot be readonly) to an object that originated outside the grain, then Orleans does not do a deep copy before setting the property, so the state represented by the passed in object is now vulnerable to modification from outside the grain. So, when returning private properties, Orleans protects the internal object, but when setting a private property, it does not. Is that correct?
I know that I can protect the private properties that represent volatile state by making them readonly, and therefore forcing the need for a deep copy, but I am not sure whether I am missing something and that there might be a formal way of handling volatile state that I am unaware of.
I'd be grateful to anyone who can provide clarity.
Beta Was this translation helpful? Give feedback.
All reactions