nodedb-lite 0.1.0

Embedded edge client for NodeDB — offline vector search, graph traversal, and CRDT sync
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
// SPDX-License-Identifier: Apache-2.0
//! MetaOp dispatch for the Lite physical visitor.

use nodedb_physical::physical_plan::MetaOp;

use crate::error::LiteError;
use crate::query::engine::LiteQueryEngine;
use crate::query::meta_ops;
use crate::storage::engine::StorageEngine;

use super::LitePhysicalFut;

pub(super) fn dispatch<'a, S: StorageEngine + 'a>(
    engine: &'a LiteQueryEngine<S>,
    permit: Option<&'a crate::engine::fts::coordinator::TextMutationPermit>,
    op: &MetaOp,
) -> Result<LitePhysicalFut<'a>, LiteError> {
    match op {
        MetaOp::CreateSnapshot => Ok(Box::pin(async move {
            meta_ops::handle_create_snapshot(engine).await
        })),
        MetaOp::Compact => Ok(Box::pin(
            async move { meta_ops::handle_compact(engine).await },
        )),
        MetaOp::Checkpoint => Ok(Box::pin(async move {
            meta_ops::handle_checkpoint(engine).await
        })),
        MetaOp::UnregisterCollection {
            tenant_id,
            name,
            purge_lsn,
            // Lite is single-process/single-core: it always owns and reclaims
            // its own on-disk L1 files, so the Control-Plane fan-out flag
            // (which selects exactly one core to unlink the shared files) does
            // not apply here — this core always fully reclaims.
            reclaim_l1_files: _,
        } => {
            let tid = *tenant_id;
            let n = name.clone();
            let lsn = *purge_lsn;
            Ok(Box::pin(async move {
                meta_ops::lifecycle::handle_unregister_collection_coordinated(
                    engine, permit, tid, &n, lsn,
                )
                .await
            }))
        }
        MetaOp::UnregisterMaterializedView { tenant_id, name } => {
            let tid = *tenant_id;
            let n = name.clone();
            Ok(Box::pin(async move {
                meta_ops::handle_unregister_materialized_view(engine, tid, &n).await
            }))
        }
        // Lite's convert probes its own per-engine stores (CRDT, strict) and
        // decodes each with that store's schema, so the plan-level source
        // mode carries nothing Lite acts on.
        MetaOp::ConvertCollection {
            collection,
            target_type,
            schema_json,
            source_storage_mode: _source_storage_mode,
        } => {
            let col = collection.clone();
            let tt = target_type.clone();
            let sj = schema_json.clone();
            Ok(Box::pin(async move {
                meta_ops::lifecycle::handle_convert_collection_coordinated(
                    engine,
                    permit,
                    col.as_str(),
                    &tt,
                    &sj,
                )
                .await
            }))
        }
        MetaOp::RegisterContinuousAggregate { def } => {
            let d = def.clone();
            Ok(Box::pin(async move {
                meta_ops::handle_register_continuous_aggregate(engine, d).await
            }))
        }
        MetaOp::UnregisterContinuousAggregate { name } => {
            let n = name.clone();
            Ok(Box::pin(async move {
                meta_ops::handle_unregister_continuous_aggregate(engine, &n).await
            }))
        }
        MetaOp::ListContinuousAggregates => Ok(Box::pin(async move {
            meta_ops::handle_list_continuous_aggregates(engine).await
        })),
        MetaOp::ContinuousAggregatesRegistered => Ok(Box::pin(async move {
            meta_ops::handle_continuous_aggregates_registered().await
        })),
        // Lite folds each flush into its aggregates as the flush runs and
        // never applies a refresh cut, so no cut exists to wait for.
        MetaOp::AwaitContinuousAggregateRefresh {
            collection,
            name,
            refresh_id,
        } => Err(LiteError::Unsupported {
            detail: format!(
                "MetaOp::AwaitContinuousAggregateRefresh of '{name}' on '{collection}' \
                 (refresh {refresh_id}): refresh cuts are not supported in Lite"
            ),
        }),
        MetaOp::ApplyContinuousAggRetention => Ok(Box::pin(async move {
            meta_ops::handle_apply_continuous_agg_retention(engine).await
        })),
        MetaOp::QueryAggregateWatermark { aggregate_name } => {
            let n = aggregate_name.clone();
            Ok(Box::pin(async move {
                meta_ops::handle_query_aggregate_watermark(engine, &n).await
            }))
        }
        MetaOp::QueryLastValues { collection } => {
            let col = collection.clone();
            Ok(Box::pin(async move {
                meta_ops::handle_query_aggregate_last_values(engine, col.as_str()).await
            }))
        }
        MetaOp::QueryLastValue {
            collection,
            series_id,
        } => {
            let col = collection.clone();
            let sid = *series_id;
            Ok(Box::pin(async move {
                meta_ops::handle_query_aggregate_last_value(engine, col.as_str(), sid).await
            }))
        }
        MetaOp::TemporalPurgeEdgeStore {
            tenant_id,
            collection,
            cutoff_system_ms,
        } => {
            let tid = *tenant_id;
            let col = collection.clone();
            let cut = *cutoff_system_ms;
            Ok(Box::pin(async move {
                meta_ops::handle_temporal_purge_edge_store(engine, tid, col.as_str(), cut).await
            }))
        }
        MetaOp::TemporalPurgeDocumentStrict {
            tenant_id,
            collection,
            cutoff_system_ms,
        } => {
            let tid = *tenant_id;
            let col = collection.clone();
            let cut = *cutoff_system_ms;
            Ok(Box::pin(async move {
                meta_ops::handle_temporal_purge_document_strict(engine, tid, col.as_str(), cut)
                    .await
            }))
        }
        MetaOp::TemporalPurgeColumnar {
            tenant_id,
            collection,
            cutoff_system_ms,
            aggregates,
        } => {
            let tid = *tenant_id;
            let col = collection.clone();
            let cut = *cutoff_system_ms;
            let aggs = aggregates.clone();
            Ok(Box::pin(async move {
                meta_ops::require_registered_aggregates(engine, "TemporalPurgeColumnar", &aggs)?;
                meta_ops::handle_temporal_purge_columnar(engine, tid, col.as_str(), cut).await
            }))
        }
        MetaOp::TemporalPurgeCrdt {
            tenant_id,
            collection,
            cutoff_system_ms,
        } => {
            let tid = *tenant_id;
            let col = collection.clone();
            let cut = *cutoff_system_ms;
            Ok(Box::pin(async move {
                meta_ops::handle_temporal_purge_crdt(engine, tid, col.as_str(), cut).await
            }))
        }
        MetaOp::TemporalPurgeArray {
            tenant_id,
            array_id,
            cutoff_system_ms,
        } => {
            let tid = *tenant_id;
            let aid = array_id.clone();
            let cut = *cutoff_system_ms;
            Ok(Box::pin(async move {
                meta_ops::handle_temporal_purge_array(engine, tid, &aid, cut).await
            }))
        }
        MetaOp::EnforceTimeseriesRetention {
            collection,
            max_age_ms,
            aggregates,
        } => {
            let col = collection.clone();
            let age = *max_age_ms;
            let aggs = aggregates.clone();
            Ok(Box::pin(async move {
                meta_ops::require_registered_aggregates(
                    engine,
                    "EnforceTimeseriesRetention",
                    &aggs,
                )?;
                meta_ops::handle_enforce_timeseries_retention(engine, col.as_str(), age).await
            }))
        }
        MetaOp::AlterArray {
            array_id,
            audit_retain_ms,
            minimum_audit_retain_ms,
        } => {
            let aid = array_id.clone();
            let arm = *audit_retain_ms;
            let marm = *minimum_audit_retain_ms;
            Ok(Box::pin(async move {
                meta_ops::handle_alter_array(engine, &aid, arm, marm).await
            }))
        }
        MetaOp::PutSynonymGroup {
            tenant_id,
            record_json,
        } => {
            let tid = *tenant_id;
            let rj = record_json.clone();
            Ok(Box::pin(async move {
                meta_ops::handle_put_synonym_group(engine, tid, &rj).await
            }))
        }
        MetaOp::DeleteSynonymGroup { tenant_id, name } => {
            let tid = *tenant_id;
            let n = name.clone();
            Ok(Box::pin(async move {
                meta_ops::handle_delete_synonym_group(engine, tid, &n).await
            }))
        }
        MetaOp::RebuildIndex {
            collection,
            index_name,
            concurrent,
        } => {
            let col = collection.clone();
            let idx = index_name.clone();
            let conc = *concurrent;
            Ok(Box::pin(async move {
                meta_ops::handle_rebuild_index(engine, col.as_str(), idx.as_deref(), conc).await
            }))
        }
        MetaOp::QueryCollectionSize { tenant_id, name } => {
            let tid = *tenant_id;
            let n = name.clone();
            Ok(Box::pin(async move {
                meta_ops::handle_query_collection_size(engine, tid, &n).await
            }))
        }
        // ── Distributed ops implemented on Lite ─────────────────────────────
        MetaOp::WalAppend { payload } => {
            let bytes = payload.clone();
            let storage = engine.storage.clone();
            Ok(Box::pin(async move {
                meta_ops::handle_wal_append(&storage, &bytes).await
            }))
        }
        MetaOp::Cancel { target_request_id } => {
            let rid = *target_request_id;
            let registry = engine.cancellation.clone();
            Ok(Box::pin(
                async move { meta_ops::handle_cancel(&registry, rid) },
            ))
        }
        MetaOp::TransactionBatch { plans, txn_id: _ } => {
            let plans = plans.clone();
            Ok(Box::pin(async move {
                meta_ops::handle_txn_batch(engine, &plans).await
            }))
        }
        MetaOp::CalvinExecuteStatic { plans, .. } => {
            let plans = plans.clone();
            Ok(Box::pin(async move {
                meta_ops::handle_calvin_static(engine, &plans).await
            }))
        }
        MetaOp::CalvinExecutePassive { .. } => {
            Ok(Box::pin(
                async move { meta_ops::handle_calvin_passive().await },
            ))
        }
        MetaOp::CalvinExecuteActive { plans, .. } => {
            let plans = plans.clone();
            Ok(Box::pin(async move {
                meta_ops::handle_calvin_active(engine, &plans).await
            }))
        }
        // ── Origin-only ops that Lite's plan converter never emits ───────────
        // A Lite write has its final outcome once it commits, so a
        // consistent cut needs no wait here.
        MetaOp::CreateTenantSnapshot {
            tenant_id,
            cut_watermark: _,
            cut_capture,
            arrays: _,
        } => {
            if cut_capture.is_some() {
                return Err(LiteError::Unsupported {
                    detail: "CreateTenantSnapshot with cut_capture is a cluster backup barrier \
                             capture; unsupported on single-node Lite"
                        .into(),
                });
            }
            let tid = *tenant_id;
            let storage = engine.storage.clone();
            Ok(Box::pin(async move {
                meta_ops::handle_create_tenant_snapshot(&*storage, tid).await
            }))
        }
        MetaOp::RestoreTenantSnapshot {
            tenant_id,
            snapshot,
            ..
        } => {
            let tid = *tenant_id;
            let snap = snapshot.clone();
            let storage = engine.storage.clone();
            Ok(Box::pin(async move {
                meta_ops::handle_restore_tenant_snapshot(&*storage, tid, &snap).await
            }))
        }
        MetaOp::PurgeTenant { tenant_id } => {
            let tid = *tenant_id;
            let storage = engine.storage.clone();
            Ok(Box::pin(async move {
                meta_ops::handle_purge_tenant(&*storage, tid).await
            }))
        }

        // Per-core transaction staging overlay. These address the Origin Data
        // Plane's `CoreLoop`-owned `TxnOverlay`, which buffers not-yet-durable
        // writes per shard core. Lite executes transactions directly against
        // its single local store (see `nodedb/collection/transaction.rs`) and
        // has no per-core overlay to stage into, mark, or roll back, so its
        // planner never emits these.
        MetaOp::StageWrite { .. } => Err(LiteError::Unsupported {
            detail: "StageWrite targets the Data Plane per-core transaction overlay; \
                     unsupported on the single-node Lite engine"
                .into(),
        }),
        MetaOp::DropTxnOverlay { .. } => Err(LiteError::Unsupported {
            detail: "DropTxnOverlay releases a Data Plane per-core transaction overlay; \
                     unsupported on the single-node Lite engine"
                .into(),
        }),
        MetaOp::MarkSavepoint { .. } => Err(LiteError::Unsupported {
            detail: "MarkSavepoint marks the Data Plane per-core overlay undo journals; \
                     unsupported on the single-node Lite engine"
                .into(),
        }),
        MetaOp::RollbackToSavepoint { .. } => Err(LiteError::Unsupported {
            detail: "RollbackToSavepoint replays Data Plane per-core overlay undo journals; \
                     unsupported on the single-node Lite engine"
                .into(),
        }),
        MetaOp::ResolveTxn { .. } => Err(LiteError::Unsupported {
            detail: "ResolveTxn folds staged Data Plane write plans into one redo record; \
                     unsupported on the single-node Lite engine"
                .into(),
        }),
        MetaOp::ApplyTransactionRedo { .. } => Err(LiteError::Unsupported {
            detail: "ApplyTransactionRedo installs a committed redo record from a vShard's \
                     data-group log; unsupported on the single-node Lite engine"
                .into(),
        }),

        // Calvin deterministic-scheduling ops. Calvin sequences transactions
        // across a replicated log; Lite has no sequencer, Raft group, or
        // cross-core write-version registry, so these are unreachable here.
        MetaOp::CalvinResolve { .. } => Err(LiteError::Unsupported {
            detail: "CalvinResolve is a deterministic-scheduler op; \
                     unsupported on the single-node Lite engine"
                .into(),
        }),
        MetaOp::CalvinDrop { .. } => Err(LiteError::Unsupported {
            detail: "CalvinDrop is a deterministic-scheduler op; \
                     unsupported on the single-node Lite engine"
                .into(),
        }),

        MetaOp::VerifyHashChain { .. } => Err(LiteError::Unsupported {
            detail: "VerifyHashChain checks a Data Plane audit hash chain; \
                     unsupported on the single-node Lite engine"
                .into(),
        }),
        MetaOp::HomeVersions { .. } => Err(LiteError::Unsupported {
            detail: "HomeVersions reads the cluster write-version registry; \
                     unsupported on the single-node Lite engine"
                .into(),
        }),
        MetaOp::RestoreRedo(_) => Err(LiteError::Unsupported {
            detail: "RestoreRedo reinstalls a cluster transaction redo record; \
                     unsupported on the single-node Lite engine"
                .into(),
        }),
    }
}