-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue171 snapshot serialization #172
base: dev
Are you sure you want to change the base?
Issue171 snapshot serialization #172
Conversation
…ses manifest of SerializerWithStringManifest proposed change is to use the same logic in deciding the manifest as for journal
Pasting this here for reference what to compare to: protected override void WriteEvent(DbCommand command, IPersistentRepresentation e, IImmutableSet<string> tags)
{
var serializationResult = _serialize(e);
var serializer = serializationResult.Serializer;
var hasSerializer = serializer != null;
string manifest = "";
if (hasSerializer && serializer is SerializerWithStringManifest)
manifest = ((SerializerWithStringManifest)serializer).Manifest(e.Payload);
else if (hasSerializer && serializer.IncludeManifest)
manifest = QualifiedName(e);
else
manifest = string.IsNullOrEmpty(e.Manifest) ? QualifiedName(e) : e.Manifest;
AddParameter(command, "@PersistenceId", DbType.String, e.PersistenceId);
AddParameter(command, "@SequenceNr", DbType.Int64, e.SequenceNr);
AddParameter(command, "@Timestamp", DbType.Int64, e.Timestamp);
AddParameter(command, "@IsDeleted", DbType.Boolean, false);
AddParameter(command, "@Manifest", DbType.String, manifest);
if (hasSerializer)
{
AddParameter(command, "@SerializerId", DbType.Int32, serializer.Identifier);
}
else
{
AddParameter(command, "@SerializerId", DbType.Int32, DBNull.Value);
}
command.Parameters.Add(new NpgsqlParameter("@Payload", serializationResult.DbType) { Value = serializationResult.Payload }); What I don't know, can't debug and don't know by heart, the Journal code checks with For what it's worth, the above Journal code can be refactored to something like this: protected override void WriteEvent(
DbCommand command,
IPersistentRepresentation e,
IImmutableSet<string> tags)
{
var serializationResult = _serialize(e);
var serializer = serializationResult.Serializer;
var manifest = serializer switch
{
SerializerWithStringManifest stringManifest => stringManifest.Manifest(e.Payload),
{ IncludeManifest: true } => QualifiedName(e),
_ => !string.IsNullOrEmpty(e.Manifest) ? e.Manifest : QualifiedName(e),
};
AddParameter(command, "@PersistenceId", DbType.String, e.PersistenceId);
AddParameter(command, "@SequenceNr", DbType.Int64, e.SequenceNr);
AddParameter(command, "@Timestamp", DbType.Int64, e.Timestamp);
AddParameter(command, "@IsDeleted", DbType.Boolean, false);
AddParameter(command, "@Manifest", DbType.String, manifest);
AddParameter(command, "@SerializerId", DbType.Int32, (object?) serializer?.Identifier ?? DBNull.Value);
command.Parameters.Add(new NpgsqlParameter("@Payload", serializationResult.DbType) { Value = serializationResult.Payload }); Might be worth it to simplify the |
That is the peculiarity of PostgreSql extension. If you set the PostgreSql data type to either JSONB or JSON, the internal Akka.NET serializer is completely ignored and the plugin will attempt to serialize the paylod using NewtonSoft.Json completely. And since the the JSON serializer already embeds type information, we do not need manifest anymore. |
Yes, we know that this is a very bad design, the PostgreSql extension should not offer to save the data in JSON nor JSONB to begin with. |
It can be handy to have JSON to be honest. It's a very versatile format without any lock-in. And it makes for easy debugging ;) |
Except when a user complained that their production deployment is failing because a serializer kept throwing circular reference exception when they're using Hyperion for everything. |
Fixes #171
applied the same logic when serializing snapshot as in journal when it comes to setting manifest
Changes
Please provide a brief description of the changes here.
Checklist
For significant changes, please ensure that the following have been completed (delete if not relevant):
Latest
dev
BenchmarksInclude data from the relevant benchmark prior to this change here.
This PR's Benchmarks
Include data from after this change here.