You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "Jackie-Jiang (via GitHub)" <gi...@apache.org> on 2026/09/16 22:06:15 UTC

[PR] Tolerate concurrent deletes when sizing consumer and segment directories [pinot]

Jackie-Jiang opened a new pull request, #19580:
URL: https://github.com/apache/pinot/pull/19580

   ## Summary
   
   `FileUtils.sizeOfDirectory` in commons-io 2.12+ walks with NIO's `FileTreeWalker`, which lists a directory and then stats each entry. If an entry disappears in between, the whole walk aborts with an `UncheckedIOException`. Pinot moved from commons-io 2.11 to 2.22 in #18308, so this now bites every site that sizes a directory another thread is writing to. Two production sites do:
   
   - **`REALTIME_CONSUMER_DIR_USAGE` gauge** in `BaseServerStarter`: walks each realtime table's consumer directory on every metrics scrape. The mutable Lucene text index in there flushes many times per second, creating and deleting `*.tmp` files, so scrapes intermittently log this WARN and the gauge reports `-1`:
   
     ```
     WARN [BaseServerStarter] Failed to gather size info for consumer directories
     java.io.UncheckedIOException: java.nio.file.NoSuchFileException: .../consumers/<segment>/<column>.lucene.v912.index/_zh6_Lucene90FieldsIndexfile_pointers_1yyd.tmp
     ```
   
   - **`SegmentLocalFSDirectory.getDiskSizeBytes`**: walks the loaded segment's directory, which a concurrent reload rewrites in place (index handlers delete old index files, write `.inprogress` markers and temp files, and force-delete the text index directory). The method only caught `IllegalArgumentException`, the pre-2.12 failure type, so the `UncheckedIOException` escapes and fails the whole `/tables/{table}/size` call. The controller's `TableSizeReader` then treats every segment on that server as missing for that round.
   
   This PR adds `org.apache.pinot.common.utils.FileUtils.sizeOfDirectory(File)`: a `listFiles()` / `length()` recursion whose primitives report a concurrently deleted entry as `null` / `0` instead of throwing. It is the implementation commons-io itself used through 2.11, plus a symlink skip. Both sites switch to it, and the now-dead `IllegalArgumentException` catch in `getDiskSizeBytes` is removed.
   
   The util's Javadoc states when to use it: a directory another thread may be writing to. The remaining commons-io `sizeOfDirectory` / `sizeOf` callers all size directories the same thread has just finished producing (segment builds, minion tasks, untarred uploads), where a genuine I/O error should surface, so they intentionally stay on commons-io.
   
   🤖 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: 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] Tolerate concurrent deletes when sizing consumer and segment directories [pinot]

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

   ## [Codecov](https://app.codecov.io/gh/apache/pinot/pull/19580?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 ([`3b760ad`](https://app.codecov.io/gh/apache/pinot/commit/3b760adb71a91dfad56de242a5b3803823f3311b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`db0944c`](https://app.codecov.io/gh/apache/pinot/commit/db0944c548102fe7e23ef15daf1aa57a3208458f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 1 commits behind head on master.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@              Coverage Diff               @@
   ##             master    #19580       +/-   ##
   ==============================================
   + Coverage     57.89%   100.00%   +42.10%     
   + Complexity        7         6        -1     
   ==============================================
     Files          2692         3     -2689     
     Lines        164895         6   -164889     
     Branches      26787         0    -26787     
   ==============================================
   - Hits          95459         6    -95453     
   + Misses        61378         0    -61378     
   + Partials       8058         0     -8058     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/pinot/pull/19580/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/19580/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/19580/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/19580/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/19580/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `100.00% <ø> (+42.10%)` | :arrow_up: |
   | [lane-a](https://app.codecov.io/gh/apache/pinot/pull/19580/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/19580/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/19580/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `100.00% <ø> (+42.10%)` | :arrow_up: |
   | [unittests](https://app.codecov.io/gh/apache/pinot/pull/19580/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/19580/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/19580?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] Tolerate concurrent deletes when sizing consumer and segment directories [pinot]

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


-- 
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] Tolerate concurrent deletes when sizing consumer and segment directories [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/store/SegmentLocalFSDirectory.java:
##########
@@ -182,12 +182,8 @@ public long getDiskSizeBytes() {
 
     // check that v3 subdirectory exists since the format may not have been converted
     if (_segmentDirectory != null && _segmentDirectory.exists()) {
-      try {
-        return FileUtils.sizeOfDirectory(_segmentDirectory.toPath().toFile());
-      } catch (IllegalArgumentException e) {
-        LOGGER.error("Failed to read disk size for directory: {}", _segmentDirectory.getAbsolutePath());
-        return -1;
-      }
+      // A concurrent reload may be rewriting this directory in place, so use the delete-tolerant walk.
+      return org.apache.pinot.common.utils.FileUtils.sizeOfDirectory(_segmentDirectory);

Review Comment:
   Is this the only usage? shall we also banned the `org.apache.commons.io.FileUtils.sizeOfDirectory` usage from checkstyle?



-- 
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] Tolerate concurrent deletes when sizing consumer and segment directories [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/store/SegmentLocalFSDirectory.java:
##########
@@ -182,12 +182,8 @@ public long getDiskSizeBytes() {
 
     // check that v3 subdirectory exists since the format may not have been converted
     if (_segmentDirectory != null && _segmentDirectory.exists()) {
-      try {
-        return FileUtils.sizeOfDirectory(_segmentDirectory.toPath().toFile());
-      } catch (IllegalArgumentException e) {
-        LOGGER.error("Failed to read disk size for directory: {}", _segmentDirectory.getAbsolutePath());
-        return -1;
-      }
+      // A concurrent reload may be rewriting this directory in place, so use the delete-tolerant walk.
+      return org.apache.pinot.common.utils.FileUtils.sizeOfDirectory(_segmentDirectory);

Review Comment:
   Not the only one. There are 12 other directory-sizing calls in main code, all on directories the calling thread has just finished producing, so nothing can race with the walk:
   - `RealtimeSegmentDataManager` and `SegmentProcessorFramework`: the segment just built
   - `BaseTaskExecutor` (x2) and the segment-generation runners (`SegmentGenerationAndPushTaskExecutor`, standalone / Hadoop / Spark job runners): the minion's local copy before/after the task
   - `PinotSegmentUploadDownloadRestletResource`: the untarred upload in a temp dir
   - `PredownloadSegmentInfo`: the local segment at startup, before Helix participation
   - `MemoryEstimator` and `SegmentSizeRule`: the recommender's sample segment
   
   I left those on commons-io on purpose. The tolerant walk trades a genuine I/O error for a silent `0`. That is the right trade for a gauge or a REST call racing a writer, but not for a size about to be recorded in ZK metadata or a task metric for a directory nobody else touches. The util's Javadoc spells out the criterion (another thread may be writing to it) so the next site can pick correctly.
   
   So I'd rather not ban it. Two mechanical reasons on top of the semantic one:
   - A third of the remaining calls go through `FileUtils.sizeOf(File)`, the file-or-directory overload, so a `sizeOfDirectory` ban would miss them, and a `sizeOf` ban would also catch the legitimate tar-file `sizeOf` calls right next to them.
   - The only lever in the build is a `RegexpSingleline` rule (no forbidden-apis plugin), which can't tell the commons-io call from the pinot-common method of the same name unless every caller of ours uses the fully qualified form.
   
   If you'd rather have one rule anyway, I'm happy to do the blanket migration of those 12 sites in a follow-up.
   



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