Skip to content

fix(datacell): update max_capacity after io operation completes in 0.18#1651

Merged
inabao merged 1 commit into0.18from
fix-resize-order-0.18
Mar 11, 2026
Merged

fix(datacell): update max_capacity after io operation completes in 0.18#1651
inabao merged 1 commit into0.18from
fix-resize-order-0.18

Conversation

@inabao
Copy link
Copy Markdown
Collaborator

@inabao inabao commented Mar 10, 2026

cp #1642 to 0.15
link: #1643

Move max_capacity assignment after io->Write() to ensure data is persisted before updating capacity.

This fixes the same resize issue as in 0.17 branch.

Move max_capacity assignment after io->Write() to ensure data is persisted before updating capacity.

This fixes the same resize issue as in 0.17 branch.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
@inabao inabao self-assigned this Mar 10, 2026
@inabao inabao added the kind/bug Something isn't working label Mar 10, 2026
@gemini-code-assist
Copy link
Copy Markdown
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 critical data integrity concern by reordering operations during capacity resizing in various data cell components. The change ensures that the internal max_capacity_ state is only updated after the underlying I/O operation to allocate or resize storage has been successfully performed. This prevents race conditions or inconsistencies where the system might incorrectly assume new capacity is available before it's physically persisted, thereby enhancing the robustness and reliability of data handling, particularly during dynamic resizing events.

Highlights

  • Data Consistency Fix: Resolved a potential data inconsistency issue by ensuring that the max_capacity_ member is updated only after the corresponding I/O write operation has successfully completed. This prevents situations where the in-memory capacity might be updated before the physical storage is allocated, leading to resize issues.
  • Broad Application: Applied this critical fix across multiple datacell implementations, including ExtraInfoDataCell, FlattenDataCell, GraphDataCell, and SparseVectorDataCell, to maintain consistent behavior and data integrity throughout the system.

🧠 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.

Changelog
  • src/datacell/extra_info_datacell.h
    • Moved the assignment of max_capacity_ to after the io_->Write() call in the Resize method.
  • src/datacell/flatten_datacell.h
    • Relocated the assignment of max_capacity_ to occur after the io_->Write() call in the Resize method.
  • src/datacell/graph_datacell.h
    • Shifted the assignment of max_capacity_ to follow the io_->Write() call in the Resize method.
  • src/datacell/sparse_vector_datacell.h
    • Placed the assignment of max_capacity_ after the io_->Write() call in the Resize method.
Activity
  • No human activity has been recorded on this pull request yet.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses a potential race condition by moving the max_capacity_ assignment to after the io->Write() operation completes. This ensures that the in-memory capacity metadata is only updated after the backing storage has been successfully resized, preventing state inconsistencies in case of an I/O failure. While the core change is correct, I've added a few suggestions to improve code clarity and maintainability by replacing a magic number and an ambiguously named variable with a clearer alternative across the modified files.

Comment on lines 56 to 58
uint8_t end_flag =
127; // the value is meaningless, only to occupy the position for io allocate
this->io_->Write(&end_flag, 1, io_size);
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.

medium

The variable name end_flag and the magic number 127 can be improved for clarity, especially since the comment states the value is meaningless. Using a named constant with a value of 0 and a more descriptive variable name like dummy_byte would enhance readability and maintainability.

Suggested change
uint8_t end_flag =
127; // the value is meaningless, only to occupy the position for io allocate
this->io_->Write(&end_flag, 1, io_size);
const uint8_t dummy_byte = 0; // value is meaningless, used to trigger allocation
this->io_->Write(&dummy_byte, 1, io_size);

Comment on lines 94 to 96
uint8_t end_flag =
127; // the value is meaningless, only to occupy the position for io allocate
this->io_->Write(&end_flag, 1, io_size);
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.

medium

The variable name end_flag and the magic number 127 can be improved for clarity, especially since the comment states the value is meaningless. Using a named constant with a value of 0 and a more descriptive variable name like dummy_byte would enhance readability and maintainability.

Suggested change
uint8_t end_flag =
127; // the value is meaningless, only to occupy the position for io allocate
this->io_->Write(&end_flag, 1, io_size);
const uint8_t dummy_byte = 0; // value is meaningless, used to trigger allocation
this->io_->Write(&dummy_byte, 1, io_size);

Comment on lines 266 to 268
uint8_t end_flag =
127; // the value is meaningless, only to occupy the position for io allocate
this->io_->Write(&end_flag, 1, io_size);
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.

medium

The variable name end_flag and the magic number 127 can be improved for clarity, especially since the comment states the value is meaningless. Using a named constant with a value of 0 and a more descriptive variable name like dummy_byte would enhance readability and maintainability.

Suggested change
uint8_t end_flag =
127; // the value is meaningless, only to occupy the position for io allocate
this->io_->Write(&end_flag, 1, io_size);
const uint8_t dummy_byte = 0; // value is meaningless, used to trigger allocation
this->io_->Write(&dummy_byte, 1, io_size);

Comment on lines 82 to 85
uint8_t end_flag =
127; // the value is meaingless, only to occupy the position for io allocate
this->io_->Write(&end_flag, 1, io_size);
this->offset_io_->Write(&end_flag, 1, new_capacity * sizeof(uint32_t));
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.

medium

The variable name end_flag and the magic number 127 can be improved for clarity. A clearer variable name and a value of 0 would be better. Also, there is a typo 'meaingless' in the comment. The same dummy byte can be used for both Write calls.

Suggested change
uint8_t end_flag =
127; // the value is meaingless, only to occupy the position for io allocate
this->io_->Write(&end_flag, 1, io_size);
this->offset_io_->Write(&end_flag, 1, new_capacity * sizeof(uint32_t));
const uint8_t dummy_byte = 0; // value is meaningless, used to trigger allocation
this->io_->Write(&dummy_byte, 1, io_size);
this->offset_io_->Write(&dummy_byte, 1, new_capacity * sizeof(uint32_t));

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##             0.18    #1651      +/-   ##
==========================================
+ Coverage   90.74%   91.24%   +0.50%     
==========================================
  Files         328      328              
  Lines       19291    19291              
==========================================
+ Hits        17505    17602      +97     
+ Misses       1786     1689      -97     
Flag Coverage Δ
cpp 91.24% <100.00%> (+0.50%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
common 85.81% <ø> (ø)
datacell 92.78% <ø> (-0.16%) ⬇️
index 91.05% <ø> (+0.80%) ⬆️
simd 100.00% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 934bdd8...fdc2caa. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@wxyucs wxyucs left a comment

Choose a reason for hiding this comment

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

lgtm

@inabao inabao merged commit 4617c06 into 0.18 Mar 11, 2026
32 of 34 checks passed
@inabao inabao deleted the fix-resize-order-0.18 branch March 11, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XS version/0.18

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants