-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(JSON): Use stateless allocator #6060
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
76d8385 to
6e2af7f
Compare
A problem with this approach is that not all cores are guaranteed to have called This is seen in the failing tests. If the There are places in code which just need to parse some string into json without relying on mimalloc heap (eg in cluster config). These places use the default memory resource. They need to use the same allocator which uses the mimalloc heap. |
The right thing to do here seems to be to defer all parsing of JSON objects until we are on the shard, in the tx callback. At present some parsing is done on coordinator thread to return errors early, and some on the shard where the key resides. The other uses of |
|
will be rebased after #6061, which will introduce two paths for parsing JSON values:
|
|
@abhijat I am not sure I get it. Why can not we use default resource in coordinator thread together with JSONFromString, and use ShardJsonFromString in shard threads together with thread local heap? |
|
Ok, I understand now: but where do they meet? i.e. do we pass a "coordinator" json objects to shard threads? in other words, even today I would expect that those objects would be "non-interchangeable", as we must allocate shard local objects only with shard local heap, so in a way having two disjoin c++ types would make things more explicit and clear. |
There are a few places where we allocate on coordinator using the default memory resource and pass to the destination shard which uses mimalloc based allocation, and then mix those objects. I think it is done to facilitate early error reporting, but I have changed those call sites in #6061 deferring json parsing to the destination shard. In fact I found this comment https://github.com/dragonflydb/dragonfly/blob/main/src/server/json_family.cc#L1905-L1907 which mentions this same problem.
Yes, I added a new type in that PR called After that parent PR is merged, the other |
|
Great! |
3fa1c19 to
707e6a7
Compare
| string s; | ||
| val.dump(s); | ||
| return JsonFromString(s); |
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.
This is unfortunate side effect of not being able to send JsonType object to the coordinator thread, it can only be destroyed on the shard that created it. We have to copy it into a safe type before sending it to coordinator.
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.
Note: mimalloc will deallocate the object from another thread, but the coordinator thread might not have mimalloc heap set up on it.
707e6a7 to
7de47b0
Compare
This comment was marked as resolved.
This comment was marked as resolved.
575e634 to
2f44fe8
Compare
A stateless allocator is added for JSON parsing. This allocator forwards all requests to a thread local pointer to a memory resource, and assumes that the resource has been initialized when the allocator is constructed. Signed-off-by: Abhijat Malviya <[email protected]>
The new stateless allocator is used for JSON type. The backing memory resource is initialized in engine shard. The function which parses JSON is refactored to no longer accept a memory resource, as the allocator is bound to its thread local memory resource. Signed-off-by: Abhijat Malviya <[email protected]>
Some unit tests do custom memory resource set up and parse JSON, these are fixed so that the thread local resource used for parsing is available before test starts. Signed-off-by: Abhijat Malviya <[email protected]>
The json expression maker function is templatized so it can be used with both short lived and storable JSON values. The short lived variant is used within search family validation. Signed-off-by: Abhijat Malviya <[email protected]>
2f44fe8 to
ed58a32
Compare
Signed-off-by: Abhijat Malviya <[email protected]>
|
I think this is in good condition now once tests pass. I would like to rename |
A stateless allocator is used to parse JSON from string. The allocator forwards requests to a thread local memory resource pointer which is backed by the mimalloc heap. The memory resource is initialized during engine shard init, same as the
CompactObjectthread local initialization.There are two new restrictions that are now in effect when using this stateless allocator: