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

Add support for Akka classic in dumping persistence schema #125

Open
PawelLipski opened this issue Nov 2, 2021 · 3 comments
Open

Add support for Akka classic in dumping persistence schema #125

PawelLipski opened this issue Nov 2, 2021 · 3 comments
Labels
event/state compatibility Relates to maintaining compatibility of akka-persistence events/state feature New feature or request nice to have Not very strictly needed for ASH to be usable

Comments

@PawelLipski
Copy link
Collaborator

No description provided.

@PawelLipski PawelLipski added the event/state compatibility Relates to maintaining compatibility of akka-persistence events/state label Nov 2, 2021
@PawelLipski PawelLipski added nice to have Not very strictly needed for ASH to be usable feature New feature or request labels Jun 17, 2022
@LukaszKontowski LukaszKontowski self-assigned this Jul 1, 2022
@LukaszKontowski
Copy link
Contributor

LukaszKontowski commented Jul 15, 2022

Current solution for akka-typed:

/**
       * All these types have three things in common:
       *   - they have 2 or more type parameters
       *   - the last type parameter corresponds to state type
       *   - the last but one type parameter corresponds to event type
       */
      private val genericsNames =
        Seq(
          "akka.persistence.typed.scaladsl.Effect",
          "akka.persistence.typed.scaladsl.EffectBuilder",
          "akka.persistence.typed.scaladsl.EventSourcedBehavior",
          "akka.persistence.typed.scaladsl.ReplyEffect")
          

Is based on code occurences of Event and State type parameters (where "Event" and "State" are not real existing types but just meaningful names) - that's how these four types were chosen. That's how we know that these particular types from akka-persistence-typed are releated to persistent events and states.

In case of akka-classic - we cannot do a similar thing - as "State" and "Event" keywords are not used as type parameters. In fact, if there are type parameters - there are two options:

  • they would not have meaningful names - jus "A" or other letter (in this case, sometimes the parameter for A is called "event: A" - so in these cases it looks obvious)
    or
  • they will be existing types, but not directly related to "Event" or "Type" - for example [Persistence] is used

So, from a quick research on the akka-persistence (classic) code base, here are my "candidates" for types that might be used:

      akka.persistence.state.scaladsl.DurableStateStore
      akka.persistence.state.scaladsl.DurableStateUpdateStore
      akka.persistence.journal.EventAdapter
      akka.persistence.journal.WriteEventAdapter
      akka.persistence.journal.ReadEventAdapter
      akka.persistence.Persistence
      akka.persistence.PersistentActor
      akka.persistence.journal.inmem.InmemJournal.Write
      akka.persistence.journal.inmem.InmemJournal.Delete

However, this is not a full list and research is not completed. @PawelLipski - what is your opinion on this? Or maybe you have some better idea?

@PawelLipski
Copy link
Collaborator Author

Huh okay, before you start further work here (as the effort/benefit ratio might not be the best for this issue)...

"candidates" for types that might be used

By used, you mean that you would detect all the types that extend any of these types and consider them to be persisted types whose schemas needs to be dumped? 🤔 Best if you could provide some small sandbox-like example here of a class and its corresponding dump in the comments

@LukaszKontowski
Copy link
Contributor

By used, you mean that you would detect all the types that extend any of these types and consider them to be persisted types whose schemas needs to be dumped?

No, current logic for typed "candidates" (genericsNames - fqcns for typed):

val foundUsedClasses: List[(Type, Position)] = body.collect {
  case x: TypeTree if genericsNames.contains(x.tpe.dealias.typeSymbol.fullName) =>
    x.tpe.typeArgs.takeRight(2).map((_, x.pos))
  }.flatten

So - from current source file we collect all usages of types from genericsNames. And these usages mean that in this place we persist some Events / States.

My idea is to find "candidates" (fqcns) for akka classic - types that can be used to persist Events / States. It would be nice to find a repo that still uses akka classic for persistence to check, which types from classic are in fact used to do this.

@LukaszKontowski LukaszKontowski removed their assignment Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
event/state compatibility Relates to maintaining compatibility of akka-persistence events/state feature New feature or request nice to have Not very strictly needed for ASH to be usable
Projects
None yet
Development

No branches or pull requests

2 participants