pjfanning opened a new pull request, #552:
URL: https://github.com/apache/pekko-persistence-r2dbc/pull/552

   ### Motivation
   Port of 
[akka/akka-persistence-r2dbc#441](https://github.com/akka/akka-persistence-r2dbc/pull/441)
 (`perf: Avoid event serialization roundtrip`), now that Pekko 2.0.0 provides 
`SerializedEvent`.
   
   The code is copied from the akka-persistence-r2dbc 1.2.0 release, which is 
available under the Apache License, Version 2.0 as of 2026-10-24 (its LICENSE 
change date). `PersistSerializedEventSpec` keeps the Lightbend copyright line, 
with the ASF header added by sbt.
   
   Today a persisted `SerializedEvent` is serialized as a wrapper by 
`FilteredPayloadSerializer` (manifest `S`). The row gets the wrapper's 
serializer id rather than the event's, replay returns the `SerializedEvent` 
instead of the event, and `eventsBySlices` pub-sub subscribers receive the 
wrapper, which fails with a `ClassCastException` when read as the event type.
   
   **Stacked on #543.** That PR's branch is on a fork, so this PR has to target 
`main`, and it shows #543's commits until #543 merges. Only the last commit 
belongs to this PR.
   
   ### Modification
   - Add `R2dbcJournal.serializeEvent`, which uses a `SerializedEvent`'s bytes, 
serializer id and manifest as they are and serializes anything else as before.
   - Use it in `R2dbcJournal` and `R2dbcBatchJournal`. Upstream has no batched 
journal, so that part is not in the upstream PR.
   - Deserialize `SerializedEvent`s received over pub-sub in 
`R2dbcReadJournal`. This also covers `eventsBySlicesStartingFromSnapshots`, 
which uses the same pub-sub source.
   - Port `PersistSerializedEventSpec` and the `publish SerializedEvent` test. 
Differences from upstream:
     - The row check compares the full list of rows, because the upstream 
`foreach` also passes when no rows are returned.
     - A batched journal variant of the spec.
     - A test that tags are kept for a tagged `SerializedEvent` over pub-sub.
   
   ### Result
   A `SerializedEvent` is stored with the wrapped event's serialization 
information and without being serialized again. Replay, queries and pub-sub 
subscribers all get the deserialized event. Other events are stored as before.
   
   Rows already written with manifest `S` are not converted, and reading them 
still returns a `SerializedEvent`, as upstream does. They exist only if an 
earlier version of this plugin persisted `SerializedEvent`s while running on 
Pekko 2.0.0-M5 or later. The manifest check from #510 keeps those rows from 
being marked as filtered.
   
   ### Tests
   Before the fix:
   - H2, Scala 2.13: `sbt -Dpekko.persistence.r2dbc.dialect=h2 "core/testOnly 
*PersistSerializedEventSpec *EventsBySlicePubSubSpec -- -z SerializedEvent"`: 
all 3 tests failed
   - PostgreSQL 18.6, Scala 2.13, with only the `R2dbcBatchJournal` change 
removed: `sbt "core/testOnly *PersistSerializedEventBatchJournalSpec"`: failed
   
   After the fix:
   - PostgreSQL 18.6, Scala 2.13: `sbt "core/testOnly *PersistSerializedEvent* 
*EventsBySlicePubSubSpec *R2dbcBatchJournalSpec *R2dbcJournalSpec 
*EventsBySliceBacktrackingSpec"`: 56 of 56 passed
   - H2, Scala 2.13: `sbt -Dpekko.persistence.r2dbc.dialect=h2 "core/testOnly 
*PersistSerializedEvent* *EventsBySlicePubSubSpec 
*EventsBySliceBacktrackingSpec *EventsBySliceSpec *PersistTagsSpec"`: 37 of 37 
passed, batched journal variant pending
   - H2, Scala 3.3.9: `sbt "++3.3.9" -Dpekko.persistence.r2dbc.dialect=h2 
"core/testOnly *PersistSerializedEvent* *EventsBySlicePubSubSpec"`: 12 of 12 
passed, batched journal variant pending
   - `sbt core/mimaReportBinaryIssues`: no issues against 1.0.0, Scala 2.13 only
   - `scalafmt --mode diff-ref=upstream/main`, `sbt scalafmtCheckAll 
core/headerCheckAll core/Test/headerCheck` and `git diff --check`: clean
   
   Not run locally, left to CI:
   - The full test suite and `sbt validatePullRequest`
   - YugabyteDB, MySQL and MariaDB
   - MiMa on Scala 3
   
   ### References
   Fixes #514. Refs akka/akka-persistence-r2dbc#441, apache/pekko#3650, #510, 
#543
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to