Skip to content

branch-4.1: [feature](cloud) Support file cache write index only#65268

Open
bobhan1 wants to merge 1 commit into
apache:branch-4.1from
bobhan1:codex/pick-64995-write-index-only-4.1
Open

branch-4.1: [feature](cloud) Support file cache write index only#65268
bobhan1 wants to merge 1 commit into
apache:branch-4.1from
bobhan1:codex/pick-64995-write-index-only-4.1

Conversation

@bobhan1

@bobhan1 bobhan1 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: N/A

Related PR: #64995

Problem Summary:

Pick master commit 73c481f65848ed5f449fad2ac9e7c59cf54bcf9e to branch-4.1 to support file cache write index only in cloud mode.

Adaptations for branch-4.1:

  • Keep the existing IndexFileWriter constructor shape on branch-4.1.
  • Drop the unused master-only row_binlog_segment_writer.h include.

Validation note:

Release note

Support file cache write index only in cloud mode.

Check List (For Author)

  • Test
    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason

Manual test:

  • git diff --check upstream/branch-4.1...HEAD

  • ./run-be-ut.sh --run --filter=CloudFileCacheWriteIndexOnly* -j100

  • ./build.sh --be --fe --cloud -j100

  • docker build -f docker/runtime/doris-compose/Dockerfile -t bh-cluster-2 .

  • ./run-regression-test.sh --run -d regression-test/suites/cloud_p0/cache/write_index_only -g docker -runMode=cloud -dockerSuiteParallel 1

  • Behavior changed:

    • No.
    • Yes. Support file cache write index only in cloud mode.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

This PR adds a new BE config, `enable_file_cache_write_index_file_only`, to make cloud rowset writes and compaction outputs write only index-related content into file cache. This avoids actively putting segment data into file cache during write, reducing cache pollution from large data pages.

The main target scenario is a limited local cache where query performance should prioritize indexes and segment metadata. With this mode enabled, the write path protects inverted index files and segment index/footer ranges, while normal data pages are still loaded and cached by the query read path when needed.

- Add BE config `enable_file_cache_write_index_file_only`, default `false`.
- Make rowset/segment file-cache write decisions file-type aware:
  - `SEGMENT_FILE` does not create a full-file cache builder and does not allow adaptive write in index-only mode.
  - `INVERTED_INDEX_FILE` is still written into file cache through the direct write path.
  - segment index/footer ranges are preloaded into file cache by `SegmentIndexFileCacheLoader` after segment close.
- Update packed file handling to honor the original file type when deciding whether to write file cache.
- Add profile statistics for segment footer/index reads and separate them from data-page and inverted-index reads.
- Replace correlated boolean parameters in `CachedRemoteFileReader::_update_stats` with a read-type enum:
  - data page
  - inverted index
  - segment footer/index
- Add BE UTs and cloud regressions for both normal file and packed file paths.

When `enable_file_cache_write_index_file_only=true`:

- Segment data is not actively written into file cache during write, flush, or compaction output.
- Segment index/footer ranges are synchronously preloaded into file cache after segment close.
- Independent inverted index files are written into file cache through the direct write path.
- Query-side data-page reads keep the existing behavior. The query read path may still fill cache according to current rules.
- Segment open, footer/index access, and inverted index access can hit the index-related content preloaded by the write path.
- Query profile exposes separate cache/remote read statistics for data pages, inverted indexes, and segment footer/index reads.

The write-side file-cache behavior is decided in this order:

1. `enable_file_cache=false` is the highest-priority global switch.
   - All file-cache writes are disabled.
   - This includes independent inverted index direct cache and segment index/footer preload.

2. `enable_file_cache=true` and `enable_file_cache_write_index_file_only=true` enables global forced index-only mode.
   - Segment data does not create a full-file cache builder.
   - Segment data cannot be written by adaptive write.
   - Segment index/footer ranges are written into file cache by `SegmentIndexFileCacheLoader` after segment close.
   - Independent inverted index files are written through the `INVERTED_INDEX_FILE` direct write path.
   - This config has higher priority than `enable_file_cache_write_base_compaction_index_only` and `enable_file_cache_write_cumu_compaction_index_only`.
   - These index writes do not depend on `enable_file_cache_adaptive_write`, compaction keep configs, hit-ratio thresholds, or request/session `write_file_cache`.

3. `enable_file_cache=true`, `enable_file_cache_write_index_file_only=false`, and a compaction-level index-only config is enabled applies index-only behavior only to the matching compaction output.
   - `enable_file_cache_write_base_compaction_index_only=true` only forces base compaction output to use index-only file-cache writes.
   - `enable_file_cache_write_cumu_compaction_index_only=true` only forces cumulative compaction output to use index-only file-cache writes.
   - These two configs do not affect load, normal flush, schema change output, or query read-path cache fill.
   - Compaction types not matched by these configs continue to use existing `write_file_cache`, adaptive write, compaction keep, and hit-ratio decisions.

4. `enable_file_cache=true` and all three index-only configs are `false` preserves existing behavior.
   - `write_file_cache`, `enable_file_cache_adaptive_write`, compaction keep configs, schema-change hit ratios, and existing rowset/file-writer decisions continue to control whether cache is written.

