Repository navigation
Wip background process - #68736
Wip background process#68736galsalomon66 wants to merge 29 commits into
Conversation
|
@galsalomon66 could you please change the target branch of the PR to be |
|
|
||
| int run_vector_index_build(LanceDBTable* table, LanceDBDistanceType distance_type) { | ||
| LanceDBVectorIndexConfig vec_config = {}; | ||
| vec_config.num_partitions = -1; // auto |
There was a problem hiding this comment.
do we need conf options for any of these parameters?
should we have table level config for any of these parameters?
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
| // still persist the updated global delete count even if no rebuild is needed | ||
| if (local_deletes > 0 && global_delete_count != prev_state.global_delete_count) { | ||
| prev_state.global_delete_count = global_delete_count; | ||
| write_build_state(table, prev_state); |
There was a problem hiding this comment.
since you do this before you take the lock. it won't be possible to update that atomically.
i think that for deletions, we should wait for lancedb to add that into their table stats.
until then, we can not handle deletions, or just use a local best-effort mechanism. so, if we cross the threshold locally (which may never happend, or happen too late) we trigger compaction
There was a problem hiding this comment.
yes, the order of steps is wrong, it impact the delete-rows scenario, not the insert scenario.
it will be fixed.
the delete-rows may challenge the system, upon a scenario of massive insert, follow by re-build, and then massive delete-row, the index may become very inefficient.
and there is no way to know the root cause.
it need for compaction/optimize triggered by user.
There was a problem hiding this comment.
so, maybe, until we fix it at lancedb level, we expose that as a user command?
| // prevents the local background loop from seeing its own lock as stale | ||
| // and reclaiming it when the build takes longer than the lock TTL. | ||
| if (active_builds.count(table_name)) { | ||
| ldpp_dout(this, 5) << "INFO: this RGW is already building " |
There was a problem hiding this comment.
would be nice to print the local_insert count here. if we see that this number is high, it means that we do not keep up with the update rate
| _ = conn.delete_vector_bucket(vectorBucketName=bucket_name) | ||
|
|
||
|
|
||
| def get_rgw_log_path(): |
There was a problem hiding this comment.
this is good as a temporary solution. but debugs logs are not reliable for tests.
we should add admin APIs, and use them.
e.g. these were added fro sessions:
#70311
once this is in, we can add similar ones (+test) for index builds
There was a problem hiding this comment.
yes,
the current rgw-log-scanning is a temp to ensure that complex workloads (create/insert/delete) indeed triggers index-rebuild as expected.
Add RGW SAL (Storage Abstraction Layer) backend for LanceDB, allowing
vector data to be stored in RADOS via RGW's SAL layer instead of
requiring an external S3 endpoint or local filesystem.
Key changes:
- New Rust crate (lancedb-rgw-store) implementing the ObjectStore
trait using C wrapper APIs over RGW SAL operations
both lancedb-c and the rust crate are staically linked
- SAL wrapper (rgw_sal_wrapper.h/.cc) providing C FFI for
underlying object operations
- Config options: rgw_s3vector_backend (local/s3/rgw),
rgw_s3vector_local_path, rgw_s3vector_s3_endpoint, rgw_s3vector_s3_region
- S3 backend uses requesting user's credentials by default
- Integration test support for all three backends
Signed-off-by: Soumya Koduri <[email protected]>
Assisted-By: Claude Opus 4.6 (1M context) <[email protected]>
* uncomment missing test * test cconcurrent updates on the same index Signed-off-by: Yuval Lifshitz <[email protected]>
Signed-off-by: Yuval Lifshitz <[email protected]>
* also fix build issues with s3 backends (new rust version) * remove .so file since we use static linking Signed-off-by: Yuval Lifshitz <[email protected]> Assisted-By: Claude Opus 5 <[email protected]>
also add coverage from bucket ownership and versioned buckets Signed-off-by: Yuval Lifshitz <[email protected]>
return 409 according to AWS spec. Signed-off-by: Yuval Lifshitz <[email protected]>
|
started working on implementing: lancedb/lancedb#3761 |
bd385f6 to
8f1331e
Compare
fa90601 to
3511072
Compare
squash 10 commits into 1 commit with the following commit message: Commit 1 — b15e839 — Background vector-index rebuild with distributed locking (966 insertions) The foundational commit. Adds the entire background rebuild system: a BackgroundManager worker thread that consumes notifications and spawns per-table rebuild coroutines. Implements a distributed lock protocol (GET → conditional DELETE → conditional PUT with If-None-Match: *) so only one RGW instance rebuilds a table at a time. Adds build-state metadata stored as JSON in LanceDB table metadata. Introduces the GetIndexStats REST operation. Adds 5 new config options in rgw.yaml.in (threshold, stats interval, lease, lock TTL, index type). Touches IAM policy, auth, and frontend to wire up the new operation. Commit 2 — a0ae2df — Rename numIndices → numIndexSegments + tests (240 insertions) Renames the misleading field numIndices to numIndexSegments in GetIndexStats response and internal structs. Adds 231 lines of Python test code in s3vector_test.py covering index stats and background rebuild behavior. Commit 3 — 77c9424 — SDK extras rename fix (2 insertions, 2 deletions) Companion fix to commit 2 — updates the numIndices → numIndexSegments rename in the boto3 SDK extras JSON file that was missed. Commit 4 — 85461b1 — Replace message queue with per-table mutation counters (458 insertions) Major architectural change. Replaces the notification message queue with atomic per-table insert_count / delete_count counters. Eliminates two levels of message loss (queue overflow and rate-limit discard). The counters provide a more reliable indication of when a rebuild is needed. Adds new config options (rgw_s3vector_index_unindexed_threshold, ratio-based threshold). Adds 200 lines of new test code for counter-based rebuild triggering. Commit 5 — dbfb19c — Configurable worker thread pool + thread safety (108 insertions) Replaces the single notif-worker thread with a configurable pool (rgw_s3vector_background_workers, default 1). Adds active_builds_mutex to protect the active_builds set for concurrent coroutine access. Fixes a lock-ordering bug where global_delete_count was read/written outside the distributed lock. Adds observability log messages. New config option for worker count. Commit 6 — 7aed746 — restore_counters() helper (35 insertions) Adds restore_counters(table_name, inserts, deletes) — returns mutation counters back to the table's atomics on error paths. Prevents counter loss when process_table fails after consuming the counters but before completing the rebuild. Commit 7 — 07fc3e9 — Lock heartbeat / main-loop refresh (184 insertions) Adds lock heartbeat to prevent false stale-lock detection during long rebuilds. Introduces active_lock_t struct and active_locks map tracking per-lock state (token, etag, last_refresh, lock_lost flag). Adds refresh_lock_object() using conditional overwrite with if_match=current_etag. refresh_active_locks() runs every main-loop iteration, refreshing locks older than TTL/3. Fixes spawn flood bug (adds active_builds.count() check). Fixes double-decrement of active_rebuild_count. Commit 8 — e742787 — Background process tests via log scanning (160 insertions) Adds/rewrites Python tests that validate the background rebuild process by scanning RGW log files for expected entries (lock acquisition, rebuild triggers, completion). Marked as WIP — tests will be converted to use REST APIs instead of log scanning. Commit 9 — 8f1331e — Adapt to feature branch API changes (12 insertions) Adapts to signature changes from the main feature branch PR ceph#66066: connect(), open_table(), and open_table_with_session_handle() now accept driver, user, and tenant parameters for the RGW storage backend. Updates call sites in background process and GetIndexStats. Commit 10 — 8247292 — 5 fixes to the background main loop (178 insertions) 1. Makes async_sleep(idle_sleep) unconditional (fixes busy loop). 2. Adds named return constants (RESULT_SUCCESS, RESULT_SKIPPED, etc.). 3. Distinguishes permanent vs transient LanceDB errors — only calls restore_counters on transient errors. 4. Adds minimum row threshold (rgw_s3vector_index_min_rows, default 256) to skip rebuilds on tiny tables. 5. Adds warning log in get_vector_index_stats before freeing error messages. 6. Fixes load_bucket_for_lock to use regular S3 bucket instead of Indexless vector bucket. Signed-off-by: gal salomon <[email protected]>
8247292 to
7dc219d
Compare
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
the lancedb engine is kind of black box. Users can see the query parameters and the results, but not how the query was executed. This makes it hard to diagnose performance issues, especially when the query falls back to brute-force scan instead of using an index.
the commit adds query plan observability to the S3 Vectors QueryVectors API. Users can inspect the DataFusion physical execution plan to diagnose index usage, brute-force fallback, hybrid scans, and pre-filter behavior,no need to parse logs.
src/rgw/lancedb-c/
- src/query.rs — 2 new Rust FFI functions:
- lancedb_query_explain_plan() — for scalar/filter queries
- lancedb_vector_query_explain_plan() — for vector queries
- Both reconstruct the Rust query from stored parameters, call .explain_plan(verbose).await, and return the plan as a C string. Non-consuming (*const) — the query remains valid for subsequent execute().
- include/lancedb.h — C declarations for both functions with const pointer semantics and lancedb_free_string() cleanup contract.
src/rgw/rgw_s3vector.h
- Added bool explain_plan and bool explain_only to query_vectors_t
- Added std::optional<std::string> query_plan to query_vectors_reply_t
src/rgw/rgw_s3vector.cc
- Request parsing: Decodes explainPlan and explainOnly from JSON; conditionally emits them in dump()
- Response formatting: Emits queryPlan when present; conditionally omits distanceMetric/vectors for explain-only responses
- Execution logic (line ~2643): Calls lancedb_vector_query_explain_plan() before execute(). If explain_only, skips execution entirely and returns plan + distance metric only. Failure is non-fatal — logs
warning and continues without the plan.
src/test/rgw/s3vectors/s3vector_test.py
- 10 new tests, all marked @pytest.mark.explain_plan_test:
a. test_explain_only_returns_plan_without_results
b. test_explain_plan_returns_plan_with_results
c. test_normal_query_has_no_plan
d. test_explain_plan_brute_force_scan — KNNVectorDistance, no ANNSubIndex
e. test_explain_plan_vector_index_used — ANNSubIndex/ANNIvfPartition after index build
f. test_explain_plan_topk_visible — fetch=K in plan
g. test_explain_plan_distance_metric — L2 vs cosine in plan
h. test_explain_plan_prefilter_on_filterable_column — FilterExec position below KNNVectorDistance, full_filter= in LanceRead
i. test_explain_plan_hybrid_scan — both ANN + KNN nodes with mixed indexed/unindexed data
j. test_explain_plan_ivf_nprobes — nprobes= in ANNIvfPartition
Signed-off-by: gal salomon <[email protected]>
…resume
Adds a per-RGW-instance observability layer for the S3 Vectors background index-rebuild worker, exposes it through a Ceph admin REST endpoint, adds a runtime pause/resume knob, and migrates the integration
tests off log-scraping onto the new structured API.
src/rgw/rgw_s3vector_background.h (+63)
Public status API in namespace rgw::s3vector: new structs active_build_info_t, background_status_t (identity + live counts + 8 aggregate counters + active-build list), and rebuild_event_info_t; plus free
functions get_background_status() and get_rebuild_events(since_epoch, bucket_filter). Adds <vector> / common/ceph_time.h.
src/rgw/rgw_s3vector_background.cc (+261/−~25)
- rebuild_event_t (enum SPAWN/FINISH/LIMIT_REACHED/LOCK_REFRESH/LOCK_LOST/LOCK_REFRESH_FAIL) + background_counters_t (8 atomics).
- In-memory ring buffer (event_log_ deque under its own mutex) bounded by rgw_s3vector_event_log_size, written via record_event(), which is additive to existing log lines. Wired at six call sites
(limit-reached, spawn, finish-with-duration/result, and the three lock outcomes). peak_active_rebuilds uses a CAS loop.
- Caches daemon identity in init() (host_id, dash-split instance_id).
- Pause switch: shutdown promoted to std::atomic<bool>; when rgw_s3vector_max_concurrent_rebuilds == 0 the worker skips the table scan (so pending mutation counters are not consumed — lossless) but still
drains control messages and calls refresh_active_locks(), keeping an in-flight build's distributed lock alive.
- build_state_t gains persisted last_rebuild_completed_at / last_rebuild_duration_ms (dump/decode_json); active_lock_t gains start_time / refresh_count.
- get_background_status() / get_rebuild_events() methods + namespace-level wrappers (null-safe when manager uninitialized).
src/rgw/rgw_rest_s3vector.h (+29) / .cc (+135)
New admin handler RGWHandler_VectorBucket : RGWHandler_Auth_S3 and RGWRESTMgr_VectorBucket, mounted at /admin/vectorbucket. RGWOp_VectorBucket_Rebuild_Status (gated by buckets=read cap) serves ?rebuild=true,
emitting JSON (instance / status / counters / active_builds / rebuild_events), honoring vectorbucket= and since= query params. s3v_iso8601() helper formats timestamps to millisecond UTC. Structured for a
future ?session=true op.
src/rgw/rgw_appmain.cc (+2)
Registers vectorbucket admin resource.
src/common/options/rgw.yaml.in (+20/−2)
- New option rgw_s3vector_event_log_size (uint, default 1000, min 1).
- rgw_s3vector_max_concurrent_rebuilds: min lowered 1 → 0 with docs describing 0 = pause (mutation counts preserved across pause).
Tests
src/test/rgw/s3vectors/s3vector_test.py (+~200/−~118)
Removes all log-scraping (get_rgw_log_path, parse_rebuild_log_events, parse_lock_refresh_events). Adds _grant_admin_caps(), get_rebuild_admin_status() (stdlib urllib + botocore S3SigV4Auth), and
wait_for_max_concurrent_rebuilds(). Migrates the concurrency and rebuild tests to the admin API, and fixes the flaky test_background_index_rebuild via a deterministic pause→load→snapshot→resume flow.
Signed-off-by: gal salomon <[email protected]>
ea5d4ff to
2359632
Compare
|
this was automatically closed because |
Purpose:
Adds automatic background vector-index rebuilding for S3 Vector tables. When put_vectors or delete_vectors operations cause the number of unindexed rows to exceed a configurable threshold, the background manager rebuilds the vector index asynchronously. Users get immediate responses; index quality is maintained transparently — aligned with how AWS S3 Vectors handles index optimization.
Main Components
Background Manager (rgw_s3vector_background.cc): A single worker thread (notif-worker) consumes notifications (TODO multiple worker-threads) and spawns per-table rebuild coroutines.
Rate-limits stats checks per table (default 30s) to avoid overhead during write bursts.
Distributed Lock Protocol: Three-step S3 conditional-write protocol (GET → conditional DELETE → conditional PUT with If-None-Match: *) ensures only one RGW instance rebuilds a given table at a time. Per-acquisition random tokens (32-char alphanumeric) provide container-safe ownership verification.
Build State Metadata: Stored as JSON in LanceDB table metadata for observability. Records builder identity, start time, and lease duration. Used for stale builds that caused by crash, (exceeding lease TTL) are detected and reset.
Configuration (rgw.yaml.in): Five new options — unindexed threshold (256), stats interval (30s), build lease (600s), lock TTL (900s), and index type (auto/ivf_pq/ivf_hnsw_pq/ivf_hnsw_sq/ivf_flat).
(WIP)the current re-build-index system has the following drawbacks
per each insert/delete request, the current system does not count the number of rows, it pushes a single message into queue per request (a single request may contain multiple rows, 1 to 500 rows),
the insert/delete row count is not reflected in the message queue.
the process-tables calls consume-all that drains the message queue, and start rebuilding the index.
The re-build-index process is rate-limited(in order not to launch frequent re-build), messages that are pushed into the queue during the rate-limit window are silently dropped, and never processed.
so,there are two levels of message loss:
replacing the message-queue with counter per table provides better indication on re-build-index status.
there is no issue with queue overflow, and the rate-limit discard is not an issue since the counter is incremented per request.
the counter can be save on table-metadata(using the existing JSON structure that contain the build status) per each re-build process.
it should be noted that the new counters (partially consistent) are not accurate, only provides an indication.
the get-index-stat provides a true status per the insert-rows, it is not sufficient per delete-rows(* it is not reflected in non-indexed number).
*the main thing.
the current task-execution architecture (token-waiter with process-tables) enforce tasks-in-batch, i.e the background system waits for all tasks to complete, thus the slowest re-build delays other re-build that could run in parallel.
in a live system where there are many tables/indexes of different sizes, and rows are get in and out, it is not-efficient to wait for all re-builds to complete before starting the next required re-build.
this issue has an impact on session handling, SESSION_CREATE and SESSION_DELETE messages are also stuck in the queue,
a new vector bucket created during the wait won't get its LanceDB session until the huge index finishes.
the solution for the work-in-a-batch issue, is NOT to work in batch, but to spawn a task when there is a need and there is an open slot.
TODO
num_indexed_rowswithout increasingnum_unindexed_rows, deletion alone would never cross the threshold and never trigger a rebuild.main feature branch : #66066
Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.