You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "deepthi912 (via GitHub)" <gi...@apache.org> on 2026/09/08 23:17:51 UTC

[PR] Defer TTL watermark bump until after segment add / preload / replace [pinot]

deepthi912 opened a new pull request, #19512:
URL: https://github.com/apache/pinot/pull/19512

   ## Problem
   
   `BasePartitionUpsertMetadataManager.doAddSegment`, `doPreloadSegment`, and `doReplaceSegment` currently advance `_largestSeenComparisonValue` **before** the segment's rows are inserted into `_primaryKeyToRecordLocationMap`. A concurrent `removeExpiredPrimaryKeys` sweep on another thread reads the newly-advanced watermark and can expire pointers for primary keys the in-flight add is about to insert, producing duplicate first-row inserts on those keys.
   
   Race timeline (`doAddSegment` for segment with `max=1000`, `metadataTTL=300`, previous watermark `500`):
   1. T1 bumps `_largestSeenComparisonValue` from 500 → 1000.
   2. T2 (`removeExpiredPrimaryKeys`) reads watermark = 1000, expires all PKs with comparison value `< 700`.
   3. T1 inserts segment's rows; any key T2 just expired that this segment carries lands with no prior pointer, becoming a first-row insert → duplicate visible row.
   
   ## Fix
   
   Move the watermark bump to **after** `addSegment`/`doPreloadSegment`/`replaceSegment` returns, and wrap it in a `finally` block so a failed add still records the max we've seen. The out-of-TTL skip path bumps the watermark before returning as before, since it inserts no rows and cannot race with the sweep.
   
   Per-partition state transitions are serialized by Helix, so concurrent `doAddSegment` invocations on the same partition are not possible; the only concurrency here is with the sweep thread.
   
   ## Reproduction
   
   Reproduced with [`startreedata/theseus-upsert-verifier`](https://github.com/startreedata/theseus-upsert-verifier), a Hypothesis-driven model of Pinot upsert coordination. The `H015`-class duplicate visible row is triggered by restart → preload → offload → metadataTTL sweep interleavings and is confirmed closed by this change:
   
   ```
   uv run python simulate_handoff.py --preset restart --restarts 2 \
     --fix rocksdb-reuse --tasks --profile mttl-deletes --examples 5000
   ```
   
   Without this fix the verifier finds a P1v violation (`visible rows differ from the fold plus ghosts`) in ~42 s.
   
   ## Testing
   
   - Existing 56 upsert unit tests in `pinot-segment-local` pass unchanged (`ConcurrentMapPartitionUpsertMetadataManagerTest`, `BasePartitionUpsertMetadataManagerTest`, `ConcurrentMapPartitionUpsertMetadataManagerForConsistentDeletesTest`).
   - `spotless:apply`, `checkstyle:check`, `license:check` all clean on the affected module.
   
   An in-process regression test requires a testable seam to pause `addSegment` mid-call so the sweep can be raced against it deterministically; primary regression coverage lives in the theseus verifier above.
   
   ## Test plan
   - [ ] Existing `pinot-segment-local` upsert tests pass
   - [ ] Manual: verify a table with `metadataTTL` set has no duplicate rows across a restart + preload cycle


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] Defer TTL watermark bump until after segment add/preload/replace (upsert & dedup) [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #19512:
URL: https://github.com/apache/pinot/pull/19512#discussion_r3981503994


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/dedup/BasePartitionDedupMetadataManager.java:
##########
@@ -167,7 +167,11 @@ public void preloadSegment(ImmutableSegment segment) {
       return;
     }
     try {
-      if (skipSegmentOutOfTTL(segment, true)) {
+      // Bump watermark after doPreloadSegment; a concurrent removeExpiredPrimaryKeys sweep reading a pre-bumped
+      // watermark could expire keys this preload is about to insert. On the skip path no rows are added, so it is
+      // safe to bump before returning.
+      if (skipSegmentOutOfTTL(segment)) {
+        updateLargestSeenTime(segment);
         return;
       }
       try (DedupUtils.DedupRecordInfoReader dedupRecordInfoReader = new DedupUtils.DedupRecordInfoReader(segment,

Review Comment:
   (minor) Remove the previous check and put this in `if(!skipSegmentOutOfTTL(segment))` for better readability



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/dedup/BasePartitionDedupMetadataManager.java:
##########
@@ -203,8 +208,12 @@ public void addSegment(IndexSegment segment) {
       return;
     }
     try {
-      if (!skipSegmentOutOfTTL(segment, true)) {
+      // Bump watermark after add; see preloadSegment.
+      if (skipSegmentOutOfTTL(segment)) {
+        updateLargestSeenTime(segment);
+      } else {
         addOrReplaceSegment(null, segment);
+        updateLargestSeenTime(segment);
       }

Review Comment:
   (minor) Can be simplified, same for other places
   ```suggestion
         if (!skipSegmentOutOfTTL(segment)) {
           addOrReplaceSegment(null, segment);
         }
         updateLargestSeenTime(segment);
   ```



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] Defer TTL watermark bump until after segment add/preload/replace (upsert & dedup) [pinot]

Posted by "deepthi912 (via GitHub)" <gi...@apache.org>.
deepthi912 commented on PR #19512:
URL: https://github.com/apache/pinot/pull/19512#issuecomment-5628429578

   > Trying to understand why this race can even happen. When this race happens, it means the records within the same segment span over TTL. This itself is invalid, and undefined. I don't think we can fix it in any way. Imagine a segment is being added, in the meanwhile a consuming record pushes the watermark higher, and we run into the same problem. Also, why is an uploaded segment moving the watermark? Shouldn't it always be moved by consuming segment?
   
   Agree on the condition that is hard to fix across the replicas when uploaded segment comes in during consumption, there are lot more corner cases as I was fixing this. But this PR was mainly focussed on ensuring the watermark is updated after rocksdb updates rather than before during each record addition and segment replacement. 
   The reason why we are updating watermark for uploaded segment could be to make sure the watermark is not too advanced if there is over consumed or under consumed rows. The bug scope is narrow but I feel it is important that we update after the rocksdb updates than before.


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] Defer TTL watermark bump until after segment add/preload/replace (upsert & dedup) [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang merged PR #19512:
URL: https://github.com/apache/pinot/pull/19512


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] Defer TTL watermark bump until after segment add/preload/replace (upsert & dedup) [pinot]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #19512:
URL: https://github.com/apache/pinot/pull/19512#issuecomment-5593935283

   ## [Codecov](https://app.codecov.io/gh/apache/pinot/pull/19512?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `0%` with `28 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 57.77%. Comparing base ([`1f5b06c`](https://app.codecov.io/gh/apache/pinot/commit/1f5b06c600123f2954dbd466e58135044dba3288?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`0367b72`](https://app.codecov.io/gh/apache/pinot/commit/0367b7247cdc9c51d0cc634856a04ddf24a0f0fc?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 2 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/pinot/pull/19512?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...local/dedup/BasePartitionDedupMetadataManager.java](https://app.codecov.io/gh/apache/pinot/pull/19512?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Fdedup%2FBasePartitionDedupMetadataManager.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9kZWR1cC9CYXNlUGFydGl0aW9uRGVkdXBNZXRhZGF0YU1hbmFnZXIuamF2YQ==) | 0.00% | [14 Missing :warning: ](https://app.codecov.io/gh/apache/pinot/pull/19512?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...cal/upsert/BasePartitionUpsertMetadataManager.java](https://app.codecov.io/gh/apache/pinot/pull/19512?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Fupsert%2FBasePartitionUpsertMetadataManager.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC91cHNlcnQvQmFzZVBhcnRpdGlvblVwc2VydE1ldGFkYXRhTWFuYWdlci5qYXZh) | 0.00% | [14 Missing :warning: ](https://app.codecov.io/gh/apache/pinot/pull/19512?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   > :exclamation:  There is a different number of reports uploaded between BASE (1f5b06c) and HEAD (0367b72). Click for more details.
   > 
   > <details><summary>HEAD has 14 uploads less than BASE</summary>
   >
   >| Flag | BASE (1f5b06c) | HEAD (0367b72) |
   >|------|------|------|
   >|lane-a|2|1|
   >|integration|4|2|
   >|java-25|6|3|
   >|temurin|6|3|
   >|lane-b|2|1|
   >|unittests|2|1|
   >|integration1|2|0|
   >|unittests2|1|0|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #19512      +/-   ##
   ============================================
   - Coverage     67.73%   57.77%   -9.96%     
   + Complexity     1430        1    -1429     
   ============================================
     Files          3489     2688     -801     
     Lines        224637   164338   -60299     
     Branches      35468    26683    -8785     
   ============================================
   - Hits         152160    94954   -57206     
   - Misses        60454    61341     +887     
   + Partials      12023     8043    -3980     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/pinot/pull/19512/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [integration](https://app.codecov.io/gh/apache/pinot/pull/19512/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `0.00% <ø> (-100.00%)` | :arrow_down: |
   | [integration1](https://app.codecov.io/gh/apache/pinot/pull/19512/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [integration2](https://app.codecov.io/gh/apache/pinot/pull/19512/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `0.00% <ø> (ø)` | |
   | [java-25](https://app.codecov.io/gh/apache/pinot/pull/19512/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.77% <0.00%> (-9.96%)` | :arrow_down: |
   | [lane-a](https://app.codecov.io/gh/apache/pinot/pull/19512/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `0.00% <ø> (-100.00%)` | :arrow_down: |
   | [lane-b](https://app.codecov.io/gh/apache/pinot/pull/19512/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `0.00% <ø> (ø)` | |
   | [temurin](https://app.codecov.io/gh/apache/pinot/pull/19512/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.77% <0.00%> (-9.96%)` | :arrow_down: |
   | [unittests](https://app.codecov.io/gh/apache/pinot/pull/19512/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.78% <0.00%> (-9.96%)` | :arrow_down: |
   | [unittests1](https://app.codecov.io/gh/apache/pinot/pull/19512/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `57.78% <0.00%> (-0.01%)` | :arrow_down: |
   | [unittests2](https://app.codecov.io/gh/apache/pinot/pull/19512/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/pinot/pull/19512?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org