Skip to content

fix(core): fix rare index reader memory on partition drop#6087

Merged
ideoma merged 2 commits intomasterfrom
jh_index_leak_after_deleted_partition
Sep 1, 2025
Merged

fix(core): fix rare index reader memory on partition drop#6087
ideoma merged 2 commits intomasterfrom
jh_index_leak_after_deleted_partition

Conversation

@jerrinot
Copy link
Copy Markdown
Contributor

@jerrinot jerrinot commented Aug 30, 2025

A partition removal followed by a schema change could cause a memory and file descriptor leak
It's fixing a FD and memory leak found by a fuzz test.

WIP.
Scenario:

  1. Partition gets deleted -> stale bitmap indexes left in bitmapIndexes list beyond a valid range (at position not references by any column)
  2. Eventually, a table schema change triggers createNewColumnList()
  3. createNewColumnList() creates a new bitmapIndexes list but only copies indexes from the old list within a valid range
  4. The stale indexes beyond the range are not included in the new bitmap index list
  5. When old arrays are replaced with new ones, those stale indexes are orphaned - they remain open but unreachable
  6. FD leak - the file descriptors for those bitmap indexes are never closed

Note:
I am not quite sure if Misc.free(bitmapIndexes.get(i)); is needed. I added it only because of the Misc.free(columns.get(i)); above. but it appears to me that both columns and indexes should be closed above at closePartitionResource():

if (partitionSize > -1) {
    closePartitionResources(partitionIndex, offset);
    openPartitionCount--;
}
int baseIndex = getPrimaryColumnIndex(columnBase, 0);
int newBaseIndex = getPrimaryColumnIndex(getColumnBase(partitionIndex + 1), 0);
for (int i = baseIndex, n = newBaseIndex - 1; i < n; i++) {
    // Close columns before deleting the objects.
    // FD leak caught by failing fuzz tests.
    Misc.free(columns.get(i)); <--- pre-existing line. is it needed? why? 
    Misc.free(bitmapIndexes.get(i)); <-- is this needed? why? 
}

but the partitionSize > -1 guard prevents the resources to be closed?

a partition removal followed by a schema change could cause a memory and file descriptor leak
@jerrinot jerrinot added Bug Incorrect or unexpected behavior Core Related to storage, data type, etc. labels Aug 30, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 30, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jh_index_leak_after_deleted_partition

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@glasstiger
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 3 / 3 (100.00%)

file detail

path covered line new line coverage
🔵 io/questdb/cairo/TableReader.java 3 3 100.00%

Copy link
Copy Markdown
Collaborator

@ideoma ideoma left a comment

Choose a reason for hiding this comment

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

Looks good, what about tests?

@ideoma ideoma changed the title fix(core): index reader memory leak fix fix(core): fix rare index reader memory on partition drop Sep 1, 2025
@ideoma ideoma merged commit 39f84f2 into master Sep 1, 2025
37 checks passed
@ideoma ideoma deleted the jh_index_leak_after_deleted_partition branch September 1, 2025 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Incorrect or unexpected behavior Core Related to storage, data type, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants