Skip to content
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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

rafalpiotrowski
Copy link
Contributor

@rafalpiotrowski rafalpiotrowski commented Dec 8, 2022

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 Benchmarks

Include data from the relevant benchmark prior to this change here.

This PR's Benchmarks

Include data from after this change here.

…ses manifest of SerializerWithStringManifest

proposed change is to use the same logic in deciding the manifest as for journal
@Aaronontheweb
Copy link
Member

cc @CumpsD @Arkatufus

@CumpsD
Copy link
Member

CumpsD commented Feb 2, 2023

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

@Arkatufus
Copy link
Contributor

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.

@Arkatufus
Copy link
Contributor

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.

@CumpsD
Copy link
Member

CumpsD commented Feb 3, 2023

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 ;)

@Arkatufus
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

jsonb serialization snapshot manifest instead of qualified name uses manifest of SerializerWithStringManifest
4 participants