Skip to main content

uqa_storage/diskann_index/format/
identity.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7use crate::mvcc::StorageTransactionId;
8use crate::StorageBackendResult;
9
10/// Persistent data identities supplied by the storage owner; independent of paths and transaction-history restoration.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12pub struct DiskANNGeneration {
13    pub(super) database: [u8; 16],
14    pub(super) table: u64,
15    pub(super) index: u64,
16    pub(super) generation: u64,
17}
18
19impl DiskANNGeneration {
20    pub fn new(
21        database: [u8; 16],
22        table: u64,
23        index: u64,
24        generation: u64,
25    ) -> StorageBackendResult<Self> {
26        if database == [0; 16] || table == 0 || index == 0 || generation == 0 {
27            return Err(super::invalid(
28                "data incarnations and generation must be nonzero",
29            ));
30        }
31        Ok(Self {
32            database,
33            table,
34            index,
35            generation,
36        })
37    }
38
39    pub fn database(self) -> [u8; 16] {
40        self.database
41    }
42    pub fn table(self) -> u64 {
43        self.table
44    }
45    pub fn index(self) -> u64 {
46        self.index
47    }
48    pub fn generation(self) -> u64 {
49        self.generation
50    }
51}
52
53/// Logical vector origin, retained as data after its writer receipt is reclaimed. Revisions are allocated by the vector mutation owner, not inferred from commit time.
54#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
55pub struct DiskANNVectorVersion {
56    pub(super) writer: StorageTransactionId,
57    pub(super) revision: u64,
58}
59
60impl DiskANNVectorVersion {
61    pub fn new(writer: StorageTransactionId, revision: u64) -> StorageBackendResult<Self> {
62        if revision == 0 {
63            return Err(super::invalid("vector origin revision must be nonzero"));
64        }
65        Ok(Self { writer, revision })
66    }
67
68    pub fn writer(self) -> StorageTransactionId {
69        self.writer
70    }
71    pub fn revision(self) -> u64 {
72        self.revision
73    }
74}