Skip to content

Fix/min folder occupied space cache - #17996

Merged
jt2594838 merged 2 commits into
apache:masterfrom
hongzhi-gao:fix/min-folder-occupied-space-cache
Jun 22, 2026
Merged

jt2594838 merged 2 commits into
apache:masterfrom
hongzhi-gao:fix/min-folder-occupied-space-cache

Conversation

@hongzhi-gao

Copy link
Copy Markdown
Contributor

Description

Cache Refresh Configuration

This PR makes the occupied-space cache refresh policy in MinFolderOccupiedSpaceFirstStrategy configurable instead of hardcoding 60s and 1000 selections.

Configuration Loading

Two common config items are added with positive-value validation:

  • min_folder_occupied_space_cache_refresh_interval_ms
  • min_folder_occupied_space_cache_refresh_selection_threshold

Invalid non-positive values are ignored and the defaults are kept.

Tests

Added real-filesystem coverage for the occupied-space cache behavior and updated existing strategy tests.


This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths.
  • added integration tests.

Key changed/added classes (or packages if there are too many classes) in this PR
  • MinFolderOccupiedSpaceFirstStrategy
  • CommonConfig
  • CommonDescriptor
  • iotdb-system.properties.template

…rategy

MinFolderOccupiedSpaceFirstStrategy recomputed every folder's occupied
space via a full Files.walk on every folder selection. While receiving a
snapshot made of hundreds of thousands of tiny files, this turned each
per-file allocation into a full directory-tree scan, making the cost
quadratic. addPeer stalled (observed ~1 file / 4-5s) and syncLag stayed
high.

Cache the occupied space per folder and only recompute it periodically:
an incremental selection counter is kept and, once a count threshold or a
time interval is reached, the cached state is reset and the occupied
space is recomputed. Selection semantics (pick the least occupied folder)
are preserved while the number of full directory scans is bounded.

Add a mocked unit test (DirectoryStrategyTest) and a real-filesystem
integration test (MinFolderOccupiedSpaceFirstStrategyRealFsTest) covering
the caching, the count-based refresh and the reset.
@jt2594838
jt2594838 merged commit ae7a5de into apache:master Jun 22, 2026
39 of 40 checks passed
MileaRobertStefan pushed a commit to MileaRobertStefan/iotdb that referenced this pull request Jun 26, 2026
* fix(consensus): cache occupied space in MinFolderOccupiedSpaceFirstStrategy

MinFolderOccupiedSpaceFirstStrategy recomputed every folder's occupied
space via a full Files.walk on every folder selection. While receiving a
snapshot made of hundreds of thousands of tiny files, this turned each
per-file allocation into a full directory-tree scan, making the cost
quadratic. addPeer stalled (observed ~1 file / 4-5s) and syncLag stayed
high.

Cache the occupied space per folder and only recompute it periodically:
an incremental selection counter is kept and, once a count threshold or a
time interval is reached, the cached state is reset and the occupied
space is recomputed. Selection semantics (pick the least occupied folder)
are preserved while the number of full directory scans is bounded.

Add a mocked unit test (DirectoryStrategyTest) and a real-filesystem
integration test (MinFolderOccupiedSpaceFirstStrategyRealFsTest) covering
the caching, the count-based refresh and the reset.

* fix(consensus): make occupied space cache refresh configurable
JackieTien97 pushed a commit that referenced this pull request Jun 29, 2026
* fix(consensus): cache occupied space in MinFolderOccupiedSpaceFirstStrategy

MinFolderOccupiedSpaceFirstStrategy recomputed every folder's occupied
space via a full Files.walk on every folder selection. While receiving a
snapshot made of hundreds of thousands of tiny files, this turned each
per-file allocation into a full directory-tree scan, making the cost
quadratic. addPeer stalled (observed ~1 file / 4-5s) and syncLag stayed
high.

Cache the occupied space per folder and only recompute it periodically:
an incremental selection counter is kept and, once a count threshold or a
time interval is reached, the cached state is reset and the occupied
space is recomputed. Selection semantics (pick the least occupied folder)
are preserved while the number of full directory scans is bounded.

Add a mocked unit test (DirectoryStrategyTest) and a real-filesystem
integration test (MinFolderOccupiedSpaceFirstStrategyRealFsTest) covering
the caching, the count-based refresh and the reset.

* fix(consensus): make occupied space cache refresh configurable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants