Skip to content

fix: many issues in tdb module#34931

Draft
localvar wants to merge 13 commits intomainfrom
fix/tdb-issues
Draft

fix: many issues in tdb module#34931
localvar wants to merge 13 commits intomainfrom
fix/tdb-issues

Conversation

@localvar
Copy link
Contributor

Description

Issue(s)

  • Close/close/Fix/fix/Resolve/resolve: Issue Link

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

localvar added 12 commits March 25, 2026 09:15
== has higher precedence than &, so the macro evaluated as
(flags) & ((flag) == 0) instead of ((flags) & (flag)) == 0.
…in tdbRealloc, header guard order, variable shadowing
…t buffer on CBC_Encrypt failure in tdbEncryptPage\n- remove dead pKey variable and tdbFree(pKey) call in tdbTbOpen\n- use tdbOsFree instead of taosMemoryFree in tdbTbcOpen error path\n- release page lock on CBC_Decrypt failure in tdbPagerInitPage\n- propagate error from tdbTbPopFreePage in tdbPagerRemoveFreePage\n- add overflow array bounds check in tdbPageInsertCell\n- use portable %td format for ptrdiff_t in tdbPageCopy\n- return error on page lock init failure in tdbPageCreate\n- log pointer before freeing in tdbPageDropCell\n- add missing parentheses in TDB_O_RDWR macro\n- free aCellIdx on early return in tdbPageDefragment\n- remove stale commented-out debug logging
- tdbPagerOpen: free pager and close fd on all failure paths (fd
  invalid, file-id generation, getFileSize)
- tdbPagerBegin: close jfd and remove journal file on hashset
  creation failure
- tdbPagerAbort/tdbPagerRestore: validate pgno from journal against
  dbOrigSize to guard against corruption
- tdbPagerFetchPage: release page refcount on init failure,
  uninitialized page, and pager mismatch error paths
- tdbPagerFetchFreePage: release page refcount on init failure
- Remove stale commented-out debug code
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a series of issues across the tdb module, focusing on improving the overall stability, reliability, and correctness of the database system. The changes encompass critical areas such as memory management, error handling, data integrity, and internal data structure operations. By fixing various bugs and refining existing logic, the PR aims to make the tdb module more robust and less prone to unexpected behavior or resource leaks, ultimately contributing to a more dependable database foundation.

Highlights

  • Enhanced Error Handling and Resource Management: Improved error propagation and added comprehensive resource cleanup in critical paths, particularly within the pager and page cache modules, to prevent memory leaks and ensure proper state management on failure.
  • Improved Data Integrity and Robustness: Introduced validation checks for page numbers during journal recovery and abort operations, and addressed potential buffer overflows in page cell insertion, significantly enhancing the database's resilience against corruption.
  • Refactored B-tree Cursor Operations: Streamlined the B-tree cursor's key and value decoding logic by introducing a dedicated helper function, leading to cleaner code and more robust memory management during iteration.
  • Corrected Memory Allocation and Macro Definitions: Updated memory allocation size tracking in tdbRealloc and tdbFree to use size_t for consistency and corrected several bitwise operation macros and a 24-bit integer decoding macro.
  • Optimized Hashset Implementation: Refined the hashset implementation within the pager, including a more robust resizing strategy with allocation failure rollback and a fix for probe chain integrity after item removal.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist
Copy link
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@localvar
Copy link
Contributor Author

/gemini review

@gemini-code-assist
Copy link
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant