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

feat: Typed envelope version of the eventsByPersistenceId queries #31892

Merged
merged 3 commits into from
Mar 22, 2023

Conversation

johanandren
Copy link
Member

No description provided.

* Copyright (C) 2015-2023 Lightbend Inc. <https://www.lightbend.com>
*/

package akka.persistence.query.scaladsl
Copy link
Member

Choose a reason for hiding this comment

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

We can place these in package akka.persistence.query.typed.scaladsl, where we have this EventEnvelope and the bySlices

Copy link
Member Author

Choose a reason for hiding this comment

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

Done 2e8c7c1

Also noticed I had missed adding javadsl.

}
val envelope =
new EventEnvelope[Event](
offset = Sequence(pr.sequenceNr),
Copy link
Member

Choose a reason for hiding this comment

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

can we use TimestampOffset here so that it corresponds to the offset used for bySlices?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the testkit currentEventsBySlices we use Sequence, so then I should change that as well I guess?

Copy link
Member

Choose a reason for hiding this comment

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

I see, maybe leave it as Sequence then, at least until we see that as a problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

Already went ahead and did it in 2e8c7c1

Do you think anyone may be using the slicing testkit stuff and expect a problem?

Copy link
Member

Choose a reason for hiding this comment

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

I think that is fine to change this. Shouldn't be a big deal. The seqNr is also in the envelope if that is needed for some reason.

storage,
persistence.sliceForPersistenceId))
.map(env =>
EventEnvelope(env.offset, env.persistenceId, env.sequenceNr, env.event, env.timestamp, env.eventMetadata))
Copy link
Member

Choose a reason for hiding this comment

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

If we change the EventsByPersistenceIdStage to emit TimestampOffset we should convert that back to Sequence here for compatibility.

Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

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

LGTM, after one small thing with the readTimestamp

*/
@InternalApi
private[akka] def timestampOffsetFor(pr: PersistentRepr) = {
val timestamp = Instant.ofEpochMilli(pr.timestamp) // Note: we don't really have microsecond granularity here
Copy link
Member

Choose a reason for hiding this comment

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

A good thing is that we always use an increasing and unique timestamp in the testkit, see akka.persistence.testkit.internal.CurrentTime

@InternalApi
private[akka] def timestampOffsetFor(pr: PersistentRepr) = {
val timestamp = Instant.ofEpochMilli(pr.timestamp) // Note: we don't really have microsecond granularity here
val readTimestamp = Instant.now().truncatedTo(ChronoUnit.MICROS)
Copy link
Member

Choose a reason for hiding this comment

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

Shall we use CurrentTime.now() for the readTimestamp also, or maybe better to use Instant.now() but make sure it is greater than or equal to the pr.timestamp so that it doesn't "go backwards" (read can't happen before write)

@johanandren johanandren merged commit 9438277 into main Mar 22, 2023
@johanandren johanandren deleted the wip-typed-events-by-pid-queries branch March 22, 2023 11:31
@johanandren johanandren added this to the 2.8.1 milestone Mar 22, 2023
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.

None yet

2 participants