Repository navigation
Conversation
ccfc74e to
a4cb455
Compare
a4cb455 to
6077c24
Compare
Every database-executing entry point is still synchronous for the caller, but its work now runs on the library's own tokio worker threads; the calling thread only parks until the operation completes. The caller's stack is never used for lance/datafusion planning or execution, so the API is safe to call from threads, coroutines and fibers with small fixed-size stacks (Ceph RGW's beast coroutines use 512 KiB). Runtime bridge - runtime::run_blocking spawns the future onto the runtime and blocks the caller on its JoinHandle. All entry points in connection, table, query and index go through it. - A panic inside a task, and a call made from inside a tokio async context, are reported as LANCEDB_RUNTIME instead of aborting the process. A rejected nested call never dispatches its work. - The runtime is created on first use. Initialization failures are reported as LANCEDB_RUNTIME and are not cached, so a later call can retry. - Arrow objects handed to the library may be consumed and released on a worker thread, i.e. not the thread that produced them. Runtime configuration - lancedb_runtime_configure() sets worker_threads, worker_stack_size and max_blocking_threads once, before the first database call. Repeated or late configuration returns LANCEDB_RUNTIME. - Fields left at 0 fall back to the defaults: number of CPUs (or TOKIO_WORKER_THREADS), 8 MiB and 512. - The worker stack has a 2 MiB floor (LANCEDB_MIN_WORKER_STACK_SIZE). Smaller nonzero values are rejected by the configure call with LANCEDB_INVALID_ARGUMENT; smaller environment values are clamped. The floor is an acceptance threshold, not a guarantee that every query fits. - Worker counts above 65535, stack sizes above isize::MAX and overflowing worker/blocking totals are rejected. - These options size the wrapper's runtime only, not Lance's separate CPU pool, and do not bound queued work or process-wide CPU use. Removed - lancedb_run_on_stack() and the stacker dependency. stacker measures remaining stack against the OS thread's bounds, which do not describe a coroutine's separately mapped stack, and it is no longer needed. examples/asio_coroutine.cpp calls the API directly from the coroutine. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01E63tgb7eXHwzmaQBSErFWu Signed-off-by: Andrew Altshuler <[email protected]>
6077c24 to
59ca9d7
Compare
|
@aaltshuler @yuvalif Two open PRs now cover the same runtime/stack work: #69 (five commits, six behind The visible differences: #69 keeps the Both PRs remove |
|
Resolving my earlier question: under the loop's duplicate-PR rule, #76 is the surviving PR, and #69 has been closed as the duplicate with the comparison linked there. No choice or follow-up is needed from either author. Review notes carried from #69: it had |
There was a problem hiding this comment.
Reviewed at 59ca9d7. The runtime bridge is applied consistently, and I am not asking to change the design or hold this PR. Three documentation/migration follow-ups:
-
C ABI migration note. Removing
lancedb_run_on_stackis a real source/ABI migration for Ceph, not just a cleanup:create_index,remove_indexes,create_vector_bucketandput_vectorspass a stack-owned context into the wrapper and readctx.resultsynchronously after it returns (put_vectors: https://github.com/ceph/ceph/blob/065d8cb97eb606fc3fec028107a98a6adf1658a0/src/rgw/rgw_s3vector.cc#L2168-L2185). The wrapper also did the caller-stack growth for them. Please add a short note the next 0.x minor release can carry (PR description is fine) saying existing C/C++ callers must recompile, and that users oflancedb_run_on_stackmust remove the wrapper and handle the remaining caller-side work explicitly. ceph/ceph#72652 still pins lancedb-c at the closed #69 head11e8072, so it does not validate this head; please state whether RGW validation was run against59ca9d7. The 256 KiB C++ stack tests are useful coverage for the wrapper, but they do not exercise the Ceph SAL path. -
Inline note on the empty-name failure path: with valid Arrow data and an empty table name,
lancedb_table_createtakes the reader and then drops it insiderun_blocking, so its arrays release on a worker. The public wording should say that explicitly and keep inputArrowSchemadistinct from consumed readers. -
Inline note on the threading paragraph:
lancedb_table_versionandlancedb_table_count_rowsreturn 0 on failure, so they cannot reportLANCEDB_RUNTIMElike error-returning functions.
No performance claims here.
| * Do not call this API from within a tokio async context (e.g. from a task | ||
| * running on the library's own runtime); doing so is reported as | ||
| * LANCEDB_RUNTIME. |
There was a problem hiding this comment.
This paragraph currently covers the whole API, but lancedb_table_version and lancedb_table_count_rows return 0 on failure and have no error channel. Please qualify the nested-call sentence.
| * Do not call this API from within a tokio async context (e.g. from a task | |
| * running on the library's own runtime); doing so is reported as | |
| * LANCEDB_RUNTIME. | |
| * Do not call this API from within a tokio async context (e.g. from a task | |
| * running on the library's own runtime). A rejected call to a function that | |
| * returns LanceDBError is reported as LANCEDB_RUNTIME; | |
| * lancedb_table_version() and lancedb_table_count_rows() return 0 instead, | |
| * since they have no error channel. |
| * Arrow objects handed to the library (record batch readers, schemas) may be | ||
| * consumed and released on those worker threads, i.e. on a different thread | ||
| * than the one that produced them. Producers must therefore tolerate | ||
| * release callbacks from another thread — the Arrow C data interface does | ||
| * not require this by itself. |
There was a problem hiding this comment.
This is the right place to distinguish ownership, because the failure path below drops a consumed reader on a worker. Suggested wording:
| * Arrow objects handed to the library (record batch readers, schemas) may be | |
| * consumed and released on those worker threads, i.e. on a different thread | |
| * than the one that produced them. Producers must therefore tolerate | |
| * release callbacks from another thread — the Arrow C data interface does | |
| * not require this by itself. | |
| * Record batch readers handed to the library may be consumed and released | |
| * on those worker threads, i.e. on a different thread than the one that | |
| * produced them, including when a call fails after ownership transfer. | |
| * Producers must therefore tolerate release callbacks from another thread — | |
| * the Arrow C data interface does not require this by itself. Input | |
| * ArrowSchema pointers are read, not consumed, and remain caller-owned. |
| // Take ownership of the reader | ||
| let reader_box = Box::from_raw(reader); |
There was a problem hiding this comment.
lancedb_table_create takes ownership here, then validate_table_name fails inside run_blocking for an empty name, so the reader is dropped on a worker even though the table was never created. The error code is unchanged (LANCEDB_INVALID_TABLE_NAME); the new part is where the drop happens. Please keep that ownership/release detail next to the transfer:
| // Take ownership of the reader | |
| let reader_box = Box::from_raw(reader); | |
| // Take ownership of the reader. It is dropped on a worker if | |
| // validate_table_name() fails below, so its release callbacks must | |
| // tolerate a worker thread. Input ArrowSchema above is borrowed. | |
| let reader_box = Box::from_raw(reader); |
|
@yuvalif Integration note after #80 merged (main is now The branches auto-merge cleanly because the new functions sit outside the edited hunks, so the conflict-free merge would hide an unresolved Additional main change: #83 is now merged at Additional integration point: #84 is now merged at The SDK upgrade is now on main at |
|
RGW validation at
The failures are Ceph-side and also occur on Ceph's base without this change: one test that needs a rebuild slower than this hardware produces, and a DeleteIndex / background-rebuild race. Scope: aarch64, Debug build, one run per variant. @yuvalif on your question in #69 about keeping only the configure API: fine by me. Drop the |
|
Thanks for testing The PR branch still needs to be integrated with current |
Every database-executing entry point is still synchronous for the caller, but its work now runs on the library's own tokio worker threads; the calling thread only parks until the operation completes. The caller's stack is never used for lance/datafusion planning or execution, so the API is safe to call from threads, coroutines and fibers with small fixed-size stacks (Ceph RGW's beast coroutines use 512 KiB).
Runtime bridge
Runtime configuration
Removed
Claude-Session: https://claude.ai/code/session_01E63tgb7eXHwzmaQBSErFWu