uqa_storage_sqlite/mvcc/native/
mod.rs1mod capture;
10mod diskann;
11pub(crate) use row::{binary_pair_limit, variable_fields_limit, vector_row_limit};
12mod family;
13mod field_guards;
14pub(crate) use field_guards::VECTOR_FIELD_GUARD_PREFIX;
15mod format;
16mod graph_cache;
17mod graph_guards;
18mod graph_lifetimes;
19mod graph_lookup;
20mod key;
21mod layout;
22mod maintenance;
23mod notifications;
24pub(super) use maintenance::NativeMaintenanceRecords;
25mod occurrence_guards;
26mod owners;
27mod physical;
28pub(crate) mod populations;
29mod projection;
30mod queue;
31mod row;
32mod sequences;
33mod session;
34mod standalone_graph;
35mod vector_guards;
36
37pub(crate) use session::{NativeSnapshot, PrivateRows};
38
39pub(super) use capture::{capture_key, CapturedKey};
40pub(super) use format::{check_mapping, initialize, initialize_in, present, reject_mapped};
41pub(super) use format::{initialize_restoration, validate_restoration};
42pub(super) use projection::materialize;
43
44#[cfg(test)]
45mod tests;
46
47pub use family::NativeRecordFamily;
48pub use key::{NativeRecordIdentity, NativeRecordOwner};
49pub use layout::{NativeColumnType, NativeRecordLayout};
50pub use row::{decode_row, encode_row};
51
52use rusqlite::types::ValueRef;
53use uqa_core::memory::BudgetedVec;
54use uqa_storage::mvcc::{CommitSequence, DatabaseId, RecordWrite, VersionError, VersionResult};
55use uqa_storage::read_control::StorageReadControl;
56
57#[derive(Clone, Copy, Debug, PartialEq, Eq)]
59pub(super) struct NativeRecordNamespace(pub(super) DatabaseId);
60
61pub(super) struct NativeMapping {
62 pub(super) identity: DatabaseId,
63 pub(super) namespace: NativeRecordNamespace,
64}
65
66#[derive(Debug)]
68pub struct NativeRecord {
69 key: BudgetedVec<u8>,
70 row: BudgetedVec<u8>,
71}
72
73impl NativeRecord {
74 pub fn encode(
75 family: NativeRecordFamily,
76 owner: NativeRecordOwner,
77 values: &[ValueRef<'_>],
78 control: &StorageReadControl,
79 ) -> VersionResult<Self> {
80 control.cancellation().check()?;
81 let layout = family.layout();
82 let identity = NativeRecordIdentity::new(family, owner)?;
83 identity.validate_row(values)?;
84 let mut components = BudgetedVec::new(control.memory());
85 for &column in layout.identity_columns {
86 components.push(values[column])?;
87 }
88 let key = identity.encode_key(&components, control)?;
89 let row = encode_row(values, control)?;
90 Ok(Self { key, row })
91 }
92
93 pub fn key(&self) -> &[u8] {
94 &self.key
95 }
96
97 pub fn row(&self) -> &[u8] {
98 &self.row
99 }
100
101 pub fn write(&self, expected: Option<CommitSequence>) -> RecordWrite<'_> {
102 RecordWrite {
103 key: self.key(),
104 expected,
105 value: Some(self.row()),
106 }
107 }
108}
109
110pub fn decode_record<'a>(
112 key: &[u8],
113 row: &'a [u8],
114 control: &StorageReadControl,
115) -> VersionResult<(NativeRecordIdentity, BudgetedVec<ValueRef<'a>>)> {
116 control.cancellation().check()?;
117 let identity = NativeRecordIdentity::decode(key)?;
118 let layout = identity.family().layout();
119 let values = decode_row(row, layout.columns.len(), control)?;
120 identity.validate_row(&values)?;
121 if !identity.matches_row_key(key, &values, control)? {
122 return Err(invalid("native row does not match its record key"));
123 }
124 Ok((identity, values))
125}
126
127fn invalid(message: &'static str) -> VersionError {
128 VersionError::InvalidEncoding(message)
129}