-
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
Conversation
fc2829d to
61b60c3
Compare
44ae87c to
87dbd48
Compare
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.
src/core/compact_object.cc
Outdated
| 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.
there is a helper function UpdateSize, maybe it should be used here. Mainly it protects against object size going down to negative. I'm not clear when that will happen though.
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.
I changed to use UpdateSize, it is more defensive.
b20bbd7 to
6774c01
Compare
|
augment review |
6774c01 to
be6fbee
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 suggestion posted.
Comment augment review to trigger a new review at any time.
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
be6fbee to
a70faa2
Compare
| if (did) { | ||
| reallocations++; | ||
| if (const ssize_t delta = it->second.MallocUsed() - original_size; | ||
| delta != 0 && db_table != nullptr) { |
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.
can db_table be nullptr?
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.
probably not but I added it to be defensive as we access a field via the pointer.
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.
i usually do not like these things as it raises questions where this state is possible. it's better to DCHECK to assert the precondition than have such ifs
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.
I see, I will remove it in a follow up
For JSON type, after defragmentation used size may change. The change is propagated to the db stats object, so that metrics observe the change and reduction in memory usage (if any) correctly.
The JSON object records the change by observing the diff in bytes used by the memory resource, this is the same pattern used in
json_family.ccetc. Once the change is determined it is set in thebytes_usedfield for the json object.The delta update is in effect for all objects whose size changes, not just JSON type objects.