-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(core): Account for size change on json object defragment #6053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
fc2829d to
61b60c3
Compare
44ae87c to
87dbd48
Compare
a2cae02 to
be880d4
Compare
Signed-off-by: Abhijat Malviya <[email protected]>
be880d4 to
b20bbd7
Compare
There was a problem hiding this 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; |
There was a problem hiding this comment.
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 👎
There was a problem hiding this comment.
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.
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.