Skip to content

Conversation

@abhijat
Copy link
Contributor

@abhijat abhijat commented Nov 13, 2025

For JSON type, after defragmentation used size may change. The change is recorded in page usage object, and the delta is propagated to the db stats object, so that metrics observe the change and reduction in memory usage (if any) correctly.

The delta update is in effect for all objects whose size changes, not just JSON type objects.

@abhijat abhijat force-pushed the abhijat/fix/account-json-size-diff-defrag branch 3 times, most recently from fc2829d to 61b60c3 Compare November 13, 2025 14:47
@abhijat abhijat changed the title core: Account for size change on json object defragment [WIP] fix(core): Account for size change on json object defragment Nov 13, 2025
@abhijat abhijat force-pushed the abhijat/fix/account-json-size-diff-defrag branch 6 times, most recently from 44ae87c to 87dbd48 Compare November 14, 2025 10:26
@abhijat abhijat force-pushed the abhijat/fix/account-json-size-diff-defrag branch 2 times, most recently from a2cae02 to be880d4 Compare December 8, 2025 08:55
@abhijat abhijat force-pushed the abhijat/fix/account-json-size-diff-defrag branch from be880d4 to b20bbd7 Compare December 8, 2025 09:02
@abhijat abhijat changed the title [WIP] fix(core): Account for size change on json object defragment fix(core): Account for size change on json object defragment Dec 8, 2025
@abhijat abhijat marked this pull request as ready for review December 8, 2025 10:17
Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 1 suggestions posted.

Comment augment review to trigger a new review at any time.

json_ptr = AllocateMR<JsonType>(DeepCopyJSON(old));
DeleteMR<JsonType>(old);
if (const ssize_t delta = mr->used() - before; delta != 0) {
bytes_used += delta;
Copy link

Choose a reason for hiding this comment

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

bytes_used is a size_t, while delta is ssize_t and may be negative; using += here can cause unsigned wraparound when defragmentation reduces size, leading to incorrect memory accounting.

🤖 Was this useful? React with 👍 or 👎

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is intentionally ssize_t, delta is expected to be negative. It should not lead to a wraparound though as delta is only caused by reallocation.

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.

2 participants