Hi!
We have a versioning extension that we are experimenting with at the moment
(it is quite experimental at this point and completely without tests):
https://github.com/odd/akka/tree/wip-persistence-odd/akka-contrib/src/main/scala/akka/contrib/persistence/versioning
The basic idea is to attach a version to the actual data to be persisted
and then when saving the data, instead of serializing the data class as is,
save a tuple containing the data of the fields of the class. Then at load
time you can transform historic versions of the saved data to the latest
version (based on the attached version).
For example:
import akka.contrib.persistence.versioning._
// Version 1 -- present in the event log but no longer available at runtime
// case class Name(first: String, last: String) extends Versioned[Name]
// Version 2 -- current version of the class at runtime
case class Name(first: String, last: String, title: Option[String] = None)
extends Versioned[Name]
object Name extends Versioned.Companion[Name] {
override def apply(data: (Version, Any)): Name = {
case (Version.Major(1), (first: String, last: String)) => Name(first,
last)
case (Version.Major(2), (first: String, last: String, title:
Option[String])) => Name(first, last, title)
case (v, d) => throw new IllegalStateException(s"Unknown version
encountered [version: $v, data: $d]")
}
}
The versioned serializer needs to be present in the akka config:
serializers {
versioned = "akka.contrib.persistence.versioning.VersionedSerializer"
}
serialization-bindings {
"akka.contrib.persistence.versioning.Versioned" = versioned
}
On Thu, May 15, 2014 at 7:41 PM, Per Johansson <[email protected]>wrote:
> What about using "versioned" objects (like Foo_v01, Foo_v02) and convert
> to the latest version when reading a snapshot?
>
> Anyone with experience of that approach?
>
> Was thinking it might be less work if you want to have e.g. maps after
> derserialization? (maps not supported in protobuf)
>
> /Per
>
> On Thursday, 8 May 2014 09:47:46 UTC+1, Martin Krasser wrote:
>
>>
>> On 08.05.14 10:43, Tim Pigden wrote:
>>
>> Hi
>> I've found a new thing to worry about :-)
>> If I use an eventsource model and content myself with the default
>> serialization and akka persistence, what's the likelihood of my serialized
>> objects becoming unreadable in the future? What's the long-term stability
>> of the default akka serialization mechanism?
>>
>>
>> By default, events are serialized with Akka's Java serializer.
>>
>> Is there a recommendation?
>>
>>
>> Use a
>> custom<http://doc.akka.io/docs/akka/2.3.2/scala/persistence.html#custom-serialization>protobuf
>> (or similar) serializer to serialize your events. This will
>> support backwards compatible changes to your event schema.
>>
>> Tim
>> --
>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>> >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/
>> current/additional/faq.html
>> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Akka User List" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>>
>> Visit this group at http://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> Martin Krasser
>>
>> blog: http://krasserm.blogspot.com
>> code: http://github.com/krasserm
>> twitter: http://twitter.com/mrt1nz
>>
>> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ:
> http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.