You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "junaiddshaukat (via GitHub)" <gi...@apache.org> on 2026/06/14 07:32:00 UTC

[PR] [GSoC 2026] Kafka Streams runner — WatermarkManager part 1: in-memory per-source-partition tracking [beam]

junaiddshaukat opened a new pull request, #38957:
URL: https://github.com/apache/beam/pull/38957

   ## Summary
   First slice of the WatermarkManager, the prerequisite for any stateful
   transform (GroupByKey etc.). Too large for one PR, so split; this part is the
   in-memory core, decoupled from the Kafka wiring so it can be unit-tested in
   isolation. Plan agreed with @je-ik on Slack.
   
   ## Design (agreed with @je-ik)
   A stage's input watermark is min() over its upstream source partitions'
   committed watermarks. Tracking is keyed on source partitions, not producer
   instances:
   - the total source-partition count travels in-band with every report, so the
     reader always knows how many it's waiting for;
   - a partition is owned by exactly one live instance, and on failure its
     partitions are reassigned and the new owner keeps reporting — so a killed
     instance never leaves the reader stuck (no instance liveness tracking, no
     describeConsumerGroups, no generationId needed).
   Validated in a standalone Kafka Streams PoC before implementation.
   
   ## Scope (this PR)
   - `WatermarkManager`: `observe(sourcePartition, committedWatermarkMillis,
     totalSourcePartitions)`; holds at `BoundedWindow.TIMESTAMP_MIN_VALUE` until
     every source partition has reported; then emits `min()`; output is clamped
     non-decreasing; a change in `totalSourcePartitions` re-opens the hold (the
     "revert" case, without an explicit epoch).
   - 9 unit tests: hold/emit, per-partition monotonicity, no-regression clamp,
     partition-count increase/decrease, argument validation.
   
   ## Out of scope (later parts)
   - Part 2: wire into `ExecutableStageProcessor` — flush
     `(sourcePartition, committedWatermark, totalSourcePartitions)` atomically
     with the offset commit (EOS), fan out to all downstream partitions, consume
     + feed the manager, replace the provisional "flush on every watermark"
     behavior; real-Kafka integration tests over the 5 scenarios (steady,
     scale-out, clean scale-in, SIGKILL, partition reassignment).
   - Part 3: persistence / watermark holds and downstream timer firing once
     state + timers land.
   
   ## Testing
   `./gradlew :runners:kafka-streams:check` green; 9 new unit tests.
   
   Refs #18479


