Skip to content

Commit db2f19f

Browse files
committed
refactor(nodedb): propagate StorageEngineSync bound across all NodeDbLite impls
Now that NodeDbLite holds array CRDT sync state that requires synchronous storage access, every impl block must carry StorageEngine + StorageEngineSync. Updates all remaining impl blocks (batch, collections, definitions, diagnostic, graph_rag, health, sync_delegate, trait_impl) to match. Additional changes bundled with the mechanical bound update: - health: expose public storage() accessor for benchmark compression-ratio measurement via backend-specific methods like db_size_bytes() - trait_impl: use cfg_attr async_trait / async_trait(?Send) to keep the NodeDb trait implementation compiling on WASM targets
1 parent cf95932 commit db2f19f

11 files changed

Lines changed: 35 additions & 26 deletions

File tree

nodedb-lite/src/nodedb/batch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use nodedb_types::Namespace;
44
use nodedb_types::error::{NodeDbError, NodeDbResult};
55

66
use super::{LockExt, NodeDbLite};
7-
use crate::storage::engine::StorageEngine;
7+
use crate::storage::engine::{StorageEngine, StorageEngineSync};
88

9-
impl<S: StorageEngine> NodeDbLite<S> {
9+
impl<S: StorageEngine + StorageEngineSync> NodeDbLite<S> {
1010
/// Batch insert vectors — O(1) CRDT delta export instead of O(N).
1111
///
1212
/// Use this for bulk loading (cold-start hydration, benchmark setup, imports).

nodedb-lite/src/nodedb/collection/bulk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use nodedb_types::value::Value;
1010

1111
use super::super::convert::value_to_loro;
1212
use super::super::{LockExt, NodeDbLite};
13-
use crate::storage::engine::StorageEngine;
13+
use crate::storage::engine::{StorageEngine, StorageEngineSync};
1414

15-
impl<S: StorageEngine> NodeDbLite<S> {
15+
impl<S: StorageEngine + StorageEngineSync> NodeDbLite<S> {
1616
/// Bulk update documents matching a predicate.
1717
///
1818
/// Scans all documents, evaluates `ScanFilter` predicates, and applies

nodedb-lite/src/nodedb/collection/ddl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use nodedb_types::error::{NodeDbError, NodeDbResult};
44

55
use super::super::{LockExt, NodeDbLite};
6-
use crate::storage::engine::StorageEngine;
6+
use crate::storage::engine::{StorageEngine, StorageEngineSync};
77

88
/// Collection metadata stored in redb.
99
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
@@ -18,7 +18,7 @@ pub struct CollectionMeta {
1818
pub config_json: Option<String>,
1919
}
2020

21-
impl<S: StorageEngine> NodeDbLite<S> {
21+
impl<S: StorageEngine + StorageEngineSync> NodeDbLite<S> {
2222
/// Create a collection with optional schema.
2323
///
2424
/// If the collection already exists, returns Ok (idempotent).

nodedb-lite/src/nodedb/collection/import.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
use nodedb_types::error::{NodeDbError, NodeDbResult};
44

55
use super::super::{LockExt, NodeDbLite};
6-
use crate::storage::engine::StorageEngine;
6+
use crate::storage::engine::{StorageEngine, StorageEngineSync};
77

8-
impl<S: StorageEngine> NodeDbLite<S> {
8+
impl<S: StorageEngine + StorageEngineSync> NodeDbLite<S> {
99
/// Import documents from NDJSON (newline-delimited JSON) text.
1010
///
1111
/// Each line is a JSON object. The "id" field is used as document ID;

nodedb-lite/src/nodedb/collection/transaction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use nodedb_types::value::Value;
1313
use super::super::convert::value_to_loro;
1414
use super::super::{LockExt, NodeDbLite};
1515
use crate::engine::crdt::engine::{CrdtBatchOp, CrdtField};
16-
use crate::storage::engine::StorageEngine;
16+
use crate::storage::engine::{StorageEngine, StorageEngineSync};
1717

1818
/// A single operation in a transaction batch.
1919
#[derive(Debug, Clone)]
@@ -29,7 +29,7 @@ pub enum TransactionOp {
2929
},
3030
}
3131

32-
impl<S: StorageEngine> NodeDbLite<S> {
32+
impl<S: StorageEngine + StorageEngineSync> NodeDbLite<S> {
3333
/// Execute a batch of operations atomically.
3434
///
3535
/// **Atomicity model**: all operations are validated upfront. If any

nodedb-lite/src/nodedb/definitions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use nodedb_types::error::{NodeDbError, NodeDbResult};
1313

1414
use super::NodeDbLite;
15-
use crate::storage::engine::StorageEngine;
15+
use crate::storage::engine::{StorageEngine, StorageEngineSync};
1616

1717
/// A stored function definition (mirrors Origin's StoredFunction).
1818
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
@@ -69,7 +69,7 @@ pub struct LiteProcedureParam {
6969

7070
// ── Generic CRUD helpers ────────────────────────────────────────────────
7171

72-
impl<S: StorageEngine> NodeDbLite<S> {
72+
impl<S: StorageEngine + StorageEngineSync> NodeDbLite<S> {
7373
/// Store a definition in the local catalog under `{prefix}:{name}`.
7474
async fn put_definition(
7575
&self,
@@ -137,7 +137,7 @@ impl<S: StorageEngine> NodeDbLite<S> {
137137

138138
// ── Type-specific convenience methods ───────────────────────────────────
139139

140-
impl<S: StorageEngine> NodeDbLite<S> {
140+
impl<S: StorageEngine + StorageEngineSync> NodeDbLite<S> {
141141
/// Store a function definition in the local catalog.
142142
pub async fn put_function(&self, func: &LiteStoredFunction) -> NodeDbResult<()> {
143143
self.put_definition("function", &func.name, func).await

nodedb-lite/src/nodedb/diagnostic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1414
use serde::Serialize;
1515

16-
use crate::storage::engine::StorageEngine;
16+
use crate::storage::engine::{StorageEngine, StorageEngineSync};
1717

1818
use super::core::NodeDbLite;
1919
use super::health::HealthStatus;
@@ -67,7 +67,7 @@ pub struct BuildInfo {
6767
pub profile: &'static str,
6868
}
6969

70-
impl<S: StorageEngine> NodeDbLite<S> {
70+
impl<S: StorageEngine + StorageEngineSync> NodeDbLite<S> {
7171
/// Generate a diagnostic dump suitable for bug reports.
7272
///
7373
/// Contains NO user data, NO document contents, NO embeddings.

nodedb-lite/src/nodedb/graph_rag.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use nodedb_types::id::NodeId;
1313
use nodedb_types::result::SearchResult;
1414

1515
use super::{LockExt, NodeDbLite};
16-
use crate::storage::engine::StorageEngine;
16+
use crate::storage::engine::{StorageEngine, StorageEngineSync};
1717

1818
/// GraphRAG fusion parameters.
1919
pub struct GraphRagParams<'a> {
@@ -47,7 +47,7 @@ impl Default for GraphRagParams<'_> {
4747
}
4848
}
4949

50-
impl<S: StorageEngine> NodeDbLite<S> {
50+
impl<S: StorageEngine + StorageEngineSync> NodeDbLite<S> {
5151
/// GraphRAG fusion: vector search → graph expansion → RRF merge.
5252
///
5353
/// 1. Vector search returns `vector_k` candidates by embedding similarity.
@@ -189,7 +189,7 @@ fn search_results_to_ranked(
189189
.collect()
190190
}
191191

192-
impl<S: StorageEngine> NodeDbLite<S> {
192+
impl<S: StorageEngine + StorageEngineSync> NodeDbLite<S> {
193193
/// Hybrid search: vector similarity + BM25 text relevance fused via RRF.
194194
///
195195
/// 1. Vector search returns `vector_k` candidates by embedding similarity.

nodedb-lite/src/nodedb/health.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use serde::Serialize;
1212

1313
use crate::memory::{EngineId, PressureLevel};
14-
use crate::storage::engine::StorageEngine;
14+
use crate::storage::engine::{StorageEngine, StorageEngineSync};
1515

1616
use super::core::NodeDbLite;
1717
use super::lock_ext::LockExt;
@@ -115,7 +115,15 @@ fn engine_memory(gov: &crate::memory::MemoryGovernor, id: EngineId) -> EngineMem
115115
}
116116
}
117117

118-
impl<S: StorageEngine> NodeDbLite<S> {
118+
impl<S: StorageEngine + StorageEngineSync> NodeDbLite<S> {
119+
/// Borrow the underlying storage engine.
120+
///
121+
/// Public so benchmark code can call backend-specific methods like
122+
/// `RedbStorage::db_size_bytes()` for compression-ratio measurement.
123+
pub fn storage(&self) -> &S {
124+
&self.storage
125+
}
126+
119127
/// Get a structured health report.
120128
///
121129
/// This is a cheap, non-blocking call — reads atomic counters and lock-free state.

nodedb-lite/src/nodedb/sync_delegate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//! `SyncDelegate` implementation — bridges the sync transport to NodeDbLite's engines.
22
3-
use crate::storage::engine::StorageEngine;
3+
use crate::storage::engine::{StorageEngine, StorageEngineSync};
44

55
use super::core::NodeDbLite;
66

77
#[cfg(not(target_arch = "wasm32"))]
88
#[async_trait::async_trait]
9-
impl<S: StorageEngine> crate::sync::SyncDelegate for NodeDbLite<S> {
9+
impl<S: StorageEngine + StorageEngineSync> crate::sync::SyncDelegate for NodeDbLite<S> {
1010
fn pending_deltas(&self) -> Vec<crate::engine::crdt::engine::PendingDelta> {
1111
self.pending_crdt_deltas().unwrap_or_default()
1212
}

0 commit comments

Comments
 (0)