Skip to main content

Record

Struct Record 

Source
pub struct Record {
    pub key: RecordKey,
    pub kind: RecordKind,
    pub revision: Revision,
    pub parent: Option<Revision>,
    pub body: Body,
    pub meta: Meta,
    pub links: Vec<RecordKey>,
    pub ancestors: Vec<Revision>,
    pub deleted_at: Option<i64>,
    pub deleted_blob: Option<ContentHash>,
    pub deleted_kind: Option<RecordKind>,
}
Expand description

The universal persisted unit.

Fields§

§key: RecordKey§kind: RecordKind§revision: Revision§parent: Option<Revision>§body: Body§meta: Meta§links: Vec<RecordKey>§ancestors: Vec<Revision>

Recent revisions this record descends from, newest first, bounded by the store’s ancestor cap. Advisory: a missing or truncated list makes sync report a conflict instead of guessing. Empty on legacy records.

§deleted_at: Option<i64>

Tombstones only: when the delete happened, in ms since the Unix epoch. Stamped by the store. None means collection never purges it.

§deleted_blob: Option<ContentHash>

Tombstones only: the blob the deleted record’s body referenced, if it had one. A tombstone’s own body is empty, so without this the hash would be lost the moment the record was deleted and blob collection could not tell a blob that is merely deleted from one nothing points at.

A tombstone pins its blob: the blob survives until the tombstone itself is collected, so a record restored from a peer, or recreated from the same content, still has its bytes (gonzalo#292).

§deleted_kind: Option<RecordKind>

Tombstones only: the kind of the record that was deleted.

Set when the deleted body is retained — the manifest kinds, whose bodies name blobs out of line — so GC knows which parser to use for the references inside, and undelete knows what kind to recreate. A manifest’s body is the only record of which blob was which shard, so discarding it would leave the pinned bytes unnameable (ADR 0029).

None on a tombstone whose body was discarded, and on every tombstone written before this field existed.

Implementations§

Source§

impl Record

Source

pub fn create(key: RecordKey, kind: RecordKind, body: Body, meta: Meta) -> Self

A record that does not exist yet: the body’s first revision, no parent and no history. Write it with put(record, None) (gonzalo#305).

use gonzalo_core::{Body, Identity, Meta, Record, RecordKey, RecordKind, Revision};

let key = RecordKey::new("caliban", "topics", "rust");
let meta = Meta::new(Identity::new("ada"), "example");
let v0 = Record::create(key, RecordKind::Topic, Body::Inline(b"first".to_vec()), meta);
assert_eq!(v0.revision, Revision::initial(b"first"));
assert_eq!(v0.parent, None);

// The next version descends from it: `put(v1, Some(v0.revision))` commits.
let meta = Meta::new(Identity::new("ada"), "example");
let v1 = v0.update(Body::Inline(b"second".to_vec()), meta);
assert_eq!(v1.revision, v0.revision.next(b"second"));
assert_eq!(v1.parent, Some(v0.revision));
Source

pub fn update(&self, body: Body, meta: Meta) -> Self

The next version of this record carrying body, written by meta.

Its revision follows this one and its parent is this revision, so put(next, Some(current.revision)) commits it and a stale read conflicts — which is the pairing that is easy to get wrong by hand (gonzalo#305). key, kind and links carry over.

ancestors is left empty: the store folds this record’s revision and history in when it commits, bounded by its ancestor cap. deleted_at is cleared, since only a store writes a tombstone.

Source

pub fn is_tombstone(&self) -> bool

Whether this record is a deletion marker.

Trait Implementations§

Source§

impl Clone for Record

Source§

fn clone(&self) -> Record

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Record

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Record

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Record

Source§

impl PartialEq for Record

Source§

fn eq(&self, other: &Record) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Record

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Record

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.