Skip to content

[AmqpIO] Acknowledge live and earlier checkpoints on restored finalize or resume - #41507

Open
jbonofre wants to merge 1 commit into
apache:masterfrom
jbonofre:amqpio-checkpoint-registry
Open

jbonofre wants to merge 1 commit into
apache:masterfrom
jbonofre:amqpio-checkpoint-registry

Conversation

@jbonofre

Copy link
Copy Markdown
Member

Similar to the recent JmsIO fixes (#40605, #41013), AmqpCheckpointMark previously kept transient Messenger messenger and transient List<Tracker> trackers, and UnboundedAmqpReader reused a single mutable AmqpCheckpointMark across all getCheckpointMark() calls:

  1. Restored checkpoints lost pending trackers: After serialization/deserialization via SerializableCoder, readObject resets trackers to an empty list and leaves messenger null, so finalizeCheckpoint() on a restored mark silently acknowledges nothing.
  2. No per-checkpoint isolation, catch-up, or deferred close: Checkpoints taken without being finalized (e.g., dropped callbacks or progress snapshots) are not caught up on subsequent finalization or on createReader(..., checkpointMark) resume, and UnboundedAmqpReader.close() immediately stops messenger before in-flight checkpoints finalize.

Changes

  • Isolate per-checkpoint tracker snapshots via AmqpCheckpointMark.Preparer and register them in a per-reader weak-valued PendingCheckpoints registry (readerId + monotonic sequence on AmqpCheckpointMark, with serialVersionUID pinned for backward compatibility).
  • finalizeCheckpoint() resolves the live reader's PendingCheckpoints (even from a restored copy) and acknowledges this checkpoint together with all earlier unfinalized checkpoints of the same reader in order.
  • UnboundedAmqpSource.createReader(options, checkpointMark) finalizes the checkpoint it resumes from when its originating reader lives in this JVM.
  • UnboundedAmqpReader.close() waits for in-flight checkpoints to finalize (up to a 60s timeout, closing immediately once drained) before stopping messenger.
  • Added unit test AmqpIOTest.testRestoredCheckpointAcknowledgesLiveTrackersAndEarlierCheckpoints.

@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 updates AmqpIO to isolate per-checkpoint tracker snapshots and maintain a weak-valued registry of pending checkpoints per reader, mirroring the checkpoint finalization fixes from JmsIO (#40605, #41013). This ensures restored checkpoints and resumed readers properly acknowledge in-flight trackers and earlier unfinalized checkpoints, while deferring messenger.stop() on reader close until active checkpoints drain.

🔍 General Feedback

  • The checkpoint registry, sequence-based catch-up finalization, and backward-compatible serialVersionUID pinning are cleanly designed.
  • One synchronization issue was identified in AmqpCheckpointMark.acknowledge() / abandonPendingCheckpointsAndStopMessenger(): messenger.accept(...) can race with messenger.stop() when the close timeout expires concurrently with finalizeCheckpoint(), which is unsafe because Qpid Proton's MessengerImpl is not thread-safe.

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

acknowledge();
}

private synchronized void acknowledge() {

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: acknowledge() can run concurrently with abandonPendingCheckpointsAndStopMessenger() (when the close timeout task fires at the same time finalizeCheckpoint() is executing on another thread). Because pending.removeUpTo(sequence) removes the checkpoint from PendingCheckpoints before calling checkpoint.acknowledge(), a concurrent checkpointPreparer.abandonPendingCheckpoints() call in abandonPendingCheckpointsAndStopMessenger() will not see that checkpoint or acquire its monitor, and will immediately proceed to call messenger.stop() while acknowledge() is calling messenger.accept(tracker, 0). Qpid Proton's Messenger (MessengerImpl) is not thread-safe, so concurrent accept and stop calls can corrupt internal state or throw.

Consider guarding messenger.accept(...) and messenger.stop() with a shared lock (e.g., closeLock or synchronizing on the Messenger instance) and checking that the reader/messenger has not already been stopped before calling accept.

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

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @kennknowles for label java.
Backup reviewer: chamikaramj (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: @kennknowles

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