Skip to content

Commit

Permalink
rename config
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Aug 15, 2024
1 parent fcb39d9 commit b5f928b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions persistence/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ pekko.persistence {
auto-start-snapshot-stores = []
# When migrating from using Akka Persistence to using Pekko Persistence,
# you may need to have the serializer handle Akka or Pekko created snapshots.
# Supported values are "pekko", "akka" and "ignore".
# Supported values are "pekko", "akka" and "no-migration".
# See https://cwiki.apache.org/confluence/display/PEKKO/Pekko+Akka+Compatibility
migrate-manifest-to = "pekko"
auto-migrate-manifest = "pekko"
}
# used as default-snapshot store if no plugin configured
# (see `pekko.persistence.snapshot-store`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,37 @@ import pekko.util.ByteString.UTF_8
@SerialVersionUID(1L)
final case class Snapshot(data: Any)

private[serialization] sealed trait SnapshotSerializerSnapshotMigration
private[serialization] sealed trait SnapshotAutoMigration

private[serialization] object SnapshotSerializerSnapshotMigration {
val ConfigName = "pekko.persistence.snapshot-store.migrate-manifest-to"
private[serialization] object SnapshotAutoMigration {
val ConfigName = "pekko.persistence.snapshot-store.auto-migrate-manifest"

// Ignore the snapshot migration strategy - means that Pekko will not be able to work with snapshots saved by Akka
object Ignore extends SnapshotSerializerSnapshotMigration
object NoMigration extends SnapshotAutoMigration
// When saving snapshots, migrate any manifests with `akka` to `org.apache.pekko`
object Pekko extends SnapshotSerializerSnapshotMigration
object Pekko extends SnapshotAutoMigration
// When saving snapshots, migrate any manifests with `org.apache.pekko` to `akka`
object Akka extends SnapshotSerializerSnapshotMigration
object Akka extends SnapshotAutoMigration

def fromString(s: String): SnapshotSerializerSnapshotMigration = s match {
case "ignore" => Ignore
case "pekko" => Pekko
case "akka" => Akka
case _ => throw new IllegalArgumentException(s"Unknown snapshot migration strategy: $s")
def fromString(s: String): SnapshotAutoMigration = s match {
case "no-migration" => NoMigration
case "pekko" => Pekko
case "akka" => Akka
case _ => throw new IllegalArgumentException(s"Unknown snapshot migration strategy: $s")
}
}

/**
* [[Snapshot]] serializer.
*/
class SnapshotSerializer(val system: ExtendedActorSystem) extends BaseSerializer {
import SnapshotSerializerSnapshotMigration._
import SnapshotAutoMigration._

override val includeManifest: Boolean = false

private lazy val serialization = SerializationExtension(system)

private lazy val migrationStrategy = SnapshotSerializerSnapshotMigration.fromString(
private lazy val migrationStrategy = SnapshotAutoMigration.fromString(
system.settings.config.getString(ConfigName))

/**
Expand Down Expand Up @@ -110,7 +110,7 @@ class SnapshotSerializer(val system: ExtendedActorSystem) extends BaseSerializer
// support Akka and Pekko serializers as required by configuration
private def migrateManifestIfNecessary(manifest: String): String = {
migrationStrategy match {
case Ignore => manifest
case NoMigration => manifest
case Pekko =>
if (manifest.startsWith("akka")) {
manifest.replaceFirst("akka", "org.apache.pekko")
Expand All @@ -129,7 +129,7 @@ class SnapshotSerializer(val system: ExtendedActorSystem) extends BaseSerializer
// when reading the data, we want to force use of the Pekko serializer
private def migrateManifestToPekkoIfNecessary(manifest: String): String = {
migrationStrategy match {
case Ignore => manifest
case NoMigration => manifest
case _ =>
if (manifest.startsWith("akka")) {
manifest.replaceFirst("akka", "org.apache.pekko")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import java.io.NotSerializableException
import java.util.Base64

class SnapshotSerializerMigrationAkkaSpec extends PekkoSpec(
s"${SnapshotSerializerSnapshotMigration.ConfigName}=akka"
s"${SnapshotAutoMigration.ConfigName}=akka"
) {

import SnapshotSerializerTestData._
Expand All @@ -55,7 +55,7 @@ class SnapshotSerializerMigrationAkkaSpec extends PekkoSpec(
"serialize snapshot with Akka class name" in {
val serialization = SerializationExtension(system)
val bytes = serialization.serialize(Snapshot(fsmSnapshot)).get
val cfg = ConfigFactory.parseString(s"${SnapshotSerializerSnapshotMigration.ConfigName}=ignore")
val cfg = ConfigFactory.parseString(s"${SnapshotAutoMigration.ConfigName}=no-migration")
.withFallback(system.settings.config)
val pekkoOnlySystem = ActorSystem("pekko-only-serialization", cfg)
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import pekko.testkit.PekkoSpec
import java.io.NotSerializableException
import java.util.Base64

class SnapshotSerializerMigrationIgnoreSpec extends PekkoSpec(
s"${SnapshotSerializerSnapshotMigration.ConfigName}=ignore"
class SnapshotSerializerNoMigrationSpec extends PekkoSpec(
s"${SnapshotAutoMigration.ConfigName}=no-migration"
) {

import SnapshotSerializerTestData._

"Snapshot serializer with migration ignored" should {
"Snapshot serializer with no migration" should {
"deserialize pekko snapshots" in {
val serialization = SerializationExtension(system)
val bytes = serialization.serialize(Snapshot(fsmSnapshot)).get
Expand Down

0 comments on commit b5f928b

Please sign in to comment.