Skip to content

[C++] Bound retained memory during hot-device metadata lookups - #1030

Merged
ColinLeeo merged 3 commits into
apache:developfrom
zhangxinyao88:codex/tsfile-1009-query-owned-index-copies
Oct 26, 2026
Merged

ColinLeeo merged 3 commits into
apache:developfrom
zhangxinyao88:codex/tsfile-1009-query-owned-index-copies

Conversation

@zhangxinyao88

@zhangxinyao88 zhangxinyao88 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Repeated lookups of a hot device clone measurement names into the cached index node's arena. Releasing each scan iterator therefore leaves retained reader memory growing even with one cached device: the regression fixture grows from 1,072 to 84,688 accounted bytes after 10,000 lookups on develop.

Give lookup-result copies an explicit destination arena and use the query/iterator arena for measurement lookup, including every level of internal-index traversal. Keep the existing lookup signature and default behavior for other callers. Temporary traversal nodes can be destroyed safely, and cache eviction cannot invalidate parsed iterator metadata. The file format and read results are unchanged.

Fixes #1009.

Validation on macOS arm64, JDK 17, clang-format 17.0.6:

  • ./mvnw -B -ntp -P with-cpp -Denable.lzma2=ON verify passes with all configured codecs, ANTLR and SIMD enabled. CTest registers 1,180 cases: 1,167 passed, 3 skipped (external cross-language fixtures not configured), 10 disabled upstream performance/large-file cases, 0 failures. Spotless, Checkstyle and RAT pass.
  • Nine focused genuinely instrumented Debug/ASan/UBSan tests pass after the 2026-10-22 test-cleanup fix. Both test and library compile flags contain -fsanitize=address,undefined; the test binary imports ASan/UBSan handlers and loads the ASan runtime. Optional codecs/ANTLR/SIMD are disabled for this separate lifetime probe. Includes both hot-device index depths, returned names surviving source arena reset and a row read after cache eviction.
  • Both new hot-device cases fail against unchanged develop production code with 84,688 retained bytes versus 1,072 at warm-up, then pass after this fix. Accounting assertions are guarded by ENABLE_MEM_STAT; functional checks still run without it.
  • git diff --check passes. No Java/Python suite, full sanitizer suite or external cross-language-fixture run is claimed.

Validation correction (2026-10-22): the earlier local build labelled ASan had lost its sanitizer compiler flags during CMake configuration, so those earlier nine passes were plain Debug results. MSVC ASan then caught a use-after-free in this PR's eviction test: column iterators were destroyed after revert_tsblock() freed their vectors. The follow-up commit scopes those iterators before block release. The full C++ Maven verification and the genuinely instrumented nine-case probe above were rerun successfully after that fix. The production metadata-ownership change is unchanged. Windows verification of the follow-up is still pending.

CI at the original head also showed Linux setup failures before compilation (clang-format-17 absent; Python 3.9 unavailable for Ubuntu 26.04). Those provisioning failures are outside this patch. No complete green-CI claim is made.

AI disclosure: OpenAI Codex generated this patch, tests, and description and performed the reported verification. No personal human review is claimed.

CI setup maintenance (2026-10-25)

The existing Ubuntu jobs failed before compilation because they assumed /usr/bin/clang-format-17 existed; the Python 3.9 job also requested a binary unavailable for Ubuntu 26.04. The workflow follow-up installs the same required clang-format 17.0.6 in a runner-local virtual environment and moves only the Linux Python 3.9 matrix cell to Ubuntu 22.04. All eight C++ and nine Python jobs, build/test commands, triggers and permissions are preserved.

Local validation: actionlint 1.7.12 and shell/YAML checks pass. Both original dependency steps reproduce the missing-formatter failure with system package commands mocked; both changed steps actually install/run clang-format 17.0.6 and expose it through the next-step PATH on macOS. The official setup-python manifest confirms a Linux x64 Python 3.9.25 artifact for Ubuntu 22.04. A Linux container smoke test could not run because the Docker credential helper stalled; no Linux/full application test pass is claimed for this workflow-only follow-up. Exact-head upstream CI remains pending observation/approval; earlier job results are not this commit's results.

Copy measurement index lookup results into the iterator/query arena,
including intermediate nodes during multi-level traversal. Preserve the
existing lookup entry point and keep cached node arenas unchanged.

Cover repeated hot-device lookups, result-copy lifetime and an active
iterator surviving cache eviction.

Generated-by: OpenAI Codex
Keep column iterator destructors inside the block lifetime. MSVC ASan
caught their reset_offset writes after revert_tsblock freed the vectors.
The production metadata ownership fix remains unchanged.

Generated-by: OpenAI Codex
Install clang-format 17.0.6 in a runner-local virtual environment rather than assuming /usr/bin/clang-format-17 exists. Keep the Python 3.9 Linux job on Ubuntu 22.04, where setup-python provides its binary, while retaining all nine Python matrix combinations.

Generated-by: OpenAI Codex
@ColinLeeo

Copy link
Copy Markdown
Contributor

LGTM and can be merged when ci pass.

@ColinLeeo
ColinLeeo self-requested a review October 26, 2026 02:46
@ColinLeeo
ColinLeeo merged commit d314779 into apache:develop Oct 26, 2026
49 checks passed
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.

[Bug][C++] Repeated metadata lookups grow hot device-cache arenas

2 participants