-
Notifications
You must be signed in to change notification settings - Fork 1k
fix(json_family): Fix json memory tracking issues. SECOND PR #5056
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
fix(json_family): Fix json memory tracking issues. SECOND PR #5056
Conversation
fixes dragonflydb#5055 , dragonflydb#5054 Signed-off-by: Stepan Bagritsevich <[email protected]>
@@ -2060,6 +2111,8 @@ void JsonFamily::Register(CommandRegistry* registry) { | |||
*registry << CI{"JSON.ARRAPPEND", CO::WRITE | CO::DENYOOM | CO::FAST, -4, 1, 1, acl::JSON}.HFUNC( | |||
ArrAppend); | |||
*registry << CI{"JSON.ARRINDEX", CO::READONLY | CO::FAST, -4, 1, 1, acl::JSON}.HFUNC(ArrIndex); | |||
*registry << CI{"JSON._MEMUSAGE", CO::READONLY | CO::FAST, 2, 1, 1, acl::JSON}.HFUNC( |
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.
you do not need it, we already have "memory usage " that should work for json as well.
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.
As I understand, MEMORY USAGE also includes the size of the key, which might be an issue in this case. I think it would be useful to add a flag to the MEMORY USAGE command that excludes the key size from the calculation.
if (update_on_delete_ && !set_size_was_called_) { | ||
SetJsonSize(); | ||
} else if (!set_size_was_called_) { | ||
VLOG(1) << "JsonAutoUpdater destructor called without SetJsonSize() being called. This may " |
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.
maybe LOG(DFATAL) ?
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 shouldn't fail in debug. For example:
JsonAutoUpdater updater{};
...
if (<result is not valid>) {
return;
}
If the result is not valid we will not update the json. This means we don't need to call SetJsonSize
, and that's totally fine. I thought we could use LOG(WARNING)
here.
Really good work, @BagritsevichStepan ! |
fixes a lot of json memory tracking issues, #5055 , #5054 .
Also, partially fixes #4926
Bugs that were found and fixed:
ShardJsonFromString
, which parses the json_str into the jsoncons's json and returns optional of this. The bug was thatstd::optional
still holds the value even afterstd::move
. So we overestimate the memory usage.JSON.SET
when we calledShardJsonFromString
before starting the memory trackingop_args.shard->search_indices()->RemoveDoc
after starting the memory tracking.RemoveDoc
has a static cache that may allocate some memory, but this memory does not belong to the JSON object itself. As a result, memory usage will be overestimated in this case.JSON.DEL
command - we didn't update the indexes and track the memory usage at all. One of the bugs is good described in JSON value is not updated in the indexes after the JSON.DEL command #5055JSON.SET
command: JSON value is removed from the index after a failed JSON.SET command #5054To fix this, I introduced
json_family_memory_test
and changedJsonMemTracker
toJsonAutoUpdater
, which eliminates most of the bugs described above.It also ensures that RemoveDoc is called before memory tracking starts, and that AddDoc is called after SetJsonSize and also it will be called even if an error occurs.
Therefore, whenever we perform an update operation on a JSON value, this class must be used.