-- 
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] [GSoC 2026] Kafka Streams runner — WatermarkManager part 1: in-memory per-source-partition tracking [beam]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #38957:
URL: https://github.com/apache/beam/pull/38957#issuecomment-4701055873

   ## Summary of Changes
   
   Hello, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
   
   This pull request introduces the core in-memory logic for the WatermarkManager, a critical component for enabling stateful transforms in the Kafka Streams runner. By decoupling watermark tracking from Kafka-specific infrastructure, the implementation provides a robust, testable mechanism for calculating stage input watermarks based on source partition reports. This is the first of a multi-part effort to fully integrate watermark propagation into the runner.
   
   ### Highlights
   
   * **WatermarkManager Implementation**: Introduced the WatermarkManager class to track input watermarks for fused stages in the Kafka Streams runner, decoupled from Kafka-specific wiring.
   * **Robust Partition Tracking**: Implemented tracking based on source partitions rather than producer instances to ensure stability during rebalances and instance failures.
   * **Watermark Logic**: Added logic to maintain monotonicity, handle partition count changes, and enforce non-regression of the stage watermark.
   * **Comprehensive Testing**: Added 9 unit tests covering hold/emit behavior, monotonicity, partition count adjustments, and input validation.
   
   <details>
   <summary><b>New Features</b></summary>
   
   🧠 You can now enable **Memory** (public preview) to help **Gemini Code Assist** learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. **Click [here](https://codeassist.google/code-review/login) to enable Memory in your admin console.**
   </details>
   
   <details>
   <summary><b>Using Gemini Code Assist</b></summary>
   <br>
   
   The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.
   
   <b>Invoking Gemini</b>
   
   You can request assistance from Gemini at any point by creating a comment using either `/gemini <command>` or `@gemini-code-assist <command>`. Below is a summary of the supported commands on the current page.
   
   Feature | Command | Description
   --- | --- | ---
   Code Review | `/gemini review` | Performs a code review for the current pull request in its current state.
   Pull Request Summary | `/gemini summary` | Provides a summary of the current pull request in its current state.
   Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments.
   Help | `/gemini help` | Displays a list of available commands.
   
   <b>Customization</b>
   
   To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
   
   <b>Limitations & Feedback</b>
   
   Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up [here](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
   </details>
   
   
   [^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
   


-- 
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] [GSoC 2026] Kafka Streams runner — WatermarkManager part 1: in-memory per-source-partition tracking [beam]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #38957:
URL: https://github.com/apache/beam/pull/38957#discussion_r3409191554


##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/WatermarkManager.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.runners.kafka.streams.translation;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.OptionalLong;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+
+/**
+ * In-memory tracker of a single fused stage's input watermark, computed from the committed
+ * watermarks reported by its upstream <i>source partitions</i>.
+ *
+ * <p>This is the core of the Kafka Streams runner's watermark propagation, decoupled from the Kafka
+ * wiring so it can be unit-tested in isolation. The wiring that produces the reports (flushing
+ * {@code (sourcePartition, committedWatermark, totalSourcePartitions)} atomically with each offset
+ * commit and fanning it out to every downstream partition) and consumes them lands in a follow-up.
+ *
+ * <h3>Why source partitions, not producer instances</h3>
+ *
+ * <p>The question a stage has to answer is "have I received the watermark from every upstream
+ * producer, so that {@code min()} across them is meaningful?". Counting <i>producer instances</i>
+ * is hard: an instance can be killed without notice, leaving stale state, and the number changes on
+ * every rebalance. Counting <i>source partitions</i> is robust instead, because the partition count
+ * is fixed and known: it travels in-band with every report ({@code totalSourcePartitions}), a
+ * partition is always owned by exactly one live instance, and when an instance dies its partitions
+ * are reassigned and the new owner keeps reporting. So the manager only ever reasons about
+ * partitions, never about instances. (Design agreed with the mentor; see the watermark
+ * coordination-channel PoC findings.)
+ *
+ * <h3>Holding until complete</h3>
+ *
+ * <p>Until a committed watermark has been seen for <i>every</i> source partition, the stage's input
+ * watermark is undefined and must be held at {@link BoundedWindow#TIMESTAMP_MIN_VALUE} — i.e. the
+ * stage emits no watermark downstream. {@link #advance()} returns {@link OptionalLong#empty()} in
+ * that case. A change in {@code totalSourcePartitions} (e.g. a repartition) re-opens this hold
+ * until the new full set has reported, which subsumes the "new epoch / revert" rule without an
+ * explicit epoch.
+ *
+ * <h3>Monotonicity</h3>
+ *
+ * <p>Beam watermarks must be non-decreasing. Each source partition's watermark is held monotonic (a
+ * lower report is ignored), and the emitted stage watermark is additionally clamped so it never
+ * regresses below the previously emitted value — relevant if a newly appeared partition reports an
+ * older watermark after the stage had already advanced.
+ *
+ * <p>Not thread-safe; the caller (a single Kafka Streams processor thread) serializes access.
+ */
+public final class WatermarkManager {
+
+  /** Millis the stage holds at while it cannot yet emit a watermark (the Beam minimum). */
+  public static final long HOLD_MILLIS = BoundedWindow.TIMESTAMP_MIN_VALUE.getMillis();
+
+  /** Total source partitions feeding this stage, learned in-band; -1 until the first report. */
+  private int expectedSourcePartitionCount = -1;
+
+  /** Latest committed watermark per source partition (kept monotonic non-decreasing). */
+  private final Map<Integer, Long> committedWatermarkByPartition = new HashMap<>();
+
+  /** Last watermark {@link #advance()} emitted, to enforce a non-decreasing output. */
+  private long lastEmittedMillis = HOLD_MILLIS;
+
+  /**
+   * Record a committed watermark reported for one source partition, together with the total source
+   * partition count carried in-band with the report.
+   *
+   * @param sourcePartition the source partition the report is for, in {@code [0,
+   *     totalSourcePartitions)}
+   * @param committedWatermarkMillis the committed watermark for that partition, in event-time
+   *     millis
+   * @param totalSourcePartitions the total number of source partitions feeding this stage
+   */
+  public void observe(
+      int sourcePartition, long committedWatermarkMillis, int totalSourcePartitions) {
+    if (totalSourcePartitions <= 0) {
+      throw new IllegalArgumentException(
+          "totalSourcePartitions must be positive: " + totalSourcePartitions);
+    }
+    if (sourcePartition < 0 || sourcePartition >= totalSourcePartitions) {
+      throw new IllegalArgumentException(
+          "sourcePartition "
+              + sourcePartition
+              + " out of range for totalSourcePartitions "
+              + totalSourcePartitions);
+    }
+    if (totalSourcePartitions != expectedSourcePartitionCount) {
+      expectedSourcePartitionCount = totalSourcePartitions;
+      // On a partition-count decrease, drop reports for partitions that no longer exist so
+      // completeness and min() are computed over the current partition set only.
+      committedWatermarkByPartition.keySet().removeIf(p -> p >= totalSourcePartitions);
+    }

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   When the `totalSourcePartitions` count changes (e.g., during a repartitioning or scaling event), the mapping and distribution of partitions change.
   
   Currently, if the partition count decreases (e.g., from 4 to 2), the code only prunes partitions with indices `>= totalSourcePartitions` (line 105). However, if partitions `0` and `1` had already reported watermarks in the previous epoch, `isComplete()` will immediately return `true` without waiting for fresh reports from the new epoch. This can lead to using stale/outdated watermarks from the old partition layout, potentially causing the stage watermark to over-advance incorrectly.
   
   To ensure correctness and adhere to the design goal of re-opening the hold until the new full set has reported, we should clear the `committedWatermarkByPartition` map whenever `totalSourcePartitions` changes. Since `lastEmittedMillis` protects the stage watermark from regressing, clearing the map is perfectly safe and guarantees we wait for a fresh report from every partition in the new layout.
   
   Note: If you apply this change, you will also need to update the corresponding unit tests in `WatermarkManagerTest.java` (such as `partitionCountIncreaseReopensHold` and `partitionCountDecreasePrunesStalePartitions`) to ensure all partitions report after a partition count change.
   
   ```suggestion
       if (totalSourcePartitions != expectedSourcePartitionCount) {
         expectedSourcePartitionCount = totalSourcePartitions;
         // On a partition-count change, clear previous reports to ensure we wait for a fresh
         // report from every partition in the new layout, avoiding stale watermarks.
         committedWatermarkByPartition.clear();
       }
   ```



-- 
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] [GSoC 2026] Kafka Streams runner — WatermarkManager part 1: in-memory per-source-partition tracking [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #38957:
URL: https://github.com/apache/beam/pull/38957#issuecomment-4701295416

   Assigning reviewers:
   
   R: @kennknowles added as fallback since no labels match configuration
   
   
   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] [GSoC 2026] Kafka Streams runner — WatermarkManager part 1: in-memory per-source-partition tracking [beam]

Posted by "junaiddshaukat (via GitHub)" <gi...@apache.org>.
junaiddshaukat commented on PR #38957:
URL: https://github.com/apache/beam/pull/38957#issuecomment-4708629546

   Thanks for the review addressed all of it in the latest commit:
   
   1. HOLD_MILLIS constant dropped it. Using BoundedWindow.TIMESTAMP_MIN_VALUE
      directly now so there's no clash with the Beam "watermark hold" concept.
   2. "partitions feeding this stage" right, these are the parent stage's
      output / repartition-topic partitions that feed this stage. Reworded the
      docs to say that explicitly.
   3. Partition-count change  now clears the whole per-partition map instead of
      pruning only out-of-range partitions, so completeness and min() are always
      computed over one consistent partitioning.
   4. isComplete() — renamed to isReady() (agree "complete" could read as the
      watermark having reached TIMESTAMP_MAX_VALUE).
   5. Instant + the empty==MIN question  witched the whole class from long
      millis to org.joda.time.Instant. advance() now returns an Instant, and a
      holding stage returns TIMESTAMP_MIN_VALUE instead of an empty Optional, so
      that ambiguity is gone.
   6. The two inspection getters — made them package-private + @VisibleForTesting.
   
   :runners:kafka-streams:check is green (10 unit tests). Let me know if anything
   else needs tweaking.


-- 
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] [GSoC 2026] Kafka Streams runner — WatermarkManager part 1: in-memory per-source-partition tracking [beam]

Posted by "je-ik (via GitHub)" <gi...@apache.org>.
je-ik commented on code in PR #38957:
URL: https://github.com/apache/beam/pull/38957#discussion_r3412122422


##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/WatermarkManager.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.runners.kafka.streams.translation;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.OptionalLong;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+
+/**
+ * In-memory tracker of a single fused stage's input watermark, computed from the committed
+ * watermarks reported by its upstream <i>source partitions</i>.
+ *
+ * <p>This is the core of the Kafka Streams runner's watermark propagation, decoupled from the Kafka
+ * wiring so it can be unit-tested in isolation. The wiring that produces the reports (flushing
+ * {@code (sourcePartition, committedWatermark, totalSourcePartitions)} atomically with each offset
+ * commit and fanning it out to every downstream partition) and consumes them lands in a follow-up.
+ *
+ * <h3>Why source partitions, not producer instances</h3>
+ *
+ * <p>The question a stage has to answer is "have I received the watermark from every upstream
+ * producer, so that {@code min()} across them is meaningful?". Counting <i>producer instances</i>
+ * is hard: an instance can be killed without notice, leaving stale state, and the number changes on
+ * every rebalance. Counting <i>source partitions</i> is robust instead, because the partition count
+ * is fixed and known: it travels in-band with every report ({@code totalSourcePartitions}), a
+ * partition is always owned by exactly one live instance, and when an instance dies its partitions
+ * are reassigned and the new owner keeps reporting. So the manager only ever reasons about
+ * partitions, never about instances. (Design agreed with the mentor; see the watermark
+ * coordination-channel PoC findings.)
+ *
+ * <h3>Holding until complete</h3>
+ *
+ * <p>Until a committed watermark has been seen for <i>every</i> source partition, the stage's input
+ * watermark is undefined and must be held at {@link BoundedWindow#TIMESTAMP_MIN_VALUE} — i.e. the
+ * stage emits no watermark downstream. {@link #advance()} returns {@link OptionalLong#empty()} in
+ * that case. A change in {@code totalSourcePartitions} (e.g. a repartition) re-opens this hold
+ * until the new full set has reported, which subsumes the "new epoch / revert" rule without an
+ * explicit epoch.
+ *
+ * <h3>Monotonicity</h3>
+ *
+ * <p>Beam watermarks must be non-decreasing. Each source partition's watermark is held monotonic (a
+ * lower report is ignored), and the emitted stage watermark is additionally clamped so it never
+ * regresses below the previously emitted value — relevant if a newly appeared partition reports an
+ * older watermark after the stage had already advanced.
+ *
+ * <p>Not thread-safe; the caller (a single Kafka Streams processor thread) serializes access.
+ */
+public final class WatermarkManager {
+
+  /** Millis the stage holds at while it cannot yet emit a watermark (the Beam minimum). */
+  public static final long HOLD_MILLIS = BoundedWindow.TIMESTAMP_MIN_VALUE.getMillis();
+
+  /** Total source partitions feeding this stage, learned in-band; -1 until the first report. */
+  private int expectedSourcePartitionCount = -1;
+
+  /** Latest committed watermark per source partition (kept monotonic non-decreasing). */
+  private final Map<Integer, Long> committedWatermarkByPartition = new HashMap<>();
+
+  /** Last watermark {@link #advance()} emitted, to enforce a non-decreasing output. */
+  private long lastEmittedMillis = HOLD_MILLIS;
+
+  /**
+   * Record a committed watermark reported for one source partition, together with the total source
+   * partition count carried in-band with the report.
+   *
+   * @param sourcePartition the source partition the report is for, in {@code [0,
+   *     totalSourcePartitions)}
+   * @param committedWatermarkMillis the committed watermark for that partition, in event-time
+   *     millis
+   * @param totalSourcePartitions the total number of source partitions feeding this stage
+   */
+  public void observe(
+      int sourcePartition, long committedWatermarkMillis, int totalSourcePartitions) {
+    if (totalSourcePartitions <= 0) {
+      throw new IllegalArgumentException(
+          "totalSourcePartitions must be positive: " + totalSourcePartitions);
+    }
+    if (sourcePartition < 0 || sourcePartition >= totalSourcePartitions) {
+      throw new IllegalArgumentException(
+          "sourcePartition "
+              + sourcePartition
+              + " out of range for totalSourcePartitions "
+              + totalSourcePartitions);
+    }
+    if (totalSourcePartitions != expectedSourcePartitionCount) {
+      expectedSourcePartitionCount = totalSourcePartitions;
+      // On a partition-count decrease, drop reports for partitions that no longer exist so
+      // completeness and min() are computed over the current partition set only.
+      committedWatermarkByPartition.keySet().removeIf(p -> p >= totalSourcePartitions);
+    }
+    // A source partition's watermark is monotonic non-decreasing; ignore an out-of-order lower
+    // report.
+    committedWatermarkByPartition.merge(sourcePartition, committedWatermarkMillis, Math::max);
+  }
+
+  /** True once a committed watermark has been seen for every current source partition. */
+  public boolean isComplete() {
+    return expectedSourcePartitionCount > 0
+        && committedWatermarkByPartition.size() == expectedSourcePartitionCount;
+  }
+
+  /**
+   * Advance and return the stage input watermark.
+   *
+   * <p>Returns {@link OptionalLong#empty()} while the stage is still holding (not every source

Review Comment:
   Is isEmpty() here the equivallent of TIMESTAMP_MIN_VALUE?
   
   Also the standard in Beam codebase is to use Instant, where possible, maybe we could use the same logic in the WatermarkManager? Costs of transition from Instant to long millis are likely compiled away.



##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/WatermarkManager.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.runners.kafka.streams.translation;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.OptionalLong;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+
+/**
+ * In-memory tracker of a single fused stage's input watermark, computed from the committed
+ * watermarks reported by its upstream <i>source partitions</i>.
+ *
+ * <p>This is the core of the Kafka Streams runner's watermark propagation, decoupled from the Kafka
+ * wiring so it can be unit-tested in isolation. The wiring that produces the reports (flushing
+ * {@code (sourcePartition, committedWatermark, totalSourcePartitions)} atomically with each offset
+ * commit and fanning it out to every downstream partition) and consumes them lands in a follow-up.
+ *
+ * <h3>Why source partitions, not producer instances</h3>
+ *
+ * <p>The question a stage has to answer is "have I received the watermark from every upstream
+ * producer, so that {@code min()} across them is meaningful?". Counting <i>producer instances</i>
+ * is hard: an instance can be killed without notice, leaving stale state, and the number changes on
+ * every rebalance. Counting <i>source partitions</i> is robust instead, because the partition count
+ * is fixed and known: it travels in-band with every report ({@code totalSourcePartitions}), a
+ * partition is always owned by exactly one live instance, and when an instance dies its partitions
+ * are reassigned and the new owner keeps reporting. So the manager only ever reasons about
+ * partitions, never about instances. (Design agreed with the mentor; see the watermark
+ * coordination-channel PoC findings.)
+ *
+ * <h3>Holding until complete</h3>
+ *
+ * <p>Until a committed watermark has been seen for <i>every</i> source partition, the stage's input
+ * watermark is undefined and must be held at {@link BoundedWindow#TIMESTAMP_MIN_VALUE} — i.e. the
+ * stage emits no watermark downstream. {@link #advance()} returns {@link OptionalLong#empty()} in
+ * that case. A change in {@code totalSourcePartitions} (e.g. a repartition) re-opens this hold
+ * until the new full set has reported, which subsumes the "new epoch / revert" rule without an
+ * explicit epoch.
+ *
+ * <h3>Monotonicity</h3>
+ *
+ * <p>Beam watermarks must be non-decreasing. Each source partition's watermark is held monotonic (a
+ * lower report is ignored), and the emitted stage watermark is additionally clamped so it never
+ * regresses below the previously emitted value — relevant if a newly appeared partition reports an
+ * older watermark after the stage had already advanced.
+ *
+ * <p>Not thread-safe; the caller (a single Kafka Streams processor thread) serializes access.
+ */
+public final class WatermarkManager {
+
+  /** Millis the stage holds at while it cannot yet emit a watermark (the Beam minimum). */
+  public static final long HOLD_MILLIS = BoundedWindow.TIMESTAMP_MIN_VALUE.getMillis();
+
+  /** Total source partitions feeding this stage, learned in-band; -1 until the first report. */
+  private int expectedSourcePartitionCount = -1;
+
+  /** Latest committed watermark per source partition (kept monotonic non-decreasing). */
+  private final Map<Integer, Long> committedWatermarkByPartition = new HashMap<>();
+
+  /** Last watermark {@link #advance()} emitted, to enforce a non-decreasing output. */
+  private long lastEmittedMillis = HOLD_MILLIS;
+
+  /**
+   * Record a committed watermark reported for one source partition, together with the total source
+   * partition count carried in-band with the report.
+   *
+   * @param sourcePartition the source partition the report is for, in {@code [0,
+   *     totalSourcePartitions)}
+   * @param committedWatermarkMillis the committed watermark for that partition, in event-time
+   *     millis
+   * @param totalSourcePartitions the total number of source partitions feeding this stage
+   */
+  public void observe(
+      int sourcePartition, long committedWatermarkMillis, int totalSourcePartitions) {
+    if (totalSourcePartitions <= 0) {
+      throw new IllegalArgumentException(
+          "totalSourcePartitions must be positive: " + totalSourcePartitions);
+    }
+    if (sourcePartition < 0 || sourcePartition >= totalSourcePartitions) {
+      throw new IllegalArgumentException(
+          "sourcePartition "
+              + sourcePartition
+              + " out of range for totalSourcePartitions "
+              + totalSourcePartitions);
+    }
+    if (totalSourcePartitions != expectedSourcePartitionCount) {
+      expectedSourcePartitionCount = totalSourcePartitions;
+      // On a partition-count decrease, drop reports for partitions that no longer exist so
+      // completeness and min() are computed over the current partition set only.
+      committedWatermarkByPartition.keySet().removeIf(p -> p >= totalSourcePartitions);
+    }
+    // A source partition's watermark is monotonic non-decreasing; ignore an out-of-order lower
+    // report.
+    committedWatermarkByPartition.merge(sourcePartition, committedWatermarkMillis, Math::max);
+  }
+
+  /** True once a committed watermark has been seen for every current source partition. */
+  public boolean isComplete() {

Review Comment:
   Suggest to rename this "complete" in terms of watermark could imply the watermark arrived at the highest value (TIMESTAMP_MAX_VALUE). Maybe "isReady"?



##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/WatermarkManager.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.runners.kafka.streams.translation;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.OptionalLong;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+
+/**
+ * In-memory tracker of a single fused stage's input watermark, computed from the committed
+ * watermarks reported by its upstream <i>source partitions</i>.
+ *
+ * <p>This is the core of the Kafka Streams runner's watermark propagation, decoupled from the Kafka
+ * wiring so it can be unit-tested in isolation. The wiring that produces the reports (flushing
+ * {@code (sourcePartition, committedWatermark, totalSourcePartitions)} atomically with each offset
+ * commit and fanning it out to every downstream partition) and consumes them lands in a follow-up.
+ *
+ * <h3>Why source partitions, not producer instances</h3>
+ *
+ * <p>The question a stage has to answer is "have I received the watermark from every upstream
+ * producer, so that {@code min()} across them is meaningful?". Counting <i>producer instances</i>
+ * is hard: an instance can be killed without notice, leaving stale state, and the number changes on
+ * every rebalance. Counting <i>source partitions</i> is robust instead, because the partition count
+ * is fixed and known: it travels in-band with every report ({@code totalSourcePartitions}), a
+ * partition is always owned by exactly one live instance, and when an instance dies its partitions
+ * are reassigned and the new owner keeps reporting. So the manager only ever reasons about
+ * partitions, never about instances. (Design agreed with the mentor; see the watermark
+ * coordination-channel PoC findings.)
+ *
+ * <h3>Holding until complete</h3>
+ *
+ * <p>Until a committed watermark has been seen for <i>every</i> source partition, the stage's input
+ * watermark is undefined and must be held at {@link BoundedWindow#TIMESTAMP_MIN_VALUE} — i.e. the
+ * stage emits no watermark downstream. {@link #advance()} returns {@link OptionalLong#empty()} in
+ * that case. A change in {@code totalSourcePartitions} (e.g. a repartition) re-opens this hold
+ * until the new full set has reported, which subsumes the "new epoch / revert" rule without an
+ * explicit epoch.
+ *
+ * <h3>Monotonicity</h3>
+ *
+ * <p>Beam watermarks must be non-decreasing. Each source partition's watermark is held monotonic (a
+ * lower report is ignored), and the emitted stage watermark is additionally clamped so it never
+ * regresses below the previously emitted value — relevant if a newly appeared partition reports an
+ * older watermark after the stage had already advanced.
+ *
+ * <p>Not thread-safe; the caller (a single Kafka Streams processor thread) serializes access.
+ */
+public final class WatermarkManager {
+
+  /** Millis the stage holds at while it cannot yet emit a watermark (the Beam minimum). */
+  public static final long HOLD_MILLIS = BoundedWindow.TIMESTAMP_MIN_VALUE.getMillis();
+
+  /** Total source partitions feeding this stage, learned in-band; -1 until the first report. */

Review Comment:
   Is this really the number of partitions feed _this_ stage, or _parent of this_ stage?



##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/WatermarkManager.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.runners.kafka.streams.translation;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.OptionalLong;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+
+/**
+ * In-memory tracker of a single fused stage's input watermark, computed from the committed
+ * watermarks reported by its upstream <i>source partitions</i>.
+ *
+ * <p>This is the core of the Kafka Streams runner's watermark propagation, decoupled from the Kafka
+ * wiring so it can be unit-tested in isolation. The wiring that produces the reports (flushing
+ * {@code (sourcePartition, committedWatermark, totalSourcePartitions)} atomically with each offset
+ * commit and fanning it out to every downstream partition) and consumes them lands in a follow-up.
+ *
+ * <h3>Why source partitions, not producer instances</h3>
+ *
+ * <p>The question a stage has to answer is "have I received the watermark from every upstream
+ * producer, so that {@code min()} across them is meaningful?". Counting <i>producer instances</i>
+ * is hard: an instance can be killed without notice, leaving stale state, and the number changes on
+ * every rebalance. Counting <i>source partitions</i> is robust instead, because the partition count
+ * is fixed and known: it travels in-band with every report ({@code totalSourcePartitions}), a
+ * partition is always owned by exactly one live instance, and when an instance dies its partitions
+ * are reassigned and the new owner keeps reporting. So the manager only ever reasons about
+ * partitions, never about instances. (Design agreed with the mentor; see the watermark
+ * coordination-channel PoC findings.)
+ *
+ * <h3>Holding until complete</h3>
+ *
+ * <p>Until a committed watermark has been seen for <i>every</i> source partition, the stage's input
+ * watermark is undefined and must be held at {@link BoundedWindow#TIMESTAMP_MIN_VALUE} — i.e. the
+ * stage emits no watermark downstream. {@link #advance()} returns {@link OptionalLong#empty()} in
+ * that case. A change in {@code totalSourcePartitions} (e.g. a repartition) re-opens this hold
+ * until the new full set has reported, which subsumes the "new epoch / revert" rule without an
+ * explicit epoch.
+ *
+ * <h3>Monotonicity</h3>
+ *
+ * <p>Beam watermarks must be non-decreasing. Each source partition's watermark is held monotonic (a
+ * lower report is ignored), and the emitted stage watermark is additionally clamped so it never
+ * regresses below the previously emitted value — relevant if a newly appeared partition reports an
+ * older watermark after the stage had already advanced.
+ *
+ * <p>Not thread-safe; the caller (a single Kafka Streams processor thread) serializes access.
+ */
+public final class WatermarkManager {
+
+  /** Millis the stage holds at while it cannot yet emit a watermark (the Beam minimum). */
+  public static final long HOLD_MILLIS = BoundedWindow.TIMESTAMP_MIN_VALUE.getMillis();

Review Comment:
   I'd suggest just use the original constant. This could be confusing, because "watermark hold" is a Beam's core construct. This just references the min timestamp.
   
   If we want to avoid calling getMillis() (which on the other hand is extremely cheap), we can store this in TIMESTAMP_MIN_MS or something like that.



##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/WatermarkManager.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.runners.kafka.streams.translation;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.OptionalLong;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+
+/**
+ * In-memory tracker of a single fused stage's input watermark, computed from the committed
+ * watermarks reported by its upstream <i>source partitions</i>.
+ *
+ * <p>This is the core of the Kafka Streams runner's watermark propagation, decoupled from the Kafka
+ * wiring so it can be unit-tested in isolation. The wiring that produces the reports (flushing
+ * {@code (sourcePartition, committedWatermark, totalSourcePartitions)} atomically with each offset
+ * commit and fanning it out to every downstream partition) and consumes them lands in a follow-up.
+ *
+ * <h3>Why source partitions, not producer instances</h3>
+ *
+ * <p>The question a stage has to answer is "have I received the watermark from every upstream
+ * producer, so that {@code min()} across them is meaningful?". Counting <i>producer instances</i>
+ * is hard: an instance can be killed without notice, leaving stale state, and the number changes on
+ * every rebalance. Counting <i>source partitions</i> is robust instead, because the partition count
+ * is fixed and known: it travels in-band with every report ({@code totalSourcePartitions}), a
+ * partition is always owned by exactly one live instance, and when an instance dies its partitions
+ * are reassigned and the new owner keeps reporting. So the manager only ever reasons about
+ * partitions, never about instances. (Design agreed with the mentor; see the watermark
+ * coordination-channel PoC findings.)
+ *
+ * <h3>Holding until complete</h3>
+ *
+ * <p>Until a committed watermark has been seen for <i>every</i> source partition, the stage's input
+ * watermark is undefined and must be held at {@link BoundedWindow#TIMESTAMP_MIN_VALUE} — i.e. the
+ * stage emits no watermark downstream. {@link #advance()} returns {@link OptionalLong#empty()} in
+ * that case. A change in {@code totalSourcePartitions} (e.g. a repartition) re-opens this hold
+ * until the new full set has reported, which subsumes the "new epoch / revert" rule without an
+ * explicit epoch.
+ *
+ * <h3>Monotonicity</h3>
+ *
+ * <p>Beam watermarks must be non-decreasing. Each source partition's watermark is held monotonic (a
+ * lower report is ignored), and the emitted stage watermark is additionally clamped so it never
+ * regresses below the previously emitted value — relevant if a newly appeared partition reports an
+ * older watermark after the stage had already advanced.
+ *
+ * <p>Not thread-safe; the caller (a single Kafka Streams processor thread) serializes access.
+ */
+public final class WatermarkManager {
+
+  /** Millis the stage holds at while it cannot yet emit a watermark (the Beam minimum). */
+  public static final long HOLD_MILLIS = BoundedWindow.TIMESTAMP_MIN_VALUE.getMillis();
+
+  /** Total source partitions feeding this stage, learned in-band; -1 until the first report. */
+  private int expectedSourcePartitionCount = -1;
+
+  /** Latest committed watermark per source partition (kept monotonic non-decreasing). */
+  private final Map<Integer, Long> committedWatermarkByPartition = new HashMap<>();
+
+  /** Last watermark {@link #advance()} emitted, to enforce a non-decreasing output. */
+  private long lastEmittedMillis = HOLD_MILLIS;
+
+  /**
+   * Record a committed watermark reported for one source partition, together with the total source
+   * partition count carried in-band with the report.
+   *
+   * @param sourcePartition the source partition the report is for, in {@code [0,
+   *     totalSourcePartitions)}
+   * @param committedWatermarkMillis the committed watermark for that partition, in event-time
+   *     millis
+   * @param totalSourcePartitions the total number of source partitions feeding this stage
+   */
+  public void observe(
+      int sourcePartition, long committedWatermarkMillis, int totalSourcePartitions) {
+    if (totalSourcePartitions <= 0) {
+      throw new IllegalArgumentException(
+          "totalSourcePartitions must be positive: " + totalSourcePartitions);
+    }
+    if (sourcePartition < 0 || sourcePartition >= totalSourcePartitions) {
+      throw new IllegalArgumentException(
+          "sourcePartition "
+              + sourcePartition
+              + " out of range for totalSourcePartitions "
+              + totalSourcePartitions);
+    }
+    if (totalSourcePartitions != expectedSourcePartitionCount) {
+      expectedSourcePartitionCount = totalSourcePartitions;
+      // On a partition-count decrease, drop reports for partitions that no longer exist so
+      // completeness and min() are computed over the current partition set only.
+      committedWatermarkByPartition.keySet().removeIf(p -> p >= totalSourcePartitions);
+    }

Review Comment:
   Yes, we need to clear the mapping altogether.



##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/WatermarkManager.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.runners.kafka.streams.translation;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.OptionalLong;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+
+/**
+ * In-memory tracker of a single fused stage's input watermark, computed from the committed
+ * watermarks reported by its upstream <i>source partitions</i>.
+ *
+ * <p>This is the core of the Kafka Streams runner's watermark propagation, decoupled from the Kafka
+ * wiring so it can be unit-tested in isolation. The wiring that produces the reports (flushing
+ * {@code (sourcePartition, committedWatermark, totalSourcePartitions)} atomically with each offset
+ * commit and fanning it out to every downstream partition) and consumes them lands in a follow-up.
+ *
+ * <h3>Why source partitions, not producer instances</h3>
+ *
+ * <p>The question a stage has to answer is "have I received the watermark from every upstream
+ * producer, so that {@code min()} across them is meaningful?". Counting <i>producer instances</i>
+ * is hard: an instance can be killed without notice, leaving stale state, and the number changes on
+ * every rebalance. Counting <i>source partitions</i> is robust instead, because the partition count
+ * is fixed and known: it travels in-band with every report ({@code totalSourcePartitions}), a
+ * partition is always owned by exactly one live instance, and when an instance dies its partitions
+ * are reassigned and the new owner keeps reporting. So the manager only ever reasons about
+ * partitions, never about instances. (Design agreed with the mentor; see the watermark
+ * coordination-channel PoC findings.)
+ *
+ * <h3>Holding until complete</h3>
+ *
+ * <p>Until a committed watermark has been seen for <i>every</i> source partition, the stage's input
+ * watermark is undefined and must be held at {@link BoundedWindow#TIMESTAMP_MIN_VALUE} — i.e. the
+ * stage emits no watermark downstream. {@link #advance()} returns {@link OptionalLong#empty()} in
+ * that case. A change in {@code totalSourcePartitions} (e.g. a repartition) re-opens this hold
+ * until the new full set has reported, which subsumes the "new epoch / revert" rule without an
+ * explicit epoch.
+ *
+ * <h3>Monotonicity</h3>
+ *
+ * <p>Beam watermarks must be non-decreasing. Each source partition's watermark is held monotonic (a
+ * lower report is ignored), and the emitted stage watermark is additionally clamped so it never
+ * regresses below the previously emitted value — relevant if a newly appeared partition reports an
+ * older watermark after the stage had already advanced.
+ *
+ * <p>Not thread-safe; the caller (a single Kafka Streams processor thread) serializes access.
+ */
+public final class WatermarkManager {
+
+  /** Millis the stage holds at while it cannot yet emit a watermark (the Beam minimum). */
+  public static final long HOLD_MILLIS = BoundedWindow.TIMESTAMP_MIN_VALUE.getMillis();
+
+  /** Total source partitions feeding this stage, learned in-band; -1 until the first report. */
+  private int expectedSourcePartitionCount = -1;
+
+  /** Latest committed watermark per source partition (kept monotonic non-decreasing). */
+  private final Map<Integer, Long> committedWatermarkByPartition = new HashMap<>();
+
+  /** Last watermark {@link #advance()} emitted, to enforce a non-decreasing output. */
+  private long lastEmittedMillis = HOLD_MILLIS;
+
+  /**
+   * Record a committed watermark reported for one source partition, together with the total source
+   * partition count carried in-band with the report.
+   *
+   * @param sourcePartition the source partition the report is for, in {@code [0,
+   *     totalSourcePartitions)}
+   * @param committedWatermarkMillis the committed watermark for that partition, in event-time
+   *     millis
+   * @param totalSourcePartitions the total number of source partitions feeding this stage
+   */
+  public void observe(
+      int sourcePartition, long committedWatermarkMillis, int totalSourcePartitions) {
+    if (totalSourcePartitions <= 0) {
+      throw new IllegalArgumentException(
+          "totalSourcePartitions must be positive: " + totalSourcePartitions);
+    }
+    if (sourcePartition < 0 || sourcePartition >= totalSourcePartitions) {
+      throw new IllegalArgumentException(
+          "sourcePartition "
+              + sourcePartition
+              + " out of range for totalSourcePartitions "
+              + totalSourcePartitions);
+    }
+    if (totalSourcePartitions != expectedSourcePartitionCount) {
+      expectedSourcePartitionCount = totalSourcePartitions;
+      // On a partition-count decrease, drop reports for partitions that no longer exist so
+      // completeness and min() are computed over the current partition set only.
+      committedWatermarkByPartition.keySet().removeIf(p -> p >= totalSourcePartitions);
+    }
+    // A source partition's watermark is monotonic non-decreasing; ignore an out-of-order lower
+    // report.
+    committedWatermarkByPartition.merge(sourcePartition, committedWatermarkMillis, Math::max);
+  }
+
+  /** True once a committed watermark has been seen for every current source partition. */
+  public boolean isComplete() {
+    return expectedSourcePartitionCount > 0
+        && committedWatermarkByPartition.size() == expectedSourcePartitionCount;
+  }
+
+  /**
+   * Advance and return the stage input watermark.
+   *
+   * <p>Returns {@link OptionalLong#empty()} while the stage is still holding (not every source
+   * partition has reported) — the caller must emit nothing downstream in that case. Once complete,
+   * returns {@code min()} over all source partitions, clamped to never regress below the previously
+   * emitted value. The sequence of present values returned across calls is non-decreasing.
+   */
+  public OptionalLong advance() {
+    if (!isComplete()) {
+      return OptionalLong.empty();
+    }
+    long min = Long.MAX_VALUE;
+    for (long w : committedWatermarkByPartition.values()) {
+      min = Math.min(min, w);
+    }
+    long emit = Math.max(min, lastEmittedMillis);
+    lastEmittedMillis = emit;
+    return OptionalLong.of(emit);
+  }
+
+  /** The total source partition count learned in-band, or -1 if nothing reported yet. */
+  public int expectedSourcePartitionCount() {

Review Comment:
   Are these two methods supposed to be package-private and `@VisibleForTesting`?



-- 
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] [GSoC 2026] Kafka Streams runner — WatermarkManager part 1: in-memory per-source-partition tracking [beam]

Posted by "je-ik (via GitHub)" <gi...@apache.org>.
je-ik commented on PR #38957:
URL: https://github.com/apache/beam/pull/38957#issuecomment-4710586149

   @junaiddshaukat you can use the review comments for a conversation. A comment should generally be resolved by the one who opened it, which then makes the process iterative and does not need a recap on the next push. :)


-- 
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] [GSoC 2026] Kafka Streams runner — WatermarkManager part 1: in-memory per-source-partition tracking [beam]

Posted by "je-ik (via GitHub)" <gi...@apache.org>.
je-ik commented on PR #38957:
URL: https://github.com/apache/beam/pull/38957#issuecomment-4710619158

   Thanks for the updates! :+1: 


-- 
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] [GSoC 2026] Kafka Streams runner — WatermarkManager part 1: in-memory per-source-partition tracking [beam]

Posted by "je-ik (via GitHub)" <gi...@apache.org>.
je-ik merged PR #38957:
URL: https://github.com/apache/beam/pull/38957


-- 
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