You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "dkranchii (via GitHub)" <gi...@apache.org> on 2026/10/18 15:04:13 UTC

[PR] Close the posting list stream in OffHeapJsonIndexCreator.close() [pinot]

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

   `OffHeapJsonIndexCreator` opens the posting list output stream in its constructor but closes it only in `seal()`. The inherited `BaseJsonIndexCreator.close()` just deletes the temp directory, so when `add()` throws (for example on a malformed json record with `continueOnError` disabled) `seal()` is never reached and the file descriptor leaks for the lifetime of the JVM.
   This overrides `close()` to close the stream and then delegate to `super.close()`, mirroring the existing `OffHeapH3IndexCreator.close()`. Closing a `DataOutputStream` twice is a no-op, so the normal `seal()`-then-`close()` path is unaffected.
   ### Testing
   Added `JsonIndexTest#testOffHeapCreatorCloseWithoutSeal`, covering close-after-failed-add (temp directory cleaned up, repeated `close()` safe) and the normal seal-then-close path.
   ### Compatibility
   No config, API, or on-disk format change.


-- 
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] Close the posting list stream in OffHeapJsonIndexCreator.close() [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #19925:
URL: https://github.com/apache/pinot/pull/19925#discussion_r4309189821


##########
pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/JsonIndexTest.java:
##########
@@ -1104,6 +1104,37 @@ public void testSkipInvalidJsonDisabledContinueOnErrorFalse() throws Exception {
     createIndex(true, jsonIndexConfig, records);
   }
 
+  /// The off-heap creator opens the posting list stream in the constructor, but seal() is never reached when add()
+  /// fails. close() must still release the stream and clean up the temp directory, and must stay idempotent so that
+  /// the normal seal()-then-close() path keeps working.
+  @Test
+  public void testOffHeapCreatorCloseWithoutSeal()
+      throws Exception {
+    String columnName = "offHeapUnsealed";

Review Comment:
   **MAJOR (test quality): this test does not actually verify the leak fix.** Every assertion here passes even if the production `close()` override is removed, so it is not a regression guard for the leaked file descriptor.
   
   Walking it with the fix reverted:
   - `assertThrows(JsonProcessingException.class, ...)` is pure `add()`/`flatten()` behavior, independent of `close()`.
   - `assertFalse(tempDir.exists())` passes because base `BaseJsonIndexCreator.close()` calls `FileUtils.deleteDirectory(_tempDir)`.
   - The second `creator.close()` passes because `deleteDirectory` on a missing dir returns silently (idempotent).
   - The sealed-creator path is untouched by the override.
   
   Nothing asserts that `_postingListOutputStream` was closed / the FD released — which is the exact regression this test claims to cover. Consider asserting the stream/FD state directly (e.g. spy or wrap the output stream and verify `close()` was invoked, or assert the underlying channel is no longer open) so the test fails when the override is absent.



-- 
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] Close the posting list stream in OffHeapJsonIndexCreator.close() [pinot]

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

   probe


-- 
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] Close the posting list stream in OffHeapJsonIndexCreator.close() [pinot]

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

   ## [Codecov](https://app.codecov.io/gh/apache/pinot/pull/19925?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 100.00%. Comparing base ([`9de9e01`](https://app.codecov.io/gh/apache/pinot/commit/9de9e01155450a2a416ba8a6b0fcfc60b0bb8782?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`bc36484`](https://app.codecov.io/gh/apache/pinot/commit/bc36484e6c0c8920472b3ebfac0869a4acb267b6?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@              Coverage Diff               @@
   ##             master    #19925       +/-   ##
   ==============================================
   + Coverage     69.52%   100.00%   +30.47%     
   + Complexity     1491         6     -1485     
   ==============================================
     Files          3546         3     -3543     
     Lines        234250         6   -234244     
     Branches      37521         0    -37521     
   ==============================================
   - Hits         162868         6   -162862     
   + Misses        58816         0    -58816     
   + Partials      12566         0    -12566     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/pinot/pull/19925/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/19925/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `100.00% <ø> (ø)` | |
   | [integration1](https://app.codecov.io/gh/apache/pinot/pull/19925/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `100.00% <ø> (ø)` | |
   | [integration2](https://app.codecov.io/gh/apache/pinot/pull/19925/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [java-25](https://app.codecov.io/gh/apache/pinot/pull/19925/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `100.00% <ø> (+30.47%)` | :arrow_up: |
   | [lane-a](https://app.codecov.io/gh/apache/pinot/pull/19925/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `100.00% <ø> (ø)` | |
   | [lane-b](https://app.codecov.io/gh/apache/pinot/pull/19925/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/19925/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `100.00% <ø> (+30.47%)` | :arrow_up: |
   | [unittests](https://app.codecov.io/gh/apache/pinot/pull/19925/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unittests1](https://app.codecov.io/gh/apache/pinot/pull/19925/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unittests2](https://app.codecov.io/gh/apache/pinot/pull/19925/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/19925?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


Re: [PR] Close the posting list stream in OffHeapJsonIndexCreator.close() [pinot]

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


-- 
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] Close the posting list stream in OffHeapJsonIndexCreator.close() [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #19925:
URL: https://github.com/apache/pinot/pull/19925#discussion_r4344735217


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/inv/json/OffHeapJsonIndexCreator.java:
##########
@@ -74,7 +74,18 @@ public OffHeapJsonIndexCreator(File indexDir, String columnName, String tableNam
       throws IOException {
     super(indexDir, columnName, tableNameWithType, continueOnError, jsonIndexConfig);
     _postingListFile = new File(_tempDir, POSTING_LIST_FILE_NAME);
-    _postingListOutputStream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(_postingListFile)));
+    try {

Review Comment:
   Nit: `catch (Throwable t)` is broad — it'll also catch things like `OutOfMemoryError`. That's arguably fine for cleanup-and-rethrow, but `catch (Exception | Error t)` or just `catch (IOException t)` (the only checked type `FileOutputStream` throws) would be a touch more conventional here. Not blocking.



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/inv/json/OffHeapJsonIndexCreator.java:
##########
@@ -74,7 +74,18 @@ public OffHeapJsonIndexCreator(File indexDir, String columnName, String tableNam
       throws IOException {
     super(indexDir, columnName, tableNameWithType, continueOnError, jsonIndexConfig);
     _postingListFile = new File(_tempDir, POSTING_LIST_FILE_NAME);
-    _postingListOutputStream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(_postingListFile)));
+    try {
+      _postingListOutputStream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(_postingListFile)));
+    } catch (Throwable t) {
+      // The base constructor already created the temp dir, but a failure here leaves the caller without an instance to
+      // close, so the temp dir has to be cleaned up here. Call super.close() because close() dereferences the stream.
+      try {

Review Comment:
   Tiny wording nit: "Call super.close() because close() dereferences the stream" reads a bit ambiguously. The real point is that `this.close()` (the override below) would NPE here since the final field is still unassigned, so we deliberately call the base `super.close()` which only cleans the temp dir. Maybe "call super.close() instead of this.close(), which would NPE on the unassigned stream."



-- 
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] Close the posting list stream in OffHeapJsonIndexCreator.close() [pinot]

Posted by "dkranchii (via GitHub)" <gi...@apache.org>.
dkranchii commented on code in PR #19925:
URL: https://github.com/apache/pinot/pull/19925#discussion_r4318057422


##########
pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/JsonIndexTest.java:
##########
@@ -1104,6 +1104,37 @@ public void testSkipInvalidJsonDisabledContinueOnErrorFalse() throws Exception {
     createIndex(true, jsonIndexConfig, records);
   }
 
+  /// The off-heap creator opens the posting list stream in the constructor, but seal() is never reached when add()
+  /// fails. close() must still release the stream and clean up the temp directory, and must stay idempotent so that
+  /// the normal seal()-then-close() path keeps working.
+  @Test
+  public void testOffHeapCreatorCloseWithoutSeal()
+      throws Exception {
+    String columnName = "offHeapUnsealed";

Review Comment:
   @xiangfu0 Good catch. My checkout still had target/classes from a build predating this change (no close() override), so I ran the test logic against both the un-fixed and fixed class — against the un-fixed one every assertion passed, exactly as you described.
   
   The test now probes the stream directly. Reflection is needed because the field is private, and a flush() is needed because the buffering layer accepts writes without touching the file descriptor, so writing alone would pass on a closed stream. The new assertFalse(isPostingListStreamOpen(creator)) fails against the un-fixed class and passes against the fixed one. I also added an assertTrue positive control before close() so the post-close assertion can't pass just because the probe is broken.
   
   One caveat: the sealed-creator assertion is not a regression guard, since seal() closes the stream either way. It only catches a double-close regression on the happy path.
   
   Took both minor notes too. Reworded the comment that overstated the JDK guarantee, and added a constructor try/catch so a failure opening the stream cleans up the temp dir — it calls super.close() because the override dereferences the not-yet-assigned stream, and suppresses cleanup failures so they can't mask the original exception. That path has its own test, which also fails pre-fix and passes post-fix.



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