Skip to main content

omnigraph/db/
mod.rs

1pub mod commit_graph;
2pub mod graph_coordinator;
3pub mod manifest;
4mod omnigraph;
5mod recovery_audit;
6mod run_registry;
7mod schema_state;
8pub(crate) mod write_queue;
9
10pub use commit_graph::GraphCommit;
11pub use graph_coordinator::{GraphCoordinator, ReadTarget, ResolvedTarget, SnapshotId};
12pub use manifest::{Snapshot, SubTableEntry, SubTableUpdate};
13pub use omnigraph::{
14    CleanupPolicyOptions, MergeOutcome, Omnigraph, OpenMode, SchemaApplyResult,
15    TableCleanupStats, TableOptimizeStats,
16};
17pub(crate) use omnigraph::ensure_public_branch_ref;
18pub(crate) use run_registry::is_internal_run_branch;
19
20pub(crate) const SCHEMA_APPLY_LOCK_BRANCH: &str = "__schema_apply_lock__";
21
22/// Mutation kind, threaded through the version-check call sites so the
23/// engine can apply an op-kind-aware policy:
24///
25/// - `Insert` / `Merge`: skip the strict pre-stage `ensure_expected_version`
26///   check. Lance's `MergeInsertBuilder` rebases concurrent appends; the
27///   per-(table, branch) writer queue serializes `commit_staged`; the
28///   publisher's CAS (refreshed under the queue via
29///   `MutationStaging::commit_all`'s `snapshot_for_branch` call) catches
30///   genuine cross-process drift as `ManifestConflictDetails::ExpectedVersionMismatch`.
31///   The pre-stage strict check would over-reject in-process concurrent
32///   inserts, which is exactly the case PR 2 / MR-686 designed the
33///   per-table queue to allow.
34///
35/// - `Update` / `Delete`: keep the strict check. These have read-modify-write
36///   semantics; Lance moving between the read at stage time and the write
37///   at commit time means the staged batch is computed against stale state.
38///   The strict check guards the per-query SI invariant. SERIALIZABLE
39///   opt-in (§VI.36 future seam) is the long-term answer for tighter
40///   semantics; today, in-process update-update races on the same key
41///   stay rejected as 409 — acceptable.
42///
43/// - `SchemaRewrite`: keep the strict check. Schema apply runs under the
44///   graph-wide `__schema_apply_lock__` AND per-table queues; the strict
45///   check is uncontested at that point.
46#[derive(Debug, Clone, Copy, PartialEq, Eq)]
47pub(crate) enum MutationOpKind {
48    Insert,
49    Merge,
50    Update,
51    Delete,
52    SchemaRewrite,
53}
54
55impl MutationOpKind {
56    /// Whether the strict pre-stage `ensure_expected_version` check should
57    /// fire for this op kind. See [`MutationOpKind`] for the rationale per
58    /// kind.
59    pub(crate) fn strict_pre_stage_version_check(self) -> bool {
60        match self {
61            MutationOpKind::Insert | MutationOpKind::Merge => false,
62            MutationOpKind::Update
63            | MutationOpKind::Delete
64            | MutationOpKind::SchemaRewrite => true,
65        }
66    }
67}
68
69pub(crate) fn is_schema_apply_lock_branch(name: &str) -> bool {
70    name.trim_start_matches('/') == SCHEMA_APPLY_LOCK_BRANCH
71}
72
73pub(crate) fn is_internal_system_branch(name: &str) -> bool {
74    is_internal_run_branch(name) || is_schema_apply_lock_branch(name)
75}