Skip to content

fix a bug that double int hashmap memory allocation - #18738

Merged
mergify[bot] merged 10 commits into
matrixorigin:mainfrom
badboynt1:inthashmap
Sep 12, 2024
Merged

mergify[bot] merged 10 commits into
matrixorigin:mainfrom
badboynt1:inthashmap

Conversation

@badboynt1

@badboynt1 badboynt1 commented Sep 12, 2024 •

Copy link
Copy Markdown
Contributor

User description

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #18150

What this PR does / why we need it:

fix a bug that double int hashmap memory allocation


PR Type

Bug fix


Description

  • Fixed a bug in the Int64HashMap implementation where the memory allocation size was incorrectly set to strCellSize instead of intCellSize.
  • Updated the allocation logic in both the Init and ResizeOnDemand methods to ensure correct memory allocation.

Changes walkthrough 📝

Relevant files
Bug fix
int64_hash_map.go
Fix memory allocation size in Int64HashMap                             

pkg/container/hashtable/int64_hash_map.go

  • Fixed memory allocation size from strCellSize to intCellSize.
  • Corrected allocation logic in Init and ResizeOnDemand methods.
  • +3/-3     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @qodo-code-review

    Copy link
    Copy Markdown

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Bug Fix Verification
    Verify that changing from strCellSize to intCellSize is the correct fix for the double memory allocation issue.

    Consistency Check
    Ensure that the change from strCellSize to intCellSize is applied consistently throughout the file, including in the ResizeOnDemand method.

    @mergify mergify Bot added the kind/bug Something isn't working label Sep 12, 2024
    @matrix-meow matrix-meow added the size/XS Denotes a PR that changes [1, 9] lines label Sep 12, 2024
    @qodo-code-review

    Copy link
    Copy Markdown

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Consistency
    Use consistent error handling style throughout the code

    Consider using a consistent error handling style across the codebase. In the Init
    method, you're using if err = ..., while in other methods you're using if err :=
    .... Stick to one style for better consistency.

    pkg/container/hashtable/int64_hash_map.go [92]

    -if err = ht.allocate(0, uint64(ht.blockCellCnt*intCellSize)); err != nil {
    +if err := ht.allocate(0, uint64(ht.blockCellCnt*intCellSize)); err != nil {
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Consistent error handling style enhances code readability and maintainability, making it easier for developers to follow and reducing the likelihood of mistakes. This suggestion addresses a noticeable inconsistency in the codebase.

    8
    Maintainability
    Extract allocation size calculation to improve maintainability

    Consider extracting the calculation of the allocation size into a constant or a
    method to improve code maintainability and reduce the risk of future errors.

    pkg/container/hashtable/int64_hash_map.go [92]

    -if err = ht.allocate(0, uint64(ht.blockCellCnt*intCellSize)); err != nil {
    +allocationSize := uint64(ht.blockCellCnt * intCellSize)
    +if err = ht.allocate(0, allocationSize); err != nil {
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Extracting the allocation size calculation into a separate variable improves code readability and maintainability by reducing repetition and potential errors in future changes.

    7
    Best practice
    Add a comment explaining the use of intCellSize

    Consider adding a comment explaining the reason for using intCellSize instead of
    strCellSize to prevent future confusion and potential reintroduction of the bug.

    pkg/container/hashtable/int64_hash_map.go [92]

    +// Use intCellSize for Int64HashMap to allocate the correct amount of memory
     if err = ht.allocate(0, uint64(ht.blockCellCnt*intCellSize)); err != nil {
     
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: Adding a comment provides clarity on the choice of intCellSize over strCellSize, which can prevent future confusion and help maintainers understand the rationale behind the change.

    6

    @badboynt1
    badboynt1 requested a review from m-schen as a code owner September 12, 2024 08:23
    @matrix-meow matrix-meow added size/S Denotes a PR that changes [10,99] lines and removed size/XS Denotes a PR that changes [1, 9] lines labels Sep 12, 2024
    @mergify
    mergify Bot merged commit c2339c3 into matrixorigin:main Sep 12, 2024
    @badboynt1
    badboynt1 deleted the inthashmap branch September 13, 2024 01:29
    fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
    fix a bug that double int hashmap memory allocation
    
    Approved by: @XuPeng-SH, @m-schen
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    Bug fix kind/bug Something isn't working Review effort [1-5]: 2 size/S Denotes a PR that changes [10,99] lines

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    4 participants