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

fix: Do not special handle protobuf payloads for replication #1212

Merged

Conversation

johanandren
Copy link
Member

We had special logic in place for more convenient handling of protobuf payloads when using Akka Projection directly, however when using that together with replication and protobuf any payloads it causes problems, this disables all special handling of payloads when using replication and always delegates to Akka serialization.

@johanandren johanandren force-pushed the wip-no-special-handling-of-protobuf-for-replication branch from f122c68 to 0e95c38 Compare October 1, 2024 14:10
@johanandren
Copy link
Member Author

We have verified that this solves our internal problem with protobuf any:s.

There is a compatibility issue with the change though, if a user is using protobuf generated message classes to represent events in their replicated entities, we will encode them as type.googleapis.com/proto.message.Type, which the deserializer cannot handle, we cannot fall back to akka serialization infra there because we do not have serializer id and manifest in the serialised event.

I wonder if the risk for such a specific use is small enough that we can live with that potential wire incompatibility during a rolling upgrade?

@johanandren
Copy link
Member Author

Thinking some more about it: if a user used protobuf generated classes for replicated events, it wouldn't work because of the bug/shortcoming we are fixing here, it would never deserialize since the receiving side did not have the proto type to descriptor mapping.

What did work before is the pass-through Java and Scala protobuf Any class, it will now be forwarded to the deserializer configured, so the wire incompatibility could happen if the found Akka serializer infra does not handle Any. We could perhaps sort that by passing it through to the user as is (but even more unlikely that anyone is actually doing this).

ScalaPbAny(akkaSerializationTypeUrl(id, manifest), UnsafeByteOperations.unsafeWrap(bytes))
}

override def deserialize(event: ScalaPbAny): Any = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked in detail at this PR, but could we keep deserialization side as it was? If we serialize with AkkaSerializationTypeUrlPrefix that would still be deserialized correctly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if we can have no special casing that is better and less trickery to try to understand, all messages are fed to the configured akka serializer. The any-passthrough is such a weird special case that it is very unlikely that anybody else than us ourselves is doing that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@johanandren johanandren force-pushed the wip-no-special-handling-of-protobuf-for-replication branch from 0a39d24 to 30f4a74 Compare October 2, 2024 09:16
@johanandren johanandren marked this pull request as ready for review October 2, 2024 09:19
Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good

akka.actor.provider = cluster
akka.actor {
serializers {
my-replication-serializer = "akka.projection.grpc.replication.ReplicationProtoEventIntegrationSpec$$ProtobufSerializer"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be more common to use the built in proto serializer in Akka (enabled by default), or what is the reason for defining your own?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly didn't think of it, changed to that one now.

// FIXME issue #702 This probably means that one GrpcReadJournal instance is created for each Projection instance,
// and therefore one grpc client for each. Is that fine or should the client be shared for same clientSettings?

val wireSerialization = new DelegateToAkkaSerialization(system)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This apply is the same as the other apply above, aside from the serialization. Where is the other used? Do we need both? Is it even so that we can look at replicationSettings.isDefined to select serializer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified to a single internal apply factory now.

* INTERNAL API
*/
@InternalApi
private[akka] trait AkkaProjectionGrpcSerialization {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to include AkkaProjection in the name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped

Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@johanandren johanandren added this to the 1.6.0-M1 milestone Oct 3, 2024
@johanandren johanandren merged commit 929524e into main Oct 3, 2024
21 checks passed
@johanandren johanandren deleted the wip-no-special-handling-of-protobuf-for-replication branch October 3, 2024 10:59
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.

2 participants