Skip to content

[SolaceIO] Finalize pending checkpoints across close and on resume - #41504

Open
jbonofre wants to merge 1 commit into
apache:masterfrom
jbonofre:solaceio-checkpoint-lifecycle
Open

jbonofre wants to merge 1 commit into
apache:masterfrom
jbonofre:solaceio-checkpoint-lifecycle

Conversation

@jbonofre

Copy link
Copy Markdown
Member

SolaceIO already tracks per-reader checkpoints via ActiveReadersRegistry and catches up earlier checkpoints via pendingCheckpoints.headMap(checkpointId, true) (#38603), but two remaining lifecycle gaps (analogous to #40605 and #41013 in JmsIO) remained:

  1. Closing the reader immediately tore down ack resources: UnboundedSolaceReader.close() synchronously invalidated sessionServiceCache, unregistered readerUuid from ActiveReadersRegistry, and shut down ackExecutor. Any finalizeCheckpoint() callback arriving after reader.close() (for instance on bundle commit after reader eviction/split) failed to find the reader and left messages unacknowledged.
  2. Resuming from a checkpoint did not finalize it: UnboundedSolaceSource.createReader(options, checkpointMark) ignored checkpointMark, so recreating a reader from a committed checkpoint in the same JVM without a prior finalize callback did not acknowledge those messages.

Changes

  • Defer sessionServiceCache.invalidate, ActiveReadersRegistry.unregister, and ackExecutor.shutdown() in UnboundedSolaceReader.close() until all pending non-empty checkpoints finalize (or ackDeadline expires, closing immediately once drained).
  • Do not enqueue empty checkpoints into pendingCheckpoints, while still incrementing checkpointId so finalizing an empty checkpoint continues to acknowledge earlier pending checkpoints without blocking close().
  • Call checkpointMark.finalizeCheckpoint() in UnboundedSolaceSource.createReader() when resuming from a non-null checkpoint.
  • Added unit test SolaceIOReadTest.testRestoredCheckpointAfterCloseAndResume.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📋 Review Summary

This PR properly defers UnboundedSolaceReader resource teardown on close() when checkpoints are still pending, avoids tracking empty checkpoints in pendingCheckpoints, and ensures restored checkpoints are finalized on reader creation in UnboundedSolaceSource. However, there are a couple of lifecycle edge cases around strong references to closed readers and messages read after the last checkpoint that should be addressed.

🔍 General Feedback

  • ActiveReadersRegistry uses weak values (CacheBuilder.newBuilder().weakValues()), which works while the runner holds the reader, but once the runner drops its reference after reader.close(), GC can collect the reader before the delayed finalizeCheckpoint() or closeTimeoutFuture runs.
  • If reader.close() is called after start()/advance() without a subsequent getCheckpointMark(), the session remains open in sessionServiceCache for up to 1 minute instead of closing immediately, preventing prompt redelivery of uncommitted messages.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

closed.set(true);
boolean hasPending;
synchronized (lock) {
hasPending = !pendingCheckpoints.isEmpty();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟠 High: ActiveReadersRegistry uses .weakValues(). Once the runner calls reader.close() and drops its strong reference to the UnboundedSolaceReader (e.g., on cache eviction or split), the only remaining strong reference to this is the lambda scheduled in cleanUpThread (closeTimeoutFuture).

If close() is called multiple times, or if GC runs when closeTimeoutFuture is not holding this, or if ActiveReadersRegistry is queried under memory pressure before closeTimeoutFuture is scheduled, the weak reference in ActiveReadersRegistry can be cleared prematurely. Additionally, if receivedMessages is non-empty when close() is called (messages were read via start()/advance() but never checkpointed) and pendingCheckpoints is empty, receivedMessages should be cleared on close().

Ensure receivedMessages.clear() is called on close(), and consider keeping a strong reference in ActiveReadersRegistry (since ActiveReadersRegistry.unregister(readerUuid) is now guaranteed to be called in closeResources() either upon finalization or after ackDeadline).


synchronized (lock) {
SortedMap<Long, PendingCheckpoint> toAck = pendingCheckpoints.headMap(checkpointId, true);
for (PendingCheckpoint cp : toAck.values()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Medium: If two threads call finalizeCheckpoint concurrently (for example, UnboundedSolaceSource.createReader finalizing the checkpoint on resume at the same time as the runner's BundleFinalizer callback for the same or an earlier checkpoint), the second thread will see pendingCheckpoints.isEmpty() inside the synchronized (lock) block while the first thread is still executing msg.ackMessage() asynchronously on ackExecutor.

The second thread will immediately enter the finally block with shouldCloseAfterAck == true and call closeResources(), which calls sessionServiceCache.invalidate(readerUuid) (closing the Solace session) while the first thread's ackExecutor tasks are still in flight, causing msg.ackMessage() to fail with IllegalStateException (session closed).

To prevent closing the session while acknowledgements are still in flight, track in-flight ack operations (or only set shouldCloseAfterAck when !messagesToAck.isEmpty() / when the last in-flight finalizeCheckpoint completes).

@github-actions github-actions Bot added java io size/m M: 50-249 lines changed labels Nov 20, 2026
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.38%. Comparing base (5d834f2) to head (9ad963b).
⚠️ Report is 153 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #41504   +/-   ##
=========================================
  Coverage     59.38%   59.38%           
  Complexity     5137     5137           
=========================================
  Files          1470     1470           
  Lines        187512   187512           
  Branches       3819     3819           
=========================================
  Hits         111351   111351           
  Misses        72756    72756           
  Partials       3405     3405           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @chamikaramj for label java.
Backup reviewer: ahmedabu98 (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @chamikaramj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant