Skip to content

[opt](lance) add session cache and data cache in lance - #67650

Open
zhangstar333 wants to merge 12 commits into
apache:branch-4.1from
zhangstar333:lance_memory
Open

zhangstar333 wants to merge 12 commits into
apache:branch-4.1from
zhangstar333:lance_memory

Conversation

@zhangstar333

@zhangstar333 zhangstar333 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Problem Summary:
doc: apache/doris-website#4126
add session cache and data cache in lance

Release note

None

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
  • Behavior changed:

    • No.
    • Yes.
  • 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

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

@zhangstar333 zhangstar333 changed the title Lance memory [opt](lance) add session cache and data cache in lance Sep 9, 2026
@zhangstar333
zhangstar333 marked this pull request as ready for review September 9, 2026 11:56
@zhangstar333

Copy link
Copy Markdown
Contributor Author

/review

1 similar comment
@zhangstar333

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: Codex completed, but no new pull request review was submitted for the current head SHA.
Workflow run: https://github.com/apache/doris/actions/runs/34348226808

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for seven P1 correctness, availability, and compatibility issues on head 8283a0ce9bfe4ca0b9481ade499041fdb14a3cc7.

Cache/session correctness: the default-on Foyer path can return truncated cache hits, its persistent namespace can collide across distinct S3-compatible endpoints, a cache-only initialization failure permanently gates every Lance read, and the pinned Lance v11 URI-scoped metadata cache can reuse stable-row-ID state across dataset generations.

FE/BE and metadata compatibility: ordinary scalar-segment plans emitted by a new FE are rejected by a base-version BE, while optional scalar-index discovery has become a hard dependency of schema discovery and ordinary scans.

Third-party repeatability: an existing generic patched_mark skips this revision's expanded Lance patch chain on a retained source tree.

Final checkpoint sweep covered all 32 authoritative changed paths and the required reader lifecycle, schema/identity, predicate/delete/fallback, COUNT/LIMIT/OFFSET, vector/FTS, lazy materialization, ABI/pin, and clean/incremental patch-build contracts. Two independent convergence rounds completed; the second round produced no new valuable findings. No additional user focus was specified. Per the review instructions, no build was run.

Comment thread be/src/format_v2/lance/lance_session_manager.cpp
Comment thread be/src/format_v2/table/lance_reader.cpp
Comment thread be/src/common/config.cpp
Comment thread be/src/format_v2/lance/lance_session_manager.cpp
Comment thread thirdparty/download-thirdparty.sh
@zhangstar333

Copy link
Copy Markdown
Contributor Author

run buildall

Comment thread be/src/format_v2/lance/lance_session_manager.cpp
@hello-stephen

Copy link
Copy Markdown
Contributor

Cloud UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 78.36% (1948/2486)
Line Coverage 65.00% (34709/53395)
Region Coverage 52.47% (33283/63438)
Branch Coverage 55.19% (10243/18560)

@Gabriel39

Copy link
Copy Markdown
Contributor

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor

/review

@github-actions

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: Codex completed, but no new pull request review was submitted for the current head SHA.
Workflow run: https://github.com/apache/doris/actions/runs/34486064069

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

@Gabriel39

Copy link
Copy Markdown
Contributor

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor

/review

@hello-stephen

Copy link
Copy Markdown
Contributor

Cloud UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.17% (1819/2486)
Line Coverage 60.96% (32552/53395)
Region Coverage 48.47% (30749/63438)
Branch Coverage 51.39% (9538/18560)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the complete 36-file authoritative diff at head 4db7c2372f1098eda589f37ca4fe2e04fd080a6b, including the shared Lance session/cache, scalar/vector/FTS planning and execution, metadata/snapshot paths, Nereids lazy materialization, Thrift compatibility, all six Lance-C patches, platform/build glue, and tests. Existing inline threads were treated as hard duplicate fences; the user focus contained no additional scope.

