RolloutStore::dataset should be interior-mutable so merge/compact can refresh the handle without an exclusive lock

未关闭
#198 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@lucyge2022 已经在做这个了。

开始于 2026年8月10日。

  • #236 来自 @lucyge2022 —— 未关闭

评估

难度
5/5
预计耗时
一周以上
新手友好度
42/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
冷清
技术栈
rust
领域
backend, databases

调研方向

从 crates/lance-context-core/src/rollout_store.rs 开始,检查 Dataset 的所有权及其大约 52 个调用点,然后审查现有的 merge 和 compact 路径。将提议的共享句柄方案与当前的锁定流程进行比较,并运行 crates/lance-context-core/tests/wal_merge_concurrency.rs。当 merge、compact 和 schema evolution 在没有 store 写锁的情况下接收 self,并新增一个 compact 与 append 之间的并发测试时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

enhancement

Context

Follow-up to the WAL-merge write-lock stall (a merge held the store's write lock for ~17s, blocking every concurrent add). That is being fixed by splitting the merge into a &self prepare phase (seal + read every flushed generation — the expensive part) and a short &mut self commit phase, so callers hold the exclusive lock only for the commit.

That fix removes the stall, but it works around the underlying constraint rather than removing it. This issue tracks removing it.

The constraint

RolloutStore owns its Dataset by value:

// crates/lance-context-core/src/rollout_store.rs
pub struct RolloutStore {
    dataset: Dataset,
    ...
}

Dataset's mutating operations are &mut self not because they mutate in place, but because they rebind the whole struct at the end:

// lance-7.0.0/src/dataset.rs:919
pub async fn append(&mut self, ...) -> Result<()> {
    let new_dataset = InsertBuilder::new(...).execute_stream(...).await?;
    *self = new_dataset;      // whole-struct replacement
    Ok(())
}

checkout_latest, add_columns and compact_files follow the same pattern. So the &mut requirement propagates outward — append_merged_batches → commit_merge → merge_own_shard_if_ready → cleanup_own_shard → and finally to every caller, which must take RwLock::write().

The result is that an exclusive lock is required for reasons that have nothing to do with mutual exclusion of the work itself. A merge appends to the base table and drains sealed generations; add writes the active memtable. They touch disjoint data. The lock exists only to satisfy the borrow checker.

Why this still bites after the split fix

The prepare/commit split shrinks the exclusive section but does not eliminate it, and it pushes the lock discipline onto callers:

  • Callers must remember the two-phase dance; a caller that just calls cleanup_own_shard() under one write lock silently reintroduces the stall. That is an easy mistake to make and there is no compile-time signal.
  • The commit phase still blocks appends for the duration of the base-table append. Small compared to reading N generations from object storage, but non-zero and proportional to merged data volume.
  • compact() has the identical shape (compact_files(&mut self.dataset, ...) then a reload) and still takes the write lock for its whole duration.

Proposal

Make the base dataset interior-mutable, e.g.:

dataset: Arc<RwLock<Dataset>>,   // or arc_swap::ArcSwap<Dataset>

Then merge, compact, and schema evolution can all take &self, refresh the shared handle when they commit, and never need an exclusive lock on the store. Merge-vs-merge exclusion (which is genuinely needed — two concurrent merges would read the same generations and append them twice) becomes an explicit, narrow mutex rather than a side effect of &mut.

ArcSwap is probably the better fit than RwLock: reads are the overwhelming majority, the value is cheap to clone (every Dataset field is already an Arc), and writers only ever replace the whole value.

Cost

~52 self.dataset call sites in rollout_store.rs, of which only 4 are assignments and 1 is a &mut borrow — the rest are reads (uri(), schema(), manifest(), object_store(), ...). Mechanical, but broad enough that it should not ride along with a targeted stall fix; it deserves its own review and its own soak.

ContextStore and DatagenStore have the same shape and would want the same treatment.

Acceptance

  • merge, compact and schema evolution take &self.
  • No caller needs RwLock::write() on the store to run a background maintenance task.
  • The existing concurrency tests (crates/lance-context-core/tests/wal_merge_concurrency.rs) still pass, plus a new one asserting compact does not block appends.
主要语言
Rust
星标
89
派生
21
平均合并
2 小时 6 分钟
30 天内合并 PR
435

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

lance-format/lance-context 的其他 Issue

查看 lance-format/lance-context 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。