You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "jbonofre (via GitHub)" <gi...@apache.org> on 2026/10/15 07:22:23 UTC
[PR] [JmsIO] Let restored checkpoint marks acknowledge live messages [beam]
jbonofre opened a new pull request, #40605:
URL: https://github.com/apache/beam/pull/40605
`JmsCheckpointMark` keeps its messages, consumer and session in `transient` fields. A mark that is serialized and restored, or finalized after the reader was recreated, therefore acknowledges nothing and the messages are redelivered.
This gives each mark an id and keeps live marks in a per-JVM registry, so a restored copy finalizes the live checkpoint with the same id. The entry is removed on finalize, and entries not finalized within an hour are dropped (the broker redelivers them).
Motivated by a Dataflow streaming job (CLIENT_ACKNOWLEDGE, `withRequiresDeduping()`) where dequeues stayed near zero while readers were recreated every few seconds. This is a hypothesis for that behavior, not yet confirmed. It does not help if finalize is delivered to a different JVM, or if the old connection is already closed.
Adds a test that serializes and restores a mark and checks the original message is acked.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [JmsIO] Let restored checkpoint marks acknowledge live messages [beam]
Posted by "chamikaramj (via GitHub)" <gi...@apache.org>.
chamikaramj commented on code in PR #40605:
URL: https://github.com/apache/beam/pull/40605#discussion_r4355037331
##########
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsCheckpointMark.java:
##########
@@ -66,6 +82,15 @@ private JmsCheckpointMark(
/** Acknowledge all outstanding message. */
@Override
public void finalizeCheckpoint() {
+ if (messages == null && consumer == null && session == null) {
+ // Possibly a restored copy of a checkpoint whose state lives in another instance.
Review Comment:
This uses `AvroCoder` for encoding right ? `id` field could be null during certain scenarios (for example, restoring from an older version during Dataflow streaming update). You should guard against that here.
##########
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsCheckpointMark.java:
##########
@@ -44,6 +46,20 @@ class JmsCheckpointMark implements UnboundedSource.CheckpointMark, Serializable
private static final Logger LOG = LoggerFactory.getLogger(JmsCheckpointMark.class);
+ /**
+ * Live checkpoints of this JVM that still hold unacknowledged messages, by id. The messages,
+ * consumer and session of a checkpoint are transient, so a runner that serializes and restores
+ * the mark (or recreates the reader) would otherwise lose them and never acknowledge. A restored
+ * mark uses this registry to find the live checkpoint with the same id and finalize that one.
+ */
+ private static final ConcurrentHashMap<String, JmsCheckpointMark> LIVE_CHECKPOINTS =
Review Comment:
Going through all items here during checkpoint creation can be expensive.
Consider replacing with a Guava Cache to put/get/invalidate checkpoints efficiently.
##########
sdks/java/io/jms/src/test/java/org/apache/beam/sdk/io/jms/JmsLocalTest.java:
##########
@@ -170,6 +170,37 @@ public void testJmsCheckpointMarkClientAcknowledgeUnsafeNoSessionRecreation() th
assertEquals(0, activeCheckpoints.get());
}
+ @Test
+ public void testRestoredCheckpointMarkAcknowledgesLiveMessages() throws Exception {
+ Message msg = Mockito.mock(Message.class);
+ JmsCheckpointMark.Preparer preparer =
+ JmsCheckpointMark.newPreparer(JmsIO.AcknowledgeMode.INDIVIDUAL_ACKNOWLEDGE);
+ preparer.add(msg);
+ AtomicInteger activeCheckpoints = new AtomicInteger(0);
+ JmsCheckpointMark mark =
+ preparer.newCheckpoint(
+ null, null, JmsIO.AcknowledgeMode.INDIVIDUAL_ACKNOWLEDGE, activeCheckpoints);
+ int live = JmsCheckpointMark.liveCheckpointCount();
+
+ // serialize/deserialize drops the transient state, as when a runner restores the mark
Review Comment:
Let's serialize/deserialize using the actual `AvroCoder` instead of using Java serialization for this test.
##########
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsCheckpointMark.java:
##########
@@ -66,6 +82,15 @@ private JmsCheckpointMark(
/** Acknowledge all outstanding message. */
@Override
public void finalizeCheckpoint() {
+ if (messages == null && consumer == null && session == null) {
+ // Possibly a restored copy of a checkpoint whose state lives in another instance.
+ JmsCheckpointMark live = LIVE_CHECKPOINTS.get(id);
+ if (live != null) {
+ live.finalizeCheckpoint();
+ return;
+ }
+ }
+ LIVE_CHECKPOINTS.remove(id);
try {
Review Comment:
May be return immediately here if `messages` is null ?
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [JmsIO] Let restored checkpoint marks acknowledge live messages [beam]
Posted by "chamikaramj (via GitHub)" <gi...@apache.org>.
chamikaramj commented on PR #40605:
URL: https://github.com/apache/beam/pull/40605#issuecomment-6401363768
waiting on author
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [JmsIO] Let restored checkpoint marks acknowledge live messages [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #40605:
URL: https://github.com/apache/beam/pull/40605#issuecomment-6187746696
Assigning reviewers:
R: @chamikaramj for label java.
Backup reviewer: kennknowles (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).
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [JmsIO] Let restored checkpoint marks acknowledge live messages [beam]
Posted by "chamikaramj (via GitHub)" <gi...@apache.org>.
chamikaramj commented on code in PR #40605:
URL: https://github.com/apache/beam/pull/40605#discussion_r4416150409
##########
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsCheckpointMark.java:
##########
@@ -44,6 +48,18 @@ class JmsCheckpointMark implements UnboundedSource.CheckpointMark, Serializable
private static final Logger LOG = LoggerFactory.getLogger(JmsCheckpointMark.class);
+ /**
+ * Live checkpoints of this JVM that still hold unacknowledged messages, by id. The messages,
+ * consumer and session of a checkpoint are transient, so a runner that serializes and restores
+ * the mark (or recreates the reader) would otherwise lose them and never acknowledge. A restored
+ * mark uses this registry to find the live checkpoint with the same id and finalize that one.
+ * Checkpoints not finalized within an hour are dropped; the broker redelivers their messages.
+ */
+ private static final Cache<String, JmsCheckpointMark> LIVE_CHECKPOINTS =
+ CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build();
Review Comment:
Probably also good to add a `maximumSize` if this could potentially lead to OOMs by holding a large number of objects up to 1 hour.
##########
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsCheckpointMark.java:
##########
@@ -44,6 +48,18 @@ class JmsCheckpointMark implements UnboundedSource.CheckpointMark, Serializable
private static final Logger LOG = LoggerFactory.getLogger(JmsCheckpointMark.class);
+ /**
+ * Live checkpoints of this JVM that still hold unacknowledged messages, by id. The messages,
+ * consumer and session of a checkpoint are transient, so a runner that serializes and restores
+ * the mark (or recreates the reader) would otherwise lose them and never acknowledge. A restored
+ * mark uses this registry to find the live checkpoint with the same id and finalize that one.
+ * Checkpoints not finalized within an hour are dropped; the broker redelivers their messages.
+ */
+ private static final Cache<String, JmsCheckpointMark> LIVE_CHECKPOINTS =
+ CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build();
+
+ // May be null when restored from a checkpoint written by a version without this field.
+ private final @Nullable String id = UUID.randomUUID().toString();
Review Comment:
We should override `equals` and `hashCode` since we randomly generate the ID here and two `CheckPointMark`s that are otherwise equal will end up being not equal (if a runner ever checks that).
##########
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsCheckpointMark.java:
##########
@@ -44,6 +48,18 @@ class JmsCheckpointMark implements UnboundedSource.CheckpointMark, Serializable
private static final Logger LOG = LoggerFactory.getLogger(JmsCheckpointMark.class);
+ /**
+ * Live checkpoints of this JVM that still hold unacknowledged messages, by id. The messages,
+ * consumer and session of a checkpoint are transient, so a runner that serializes and restores
+ * the mark (or recreates the reader) would otherwise lose them and never acknowledge. A restored
+ * mark uses this registry to find the live checkpoint with the same id and finalize that one.
+ * Checkpoints not finalized within an hour are dropped; the broker redelivers their messages.
+ */
+ private static final Cache<String, JmsCheckpointMark> LIVE_CHECKPOINTS =
+ CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build();
+
+ // May be null when restored from a checkpoint written by a version without this field.
Review Comment:
Probably should add `@AvroDefault("null")` for backwards compatiblity.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [JmsIO] Let restored checkpoint marks acknowledge live messages [beam]
Posted by "jbonofre (via GitHub) via github" <gi...@beam.apache.org>.
jbonofre merged PR #40605:
URL: https://github.com/apache/beam/pull/40605
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [JmsIO] Let restored checkpoint marks acknowledge live messages [beam]
Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre commented on code in PR #40605:
URL: https://github.com/apache/beam/pull/40605#discussion_r4411525134
##########
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsCheckpointMark.java:
##########
@@ -44,6 +46,20 @@ class JmsCheckpointMark implements UnboundedSource.CheckpointMark, Serializable
private static final Logger LOG = LoggerFactory.getLogger(JmsCheckpointMark.class);
+ /**
+ * Live checkpoints of this JVM that still hold unacknowledged messages, by id. The messages,
+ * consumer and session of a checkpoint are transient, so a runner that serializes and restores
+ * the mark (or recreates the reader) would otherwise lose them and never acknowledge. A restored
+ * mark uses this registry to find the live checkpoint with the same id and finalize that one.
+ */
+ private static final ConcurrentHashMap<String, JmsCheckpointMark> LIVE_CHECKPOINTS =
Review Comment:
Good point. I replaced the `ConcurrentHashMap` and the `removeIf` scan with a Guava `Cache` using `expireAfterWrite(1, HOURS)`.
Registering a checkpoint is now a single `put`, and finalize uses an atomic `asMap().remove(id)`.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [JmsIO] Let restored checkpoint marks acknowledge live messages [beam]
Posted by "jbonofre (via GitHub) via github" <gi...@beam.apache.org>.
jbonofre commented on PR #40605:
URL: https://github.com/apache/beam/pull/40605#issuecomment-6599895897
@chamikaramj I updated the PR to address your comments.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [JmsIO] Let restored checkpoint marks acknowledge live messages [beam]
Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre commented on code in PR #40605:
URL: https://github.com/apache/beam/pull/40605#discussion_r4411562922
##########
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsCheckpointMark.java:
##########
@@ -66,6 +82,15 @@ private JmsCheckpointMark(
/** Acknowledge all outstanding message. */
@Override
public void finalizeCheckpoint() {
+ if (messages == null && consumer == null && session == null) {
+ // Possibly a restored copy of a checkpoint whose state lives in another instance.
Review Comment:
Done. `id` is now `@Nullable`, and `finalizeCheckpoint()` skips the registry lookup when it's null.
Just a clarification from my side: the checkpoint coder here is `SerializableCoder`, not `AvroCoder` (see `UnboundedJmsSource#getCheckpointMarkCoder`).
A mark written by an older version still deserializes with `id == null`, so the guard applies.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [JmsIO] Let restored checkpoint marks acknowledge live messages [beam]
Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre commented on PR #40605:
URL: https://github.com/apache/beam/pull/40605#issuecomment-6495002264
@chamikaramj I did a first updates round 😄
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [JmsIO] Let restored checkpoint marks acknowledge live messages [beam]
Posted by "jbonofre (via GitHub) via github" <gi...@beam.apache.org>.
jbonofre commented on code in PR #40605:
URL: https://github.com/apache/beam/pull/40605#discussion_r4452812176
##########
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsCheckpointMark.java:
##########
@@ -44,6 +48,18 @@ class JmsCheckpointMark implements UnboundedSource.CheckpointMark, Serializable
private static final Logger LOG = LoggerFactory.getLogger(JmsCheckpointMark.class);
+ /**
+ * Live checkpoints of this JVM that still hold unacknowledged messages, by id. The messages,
+ * consumer and session of a checkpoint are transient, so a runner that serializes and restores
+ * the mark (or recreates the reader) would otherwise lose them and never acknowledge. A restored
+ * mark uses this registry to find the live checkpoint with the same id and finalize that one.
+ * Checkpoints not finalized within an hour are dropped; the broker redelivers their messages.
+ */
+ private static final Cache<String, JmsCheckpointMark> LIVE_CHECKPOINTS =
+ CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build();
Review Comment:
Done, the registry now also has `maximumSize(10_000)`. An evicted entry behaves like an expired one: a restored copy no longer finds the live checkpoint, and the broker redelivers its messages. The original instance still finalizes itself, since it holds its own state.
##########
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsCheckpointMark.java:
##########
@@ -44,6 +48,18 @@ class JmsCheckpointMark implements UnboundedSource.CheckpointMark, Serializable
private static final Logger LOG = LoggerFactory.getLogger(JmsCheckpointMark.class);
+ /**
+ * Live checkpoints of this JVM that still hold unacknowledged messages, by id. The messages,
+ * consumer and session of a checkpoint are transient, so a runner that serializes and restores
+ * the mark (or recreates the reader) would otherwise lose them and never acknowledge. A restored
+ * mark uses this registry to find the live checkpoint with the same id and finalize that one.
+ * Checkpoints not finalized within an hour are dropped; the broker redelivers their messages.
+ */
+ private static final Cache<String, JmsCheckpointMark> LIVE_CHECKPOINTS =
+ CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build();
+
+ // May be null when restored from a checkpoint written by a version without this field.
Review Comment:
The checkpoint mark coder is `SerializableCoder` (`UnboundedJmsSource#getCheckpointMarkCoder`), so `@AvroDefault` wouldn't apply. The test Javadoc saying "AvroCoder" was stale; I fixed it.
Your compatibility concern does apply to Java serialization, though: adding `id` changed the implicit `serialVersionUID`, so marks encoded before this change failed with `InvalidClassException`. I pinned `serialVersionUID` to the previous value (`-275230511397134772L`), so older marks decode with `id == null`. I also added `testDecodeCheckpointMarkWithoutId`, which decodes a mark encoded by the previous class.
##########
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsCheckpointMark.java:
##########
@@ -44,6 +48,18 @@ class JmsCheckpointMark implements UnboundedSource.CheckpointMark, Serializable
private static final Logger LOG = LoggerFactory.getLogger(JmsCheckpointMark.class);
+ /**
+ * Live checkpoints of this JVM that still hold unacknowledged messages, by id. The messages,
+ * consumer and session of a checkpoint are transient, so a runner that serializes and restores
+ * the mark (or recreates the reader) would otherwise lose them and never acknowledge. A restored
+ * mark uses this registry to find the live checkpoint with the same id and finalize that one.
+ * Checkpoints not finalized within an hour are dropped; the broker redelivers their messages.
+ */
+ private static final Cache<String, JmsCheckpointMark> LIVE_CHECKPOINTS =
+ CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build();
+
+ // May be null when restored from a checkpoint written by a version without this field.
+ private final @Nullable String id = UUID.randomUUID().toString();
Review Comment:
Agreed. They compare only `oldestMessageTimestamp` again, as before this PR, so the random id doesn't affect equality. The registry lookup uses the id directly, and `finalizeCheckpoint()` compares the live instance by reference.
##########
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsCheckpointMark.java:
##########
@@ -66,6 +82,15 @@ private JmsCheckpointMark(
/** Acknowledge all outstanding message. */
@Override
public void finalizeCheckpoint() {
+ if (messages == null && consumer == null && session == null) {
+ // Possibly a restored copy of a checkpoint whose state lives in another instance.
+ JmsCheckpointMark live = LIVE_CHECKPOINTS.get(id);
+ if (live != null) {
+ live.finalizeCheckpoint();
+ return;
+ }
+ }
+ LIVE_CHECKPOINTS.remove(id);
try {
Review Comment:
A checkpoint without messages can still hold a consumer and session to close (`CLIENT_ACKNOWLEDGE`), and it always increments `activeCheckpoints`, which the reader waits on before closing its connection. So we can't return on `messages == null` alone. `finalizeCheckpoint()` returns early when there is nothing to acknowledge or release (`messages`, `consumer`, `session` and `activeCheckpoints` all null).
##########
sdks/java/io/jms/src/test/java/org/apache/beam/sdk/io/jms/JmsLocalTest.java:
##########
@@ -170,6 +170,37 @@ public void testJmsCheckpointMarkClientAcknowledgeUnsafeNoSessionRecreation() th
assertEquals(0, activeCheckpoints.get());
}
+ @Test
+ public void testRestoredCheckpointMarkAcknowledgesLiveMessages() throws Exception {
+ Message msg = Mockito.mock(Message.class);
+ JmsCheckpointMark.Preparer preparer =
+ JmsCheckpointMark.newPreparer(JmsIO.AcknowledgeMode.INDIVIDUAL_ACKNOWLEDGE);
+ preparer.add(msg);
+ AtomicInteger activeCheckpoints = new AtomicInteger(0);
+ JmsCheckpointMark mark =
+ preparer.newCheckpoint(
+ null, null, JmsIO.AcknowledgeMode.INDIVIDUAL_ACKNOWLEDGE, activeCheckpoints);
+ int live = JmsCheckpointMark.liveCheckpointCount();
+
+ // serialize/deserialize drops the transient state, as when a runner restores the mark
Review Comment:
Done. Both tests now round-trip through the source's checkpoint mark coder (`SerializableCoder`) with `CoderUtils.clone`: `JmsLocalTest#testRestoredCheckpointMarkAcknowledgesLiveMessages` and `JmsIOTest#testRestoredCheckpointMarkFinalizedAfterReaderRecreation`.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [JmsIO] Let restored checkpoint marks acknowledge live messages [beam]
Posted by "jbonofre (via GitHub) via github" <gi...@beam.apache.org>.
jbonofre commented on PR #40605:
URL: https://github.com/apache/beam/pull/40605#issuecomment-6569390129
@chamikaramj thanks for the new review, I'm addressing your comments 😄
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org