Requesting changes for three newly identified issues:

  • A pushed filter that cannot drive the chosen physical scalar segment can collapse a fragment-parallel scan into one full scan on one BE.
  • Per-dataset cache counters are not published until dataset close, leaving active and error-exit profiles stale.
  • The new Remote cache counter records logical miss bytes, excludes aligned read amplification, and also counts local origins.

Validation was static only because this review runner explicitly prohibits builds/tests. Observed CI at submission preparation: third-party Linux/macOS/macOS-arm64 builds, third-party script test, Cloud UT, formatting, licensing, dependency review, and related checks pass; compile, FE UT, and BE UT remain pending. No checkout-local code-review SKILL.md was discoverable after a full repository search, so the review followed the explicit prompt, required AGENTS.md files, and mandatory scanner-v2 design/review guides.

LanceIndexSegmentInfo index = segments.get(0);
if ((index.getIndexType() != IndexType.BTREE && index.getIndexType() != IndexType.BITMAP
&& index.getIndexType() != IndexType.LABEL_LIST)
|| index.getFieldIds().size() != 1 || !filterFields.contains(index.getFieldIds().get(0))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Only create a segment split when the pushed filter can actually drive this index. This check accepts any pushed expression that mentions the field, but Doris pushes predicates such as !=, NOT IN, and IS NOT NULL that Lance v11 represents as Not(Query); PR #79's driver() only descends Query/And. It then reports no_driver after disabling ordinary scalar indexes and full-scans the segment's entire fragment domain. With the common single segment covering many fragments, this turns the previous fragment-parallel scan into one unsplittable full scan on one BE. Please align FE eligibility with the typed Lance planner, or retain fragment/global-index planning whenever a driver is not guaranteed.

ADD_CHILD_COUNTER_WITH_LEVEL(_scanner_profile, "LanceDataCacheBytesReadFromCache",
TUnit::BYTES, LANCE_READER_PROFILE, 1);
_data_cache_bytes_read_from_remote =
ADD_CHILD_COUNTER_WITH_LEVEL(_scanner_profile, "LanceDataCacheBytesReadFromRemote",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Do not expose this logical miss counter as remote I/O bytes. The C ABI says bytes_read_from_remote counts requested bytes returned after a miss and excludes block-aligned amplification; cached_ranges() can fetch a full 1 MiB block for a tiny range while incrementing only the tiny range. The same field is also incremented for local origins. This profile value therefore understates physical reads and misattributes local I/O as remote. Please name it as logical origin/miss bytes, and separately publish actual aligned origin bytes/requests with the real source attribution.

_fts_query_context = nullptr;
}
if (_dataset != nullptr) {
_collect_data_cache_statistics();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Refresh these counters at scan batch boundaries. This is the only call to _collect_data_cache_statistics(), and _close_dataset() normally runs only when the reader closes (the same dataset can also span several splits). Every successful batch, intermediate split, cancellation, and scanner/conversion error therefore leaves the new cache counters at zero until the query is already tearing down, contrary to the scanner-v2 requirement that child statistics be visible for in-progress scans. Please sample the cumulative dataset snapshot on each get_block() exit, including EOF/error paths, while retaining the close-time refresh.

@zhangstar333
zhangstar333 force-pushed the lance_memory branch 3 times, most recently from 8347f2d to 7312a9c Compare September 16, 2026 06:48
@zhangstar333

Copy link
Copy Markdown
Contributor Author

run buildall

1 similar comment
@zhangstar333

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 50.00% (151/302) 🎉
Increment coverage report
Complete coverage report

@Gabriel39

Copy link
Copy Markdown
Contributor

/review

yiguolei
yiguolei previously approved these changes Sep 16, 2026
@zhangstar333

Copy link
Copy Markdown
Contributor Author

run buildall

@zhangstar333

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 82.25% (190/231) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 74.36% (31430/42265)
Line Coverage 58.64% (350477/597628)
Region Coverage 55.35% (292412/528286)
Branch Coverage 56.21% (131969/234773)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 38.17% (121/317) 🎉
Increment coverage report
Complete coverage report

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.

4 participants