He-Pin commented on code in PR #517:
URL:
https://github.com/apache/pekko-persistence-jdbc/pull/517#discussion_r3370856315
##########
core/src/main/scala/org/apache/pekko/persistence/jdbc/journal/dao/BaseJournalDaoWithReadMessages.scala:
##########
@@ -42,62 +42,102 @@ trait BaseJournalDaoWithReadMessages extends
JournalDaoWithReadMessages {
}
/**
- * separate this method for unit tests.
+ * Separate this method for unit tests.
*/
@InternalApi
private[dao] def internalBatchStream(
persistenceId: String,
fromSequenceNr: Long,
toSequenceNr: Long,
batchSize: Int,
- refreshInterval: Option[(FiniteDuration, Scheduler)]) = {
- val firstSequenceNr: Long = Math.max(1, fromSequenceNr)
+ refreshInterval: Option[(FiniteDuration, Scheduler)]
+ ): Source[Seq[Try[(PersistentRepr, Long)]], NotUsed] = {
+
+ val normalizedBatchSize = Math.max(1, batchSize)
+ val normalizedFromSequenceNr = Math.max(1, fromSequenceNr)
+
+ def pollOrComplete(from: Long): QueryPlan = refreshInterval match {
+ case Some((delay, scheduler)) => PollRemaining(from, delay, scheduler)
+ case None => Complete
+ }
+
+ // A windowed query spans [from, min(from + batchSize, toSequenceNr)]; at
full width that is
+ // batchSize + 1 sequence numbers, which lets a window tolerate one
missing sequence number
+ // and still return a full batch.
+ def windowedQuery(from: Long): QueryWindow = {
+ val endInclusive =
+ if (from <= (Long.MaxValue - normalizedBatchSize)) Math.min(from +
normalizedBatchSize, toSequenceNr)
+ else toSequenceNr // from + batchSize overflows; fall back to the full
remaining range
+ QueryWindow(from, endInclusive)
+ }
+
+ def retrieveBatch(from: Long, endInclusive: Long):
Future[Option[(QueryPlan, Seq[Try[(PersistentRepr, Long)]])]] =
Review Comment:
**✅ nice design**: The `unfoldAsync` pattern matching on `QueryPlan`
subtypes is much cleaner than the old `FlowControl` approach. The state machine
is self-documenting — each case in the match clearly shows what query runs and
what the next state is. The sealed trait hierarchy with
`QueryWindow`/`QueryRemaining`/`PollRemaining`/`Complete` makes the transition
graph explicit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]