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 querying last known sequence number by persistenceId. #267

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

Conversation

janjaali
Copy link
Contributor

@janjaali janjaali commented Feb 9, 2025

Resolves apache/pekko#1761 for this plugin.

@janjaali
Copy link
Contributor Author

janjaali commented Feb 9, 2025

@pjfanning I tried to align column widths to 120 and dropped curly braces for single statement methods. I hope that fits better now.

@@ -0,0 +1,27 @@
/*
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 change the license header on new files that are not copies of other files to be https://github.com/apache/pekko/blob/main/project/AddMetaInfLicenseFiles.scala#L1-L16 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! Updated in b033218.

import org.scalatest.concurrent.ScalaFutures

abstract class CurrentLastKnownSequenceNumberByPersistenceIdTest(
config: String
Copy link
Contributor

Choose a reason for hiding this comment

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

this style is still wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hope f0cc6c5 does the job?

@@ -32,7 +38,8 @@ class JdbcReadJournal(journal: ScalaJdbcReadJournal)
with CurrentEventsByPersistenceIdQuery
with EventsByPersistenceIdQuery
with CurrentEventsByTagQuery
with EventsByTagQuery {
with EventsByTagQuery
with CurrentLastKnownSequenceNumberByPersistenceIdQuery {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need the CurrentLastKnownSequenceNumberByPersistenceIdQuery trait? Can't we just add the function without having a marker trait.
We can add the trait to the pekko-persistence jar at some stage and then do another PR to uptake the trait here.

Copy link
Member

Choose a reason for hiding this comment

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

Assuming a marker trait would allow writing this:

PersistenceQuery(system).readJournalFor[CurrentLastKnownSequenceNumberByPersistenceIdQuery](JdbcReadJournal.Identifier)

Instead of having to write this:

PersistenceQuery(system).readJournalFor[JdbcReadJournal](JdbcReadJournal.Identifier)

But if the goal is to eventually have the marker trait in the core repository then this serves very little and temporary purpose, so overall I agree with suggestion to remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Main intent was to stick to existing marker traits application + having that part of contract testable on its own. In our applications we rarely declare dependencies to the full query journal, usually we tend to have the capabilities speaking:

object FancyAggregator {
  def apply(readJournal: EventsByTagQuery)
}

vs

object FancyAggregator {
  def apply(readJournal: JdbcReadJournal)
}

If you feel more comfortable, surely, I can try to inline it without marker trait. Would make dependency injection a bit harder.

Copy link
Contributor

Choose a reason for hiding this comment

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

My aim would be merge this without the marker trait meaning that we could release a version pekko-persistence-jdbc 1.1.x that supports this but without needing a new Pekko core release. pekko-persistence 1.2.0-M2 and above could have the marker trait and a pekko-persistence-jdbc 1.2.0(-M1) release could rely on pekko-persistence 1.2.0-M2 and uptake the marker trait.

I haven't studied pekko-persistence-r2dbc but I presume that it too could implement this support and in a similar timeline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I will drop the marker trait today or tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed marker trait with ce15d5e.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ptrdom it looks like pekko-persistence-r2dbc can have a similar PR added at some stage? Can you confirm this? I can look into adding the marker trait to the pekko core but it could be a while before it makes it into a full release meaning that we will have to wait to add the uptake of the marker trait.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think it should be no problem to add this functionality to pekko-persistence-r2dbc.

@pjfanning pjfanning requested a review from ptrdom February 9, 2025 12:54
pjfanning
pjfanning previously approved these changes Feb 14, 2025
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.

Lgtm

@pjfanning pjfanning added this to the 1.1.1 milestone Feb 14, 2025
* @param persistenceId The `persistenceId` for which the last known sequence number should be returned.
* @return Some sequence number or None if the `persistenceId` is unknown.
*/
def currentLastKnownSequenceNumberByPersistenceId(persistenceId: String): CompletionStage[Optional[Long]] =
Copy link
Contributor

@pjfanning pjfanning Feb 14, 2025

Choose a reason for hiding this comment

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

I wonder if this should be java.lang.Long instead of scala.Long? scala.Long acts as an alias for the Java long primitive which is not the same as java.lang.Long. java.lang.Long is nullable but I still prefer the Optional wrapper.

wdyt @janjaali @ptrdom @raboof @He-Pin ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was considering scala.Long as the better suited one here, since the EventEnvelope itself - which is the return type of multiple other methods in this class - carries the offset and specially the sequenceNr - the attribute that this method is actually interested in - as scala.Long.

The Optional wrapper was "inspired" by the GetObjectResult for the DurableStateStore javadsl.

Copy link
Member

Choose a reason for hiding this comment

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

Quick search in Pekko repository gives mixed results, some javadsl classes stick to java.lang.Long quite well, others do not. My guess is that javadsl should use java.lang.Long, it is just difficult to enforce, because there is no automatic linting for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that Pekko is inconsistent but I would prefer that we use java.lang.Long here.

@pjfanning pjfanning dismissed their stale review February 15, 2025 17:22

Small issue

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.

Pekko-Persistence: CurrentLastKnownSequenceNumberByPersistenceId
3 participants