Skip to content

[MqttIO] Acknowledge live and earlier checkpoints on restored finalize or resume - #41503

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

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

Conversation

@jbonofre

Copy link
Copy Markdown
Member

Similar to the recent JmsIO fixes (#40605, #41013), MqttCheckpointMark previously stored pending Mqtt3Publish messages only in a transient list:

  1. Restored checkpoints lost pending messages: When a runner serializes and restores MqttCheckpointMark (or recreates the reader), readObject resets messages to an empty list, so finalizeCheckpoint() silently acknowledges nothing and messages are redelivered.
  2. Unfinalized earlier checkpoints & premature disconnect: Checkpoints that are taken without being finalized (e.g., dropped callbacks or progress snapshots) are never acknowledged by subsequent checkpoints or on createReader(..., checkpointMark) resume, and UnboundedMqttReader.close() immediately disconnects the MQTT client before in-flight checkpoints finalize.

Changes

  • Give each reader a per-JVM weak-valued PendingCheckpoints registry (readerId + monotonic sequence on MqttCheckpointMark, 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.
  • UnboundedMqttSource.createReader(options, checkpointMark) finalizes the checkpoint it resumes from when its originating reader is still live in the same JVM.
  • UnboundedMqttReader.close() waits for in-flight checkpoints to finalize (up to a 60s timeout, closing immediately once drained) before disconnecting the MQTT client, abandoning any remaining pending checkpoints on timeout.
  • Added unit tests in MqttIOTest covering restored checkpoint finalization, catching up earlier checkpoints, empty checkpoints, and resuming via createReader.

@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 MqttIO checkpoint handling to mirror the recent JmsIO improvements (#40605, #41013), ensuring that restored checkpoints and unfinalized earlier checkpoints are properly acknowledged via a per-JVM PendingCheckpoints registry, and delaying client disconnection on close() until in-flight checkpoints finalize or time out.

🔍 General Feedback

  • The design and implementation cleanly align with JmsCheckpointMark, preserving backward serialization compatibility via the pinned serialVersionUID and preventing memory leaks through weak-valued cache entries.
  • One edge case was identified in UnboundedMqttReader.start() where an empty clientId overwrites the client ID passed into Preparer on resume.

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

checkpointMark == null
? new MqttCheckpointMark.Preparer()
: new MqttCheckpointMark.Preparer(checkpointMark);
: new MqttCheckpointMark.Preparer(checkpointMark.clientId);

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: createReader initializes Preparer with checkpointMark.clientId, and ConnectionConfiguration.createClient() always generates a new random UUID client ID when connecting. However, if UnboundedMqttReader is used in a test or with a client whose config has no identifier (client.getConfig().getClientIdentifier() is empty), start() sets this.clientId = "" and overwrites checkpointPreparer.clientId with "" (line 842). Furthermore, ConnectionConfiguration.createClient() never reuses checkpointMark.clientId when reconnecting a resumed reader, which may prevent the MQTT broker from resuming the previous client's session.

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

Copy link
Copy Markdown
Contributor

Assigning reviewers:

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

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