Open rafalpiotrowski opened 1 year ago
cc @CumpsD @Arkatufus
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 e.Payload
and seems to pretty much ignore serializationResult
? @Aaronontheweb or @Arkatufus will know this better :)
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 hasSerializer
stuff in this PR too
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.