store: index ops take WriteTransaction, mutations batch properly

Index functions now take &WriteTransaction instead of &Database,
allowing callers to batch multiple index operations in a single
transaction. Store mutations (upsert, delete, rename, etc.) now
begin_write/commit their own transactions, ensuring atomicity.

- replay_relations uses single txn for all relation indexing
- Store::db() exposes Database for callers needing txn control
- Convenience wrappers open their own txn for simple cases

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-13 21:44:20 -04:00
parent 2548ca059d
commit 4696bb8b7d
5 changed files with 151 additions and 144 deletions

View file

@ -354,12 +354,14 @@ impl Store {
}
}
// Index relations directly (no Vec intermediate)
// Index relations directly (single transaction)
if let Some(db) = &self.db {
let txn = db.begin_write()?;
for rel in by_uuid.into_values() {
if rel.deleted { continue; }
index::index_relation(db, &rel.source, &rel.target, rel.strength, rel.rel_type as u8)?;
index::index_relation(&txn, &rel.source, &rel.target, rel.strength, rel.rel_type as u8)?;
}
txn.commit()?;
}
Ok(())
}