- When index-only is disabled, `enable_file_cache_adaptive_write=true` keeps the existing adaptive write behavior. Segment data may be written into file cache if the cache-space check passes.
- When index-only is enabled, adaptive write no longer participates in segment data decisions.
- Even if `enable_file_cache_adaptive_write=true`, segment data is still not written into file cache, while segment index/footer and independent inverted index files are still written.

Related configs include:

- `enable_file_cache_keep_base_compaction_output`
- `file_cache_keep_base_compaction_output_min_hit_ratio`
- compaction output hit-ratio checks

When index-only is disabled, existing compaction output cache behavior is preserved.

When index-only is enabled, compaction output is forced into index-only behavior:

- Compaction output segment data is not actively written into file cache.
- Segment index/footer ranges are synchronously written into file cache.
- Independent inverted index files are direct-cached.
- Compaction keep configs and hit-ratio thresholds no longer decide whether index content is written into file cache.

Related configs include:

- `enable_file_cache_write_base_compaction_index_only`
- `enable_file_cache_write_cumu_compaction_index_only`

These two configs are narrower compaction-output policies and only take effect when `enable_file_cache_write_index_file_only=false`.

- When `enable_file_cache_write_base_compaction_index_only=true`, base compaction output uses index-only behavior: output segment data is not actively cached, while output segment index/footer ranges and independent inverted index files are written into file cache.
- When `enable_file_cache_write_cumu_compaction_index_only=true`, cumulative compaction output uses index-only behavior: output segment data is not actively cached, while output segment index/footer ranges and independent inverted index files are written into file cache.
- If only one of the two configs is enabled, the other compaction type keeps the existing cache-write decision flow.
- If `enable_file_cache_write_index_file_only=true`, the global index-only config takes precedence and the base/cumulative compaction-specific configs no longer change the final behavior.
- `enable_file_cache=false` is still the highest-priority switch and disables all of these file-cache writes.

- When index-only is disabled, `file_cache_keep_schema_change_output_min_hit_ratio` keeps its existing semantics.
- When index-only is enabled, schema change output also follows index-only behavior:
  - segment data is not actively written into file cache;
  - index-related content is written into file cache;
  - schema-change hit-ratio thresholds no longer decide whether index content is cached.

- `enable_file_cache=false` disables everything and has the highest priority.
- When index-only is enabled, the BE config has higher priority than request/session `write_file_cache=false`.
- Even if session `disable_file_cache=true` makes request-side `write_file_cache=false`, as long as BE `enable_file_cache=true` and index-only is enabled:
  - index-related content is still written into file cache;
  - segment data is still not written into file cache.
- When index-only is disabled, `disable_file_cache=true` preserves existing behavior and load output does not actively write file cache.

- When index-only is disabled, packed small files keep the existing whole-file cache behavior.
- When index-only is enabled:
  - packed small segment files must not be whole-file cached, preventing segment data from entering file cache;
  - segment index/footer ranges are written into file cache by `SegmentIndexFileCacheLoader`;
  - packed independent index small files are independent index files and can be whole-file cached.

- Segment index/footer ranges are written through synchronous dry-run reads and do not depend on write-path `enable_flush_file_cache_async`.
- Independent inverted index files still use the direct write path, so they continue to follow existing async flush behavior.

`SegmentIndexFileCacheLoader` marks index-related reads as index data so that they go to the `FileCacheType::INDEX` queue when possible.

After enabling index-only mode, `index_percent` should be reviewed based on index size. The default `index_percent=5` may be insufficient for large indexes.

| Scenario | index-only=false | index-only=true |
| --- | --- | --- |
| load segment data | follows existing cache policy | not actively cached |
| load segment index/footer | depends on existing whole-file cache or read path | synchronously range-read into file cache after segment close |
| load independent inverted index file | follows existing cache policy | direct-cached by write path |
| cumulative compaction segment data | may be cached by existing behavior | not actively cached |
| cumulative compaction segment index/footer | may be cached by existing behavior | synchronously range-read into file cache after segment close |
| base compaction force-keep output | whole output rowset may be cached | only output segment index/footer is preloaded |
| adaptive write has enough space | segment data may be cached | segment data is still not cached |
| packed small index file | may be cached | can be whole-file cached |
| packed small segment file | may be cached | not whole-file cached; internal index/footer is preloaded |
| query read fill cache | unchanged | unchanged |
| event-driven warm-up | unchanged | unchanged |

Add BE config `enable_file_cache_write_index_file_only` to support index-only file-cache writes for cloud rowset writes and compaction outputs.

(cherry picked from commit 73c481f)
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@bobhan1 bobhan1 changed the title [feature](cloud) Support file cache write index only branch-4.1: [feature](cloud) Support file cache write index only Jul 6, 2026
@bobhan1 bobhan1 marked this pull request as ready for review July 6, 2026 10:43
@bobhan1 bobhan1 requested a review from yiguolei as a code owner July 6, 2026 10:43
@bobhan1

bobhan1 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100% (0/0) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.89% (27626/37390)
Line Coverage 57.51% (299691/521151)
Region Coverage 55.18% (251660/456093)
Branch Coverage 56.48% (108860/192737)

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