Add C API to unset all query buffers.#5783
Conversation
9e653ab to
e44cf5a
Compare
| /** | ||
| * Unsets all buffers set by previous calls to tiledb_query_set_data_buffer, | ||
| * tiledb_query_set_offsets_buffer, and tiledb_query_set_validity_buffer, | ||
| * resetting the query to a state as if no buffers had been set. | ||
| * | ||
| * This function can be useful to call before releasing the memory from the | ||
| * query buffers, providing additional memory safety. | ||
| * | ||
| * @param query The TileDB query. | ||
| * | ||
| * @return `TILEDB_OK` for success and `TILEDB_ERR` for error. The function will | ||
| * return an error only if the query pointer is invalid. | ||
| */ | ||
| TILEDB_EXPORT int32_t tiledb_query_unset_buffers(tiledb_query_t* query) | ||
| TILEDB_NOEXCEPT; | ||
|
|
There was a problem hiding this comment.
I had the idea of not accepting a context here, because this API can only fail if called with a null pointer. Let me know what you think.
|
This implementation looks fine to me - but I wonder if it's the right way to solve the problem, which as I understand it is that we can't detach buffers from the Rust query object in order to fill them with the next round of global order write data. I've suggested before that we tried replacing the This pattern didn't occur to us 2 years ago; but now maybe it's something we can try. The What do you think? If there's other potential uses of this C API then I'll approve anyway. |
…d create the array in MemFS.
|
I am not a fan of replicating the For me, the ideal UX for writing arrays would look like this (see also TileDB-Inc/TileDB-Py#2237 (comment)): TileDB-rs is halfway through realizing this vision, and thus manually setting buffers would be IMO a step backwards.
APIs for garbage-collected languages like C# and Go can unpin the query buffers after unsetting them from a query (e.g. after each global order write step or when resizing buffers in incomplete reads), allowing to increase memory efficiency. |
I'll nitpick you a bit here to point out that there's an implicit map construction here which we probably ought to avoid. Or at least have the option to avoid. One idiomatic way would be to do The needs for write and read queries are quite different and I definitely agree with you that write queries should not need to do a mutable borrow. You didn't specifically say so but it seems to me like you would be on board to having entirely different code pathways for reads and writes.
Does the query object in these languages also pin the buffers? Surely it must. Wouldn't garbage collection clear the query, and then clear the buffers after that? I approved anyway - I'm just curious. |
Definitely;
Yes, query buffers are pinned before passing them to the C API. Because garbage collection finalizers run in a non-deterministic order, there is a single "query handle" object that manages both the REST-CI has succeeded on rerun (unfortunately it's not visible from this page), so merging… |
This PR adds new C and C++ APIs that unset all previously set query buffers. It can be useful to provide additional memory safety by guaranteeing that the Core will not hold references to user buffers after a certain point, which will be used by TileDB-rs to safely decouple the buffers' lifetime from the query object (CORE-502).
TYPE: C_API
DESC: Add
tiledb_query_unset_buffersfunction, that unsets all previously set buffers.TYPE: CPP_API
DESC: Add
Query::unset_buffersfunction, that unsets all previously set buffers.