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

Persistence API: add CurrentLastSequenceNumberByPersistenceIdQuery #1773

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.pekko.persistence.query.javadsl

import java.util.Optional
import java.util.concurrent.CompletionStage

/**
* A trait that enables querying the current last known sequence number for a given `persistenceId`.
* @since 1.2.0
*/
trait CurrentLastKnownSequenceNumberByPersistenceIdQuery extends ReadJournal {

/**
* Returns the last known sequence number for the given `persistenceId`. Empty if the `persistenceId` is unknown.
Copy link
Member

Choose a reason for hiding this comment

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

Optional should use the value is absent instead of Empty?

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 think 'empty' makes since this is the terminology used by scala.Option and java Optional.

*
* @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[java.lang.Long]]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.pekko.persistence.query.scaladsl

import scala.concurrent.Future

/**
* A trait that enables querying the current last known sequence number for a given `persistenceId`.
* @since 1.2.0
*/
trait CurrentLastKnownSequenceNumberByPersistenceIdQuery extends ReadJournal {
Copy link
Member

@He-Pin He-Pin Feb 19, 2025

Choose a reason for hiding this comment

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

LastKnownSequenceNumberQuery ?

Choose a reason for hiding this comment

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

Just to highlight the intent behind the Current in name: It seemed to me that "final" queries like CurrentEventsByPersistenceIdQuery are prefixed with 'Current', while continuous corresponding queries like EventsByPersistenceIdQuery drop this prefix. The ByPersistenceId clarifies the scope of query. Even though a LastKnownSequenceNumberByPersistenceIdQuery doesn't exist yet, one could imagine a query that continuously emits the last known sequence number for persistence id in future and thus I had preferred to 1. not block the name already 2. align to existing naming schema.

Copy link
Member

@He-Pin He-Pin Feb 19, 2025

Choose a reason for hiding this comment

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

I just think the name is too long, maybe CurrentLastKnownSequenceNumberQuery, otherwise , if we need add more methods to this trait, then we need another trait.

Copy link
Member

@ptrdom ptrdom Feb 19, 2025

Choose a reason for hiding this comment

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

How about dropping the Known from the name? Current already implies it in a way. EventSourcedBehavior.lastSequenceNumber already exist, so naming would align.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would CurrentLastSequenceNumberQuery work?

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 CurrentLastSequenceNumberByPersistenceIdQuery is good if we are sticking to the style of having a trait per least amount of methods, which does make sense - for example each journal might want to implement CurrentLastSequenceNumberByPersistenceIdQuery, but not necessarily CurrentLastSequenceNumberBySliceQuery or CurrentLastSequenceNumberByTagQuery if we ever implement them.


/**
* Returns the last known sequence number for the given `persistenceId`. Empty if the `persistenceId` is unknown.
*
* @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): Future[Option[Long]]
}