Skip to main content

uqa_storage/mvcc/commit/
metadata.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! What a prepared write changes, without its value.
8
9use crate::mvcc::key::RecordKey;
10use crate::mvcc::CommitSequence;
11
12use super::RecordWriteKind;
13
14/// What a write changes, without its value: its key, the revision it expects, its kind and the length of its value, if it has one.
15pub struct PreparedWriteMetadata {
16    key: RecordKey,
17    expected: Option<CommitSequence>,
18    kind: RecordWriteKind,
19    value_len: Option<u64>,
20}
21
22impl PreparedWriteMetadata {
23    pub(super) fn new(
24        key: RecordKey,
25        expected: Option<CommitSequence>,
26        kind: RecordWriteKind,
27        value_len: Option<u64>,
28    ) -> Self {
29        Self {
30            key,
31            expected,
32            kind,
33            value_len,
34        }
35    }
36
37    pub fn key(&self) -> &[u8] {
38        self.key.bytes()
39    }
40
41    pub fn expected(&self) -> Option<CommitSequence> {
42        self.expected
43    }
44
45    /// Whether the write has a value; a write without one is a deletion.
46    pub fn live(&self) -> bool {
47        self.value_len.is_some()
48    }
49
50    /// The length of the write's value, if it has one.
51    pub fn value_len(&self) -> Option<u64> {
52        self.value_len
53    }
54
55    pub(crate) fn kind(&self) -> RecordWriteKind {
56        self.kind
57    }
58}