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

Configuring persistence plugins at runtime for EventSourcedBehavior #1518

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

ptrdom
Copy link
Contributor

@ptrdom ptrdom commented Oct 6, 2024

Resolves #1513.

@@ -112,9 +112,12 @@ object PersistenceTestKitPlugin {
* Persistence testkit plugin for snapshots.
*/
@InternalApi
class PersistenceTestKitSnapshotPlugin extends SnapshotStore {
class PersistenceTestKitSnapshotPlugin(@unused cfg: Config, cfgPath: String) extends SnapshotStore {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need an unused parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is because of this bit of code:

val pluginActorArgs: List[AnyRef] =
try {
Reflect.findConstructor(pluginClass, List(pluginConfig, configPath)) // will throw if not found
List(pluginConfig, configPath)
} catch {
case NonFatal(_) =>
try {
Reflect.findConstructor(pluginClass, List(pluginConfig)) // will throw if not found
List(pluginConfig)
} catch {
case NonFatal(_) => Nil
} // otherwise use empty constructor
}

Easiest solution seemed to work around this the same as it is done in PersistenceTestKitPlugin.

Copy link
Contributor

Choose a reason for hiding this comment

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

so if the param is used, can you removed the @unused annotation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is used only through reflection, so compilation throws the following if @unused is removed:

parameter cfg in class PersistenceTestKitSnapshotPlugin is never used
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=unused-params, site=org.apache.pekko.persistence.testkit.PersistenceTestKitSnapshotPlugin.cfg                                                                         
[error] class PersistenceTestKitSnapshotPlugin(cfg: Config, cfgPath: String) extends SnapshotStore {                                                                                                                                                                     
[error]                                        ^                                                                                                                                                                                                                         
[error] one error found
[error] (persistence-testkit / Compile / compileIncremental) Compilation failed

Copy link
Contributor

Choose a reason for hiding this comment

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

fair enough - could you add a code comment explaining the @unused?

Copy link
Contributor

@pjfanning pjfanning left a comment

Choose a reason for hiding this comment

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

there are quite a lot of changes to constructors - even if they are for internal classes

I don't know but we might want to consider adding secondary constructors that match the existing param lists in the 1.1.2-RC1 release.

@@ -13,10 +13,12 @@

package org.apache.pekko.persistence.typed.internal

import com.typesafe.config.ConfigFactory
Copy link
Contributor

Choose a reason for hiding this comment

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

keep the scala namespace imports at the start

@@ -107,14 +113,18 @@ private[pekko] final class BehaviorSetup[C, E, S](

private var recoveryTimer: OptionVal[Cancellable] = OptionVal.None

val recoveryEventTimeout: FiniteDuration = persistence
Copy link
Contributor

Choose a reason for hiding this comment

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

private please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is accessed in multiple places of EventSourcedBehavior state machine - ReplayingEvents and ReplayingSnapshot are using this to make error messages, so cannot be made private. Please advise if some different solution is required.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a @since 1.1.3 annotation to any new public classes, variables or functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just double-checking - is this required for public members of classes marked with @InternalApi and private[pekko]?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure - this whole PR is looking like something we might need to stick in a future major release as opposed to an upcoming patch release. Leave the since annotations out for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood. Is there any issue with creating a PR with this code in Akka repository? Wondering about any potential license conflicts, would not want interaction with BSL repositories voiding Pekko of this code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to submit this to Akka. You own this code and submitting it Akka does not change that. The problem will only arise if you collaborate on some of the code with a Lightbend employee and then take that collaboration and try to submit that to us.

@ptrdom ptrdom requested a review from pjfanning October 7, 2024 16:54
@pjfanning
Copy link
Contributor

There are binary compat problems that will require adding an exclude file for.

[error] pekko-persistence-typed: Failed binary compatibility check against org.apache.pekko:pekko-persistence-typed_2.12:1.0.0! Found 2 potential problems
[error]  * abstract method withJournalPluginConfig(scala.Option)org.apache.pekko.persistence.typed.scaladsl.EventSourcedBehavior in interface org.apache.pekko.persistence.typed.scaladsl.EventSourcedBehavior is present only in current version
[error]    filter with: ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.pekko.persistence.typed.scaladsl.EventSourcedBehavior.withJournalPluginConfig")
[error]  * abstract method withSnapshotPluginConfig(scala.Option)org.apache.pekko.persistence.typed.scaladsl.EventSourcedBehavior in interface org.apache.pekko.persistence.typed.scaladsl.EventSourcedBehavior is present only in current version
[error]    filter with: ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.pekko.persistence.typed.scaladsl.EventSourcedBehavior.withSnapshotPluginConfig")
[error] java.lang.RuntimeException: Failed binary compatibility check against org.apache.pekko:pekko-persistence-typed_2.12:1.0.0! Found 2 potential problems

@@ -16,6 +16,8 @@ package org.apache.pekko.persistence.typed.javadsl
import java.util.Collections
import java.util.Optional

import scala.jdk.OptionConverters._
Copy link
Contributor

Choose a reason for hiding this comment

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

there is a Pekko OptionConverters - can you use that? org.pekko.util

We can't use scala.jdk.OptionConverters because we still support Scala 2.12

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.

Configuring persistence plugins at runtime for EventSourcedBehavior
2 participants