orleans
orleans copied to clipboard
Serializer (for PersistentState) does not use AliasAttribute on State type
(Orleans version: 7.1.1) Maybe my understanding of this topic is incorrect, but i believe this behaviour is not good: I want to give my state types an alias (as suggested in the docs) so that those types can be refactored/renamed without breaking existing persisted grain states.
Example:
public class TestGrain : Grain, ITestGrain
{
private IPersistentState<TestState> GrainState { get; }
public TestGrain([PersistentState("TestGrainState", "defaultStore")] IPersistentState<TestState> grainState)
{
GrainState = grainState;
}
public async Task Init()
{
this.GrainState.State = new TestState
{
SomeField = "something",
SomeOtherField = "something else"
};
await this.GrainState.WriteStateAsync();
}
}
[Alias("myalias")]
[GenerateSerializer]
public class TestState
{
[Id(0)]
public string SomeField { get; set; }
[Id(1)]
public string SomeOtherField { get; set; }
}
however, the full type names are serialized to storage, and (de)serialization breaks if those are renamed:
{"$id":"1","$type":"WebApplication1.TestState, WebApplication1","SomeField":"something","SomeOtherField":"something else"}
Is this a bug or is there a better way to make serialization refactoring-safe?
The default serializer for grain storage is Newtonsoft.Json, but the [Alias(...)] attribute applies to Orleans.Serialization (which is the default for RPC). I will update the Serialization doc to make this more clear.
Ok, thanks for the info. Looking at this, i saw that there is also the option to use the orleans-serializer for grain storage via the OrleansGrainStorageSerializer class, but this is not explicitly recommended in the docs. Is there a downside to use the Orleans serialization also for persistence? I was positively surprised by the size of the resuting blob. As it is version tolerant as well, it might be a very interesting alternative.
The orleans serializer produces a compact binary payload, it is not designed to be human readable, or readable by any other tools. It supports version tolerance but not to the extent of JSON serializers.
If you are willing to accept those tradeoffs then you potentially gain performance, smaller data payload (although not always) and the need for your types to only support one serializer for transmission over-the-wire and for storage.