Rust · Collections

Collections

use ustore::Collection;use ustore::ArenaDescription;use ustore::CollectionID;use ustore::Collections;use ustore::CompactConfig;use ustore::Description;use ustore::DropMode;use ustore::Key;use ustore::Modality;use ustore::UUID;use ustore::Names;use ustore::db::CollectionList;use ustore::db::CollectionDrop;use ustore::db::Clear;use ustore::db::Compact;use ustore::db::Flush;use ustore::strings::CollectionFind;use ustore::strings::CollectionNames;use ustore::*; 1.0.0-rc.1 · d6d40961

§ Keys

A Key is a UUID, sixteen bytes ordered as their bytes, and converts from [u8; 16], from a UUID, or from a u64 or u128 spelled big-endian, so keys made from integers order as the integers. Key::next is the key right after one in their order, where a scan resumes past it, and key_unknown is the key that stands for no key, every bit of it set. A CollectionID is a UUIDv7 minted when a collection is created, and the nil one names none, as a database holds no collection until one is created. A batch of keys is anything that reads as &[Key]: an array, a Vec, or a borrow of either.

let [ada, grace, kent] = [1u64, 2, 3].map(Key::from);
assert!(ada < grace && grace.next() == kent);
println!("{kent}"); // 00000000-0000-0000-0000-000000000003

§ Collections & Names

Collections are created under a name and the modality they hold, resolved by name once and addressed by identifier from then on, and dropping one forgets its name. Each engine keeps the names in the system collection _names and every collection’s modality and name in _collections, which no identifier reaches, so a name starting with _ is refused with Status::InvalidArgument. A name is read through a view as a value is, so a watching transaction conflicts with a concurrent create or drop of a name it resolved, while a listing describes the database and reads the view’s snapshot or the head.

use ustore::DropMode;

let people = database.collection_create("people", Modality::Blobs)?;
let (same, modality) = database.head().collection_find("people", &mut arena)?;
let every = database.head().collection_list(&mut arena)?;

for name in database.head().collection_names("pe", None, 100, &mut arena)?.iter() {
    println!("{name}");
}

database.collection_drop(people, DropMode::Collection)?;

A database holds no collection until one is created, and Database::collection_drop empties a collection of its pairs or values with DropMode::Pairs or DropMode::Values, or drops it whole with DropMode::Collection. Walks paginate rather than hold an iterator over concurrent state: a cursor resumes past the last key it handed out, a scan from Key::next of the last key it found, and a name walk from a name.

The ABI carries a collection per task, so a batch spans as many collections as it has entries. Every batch verb takes a Collections, and a bare CollectionID converts into Collections::Every, which is the common case written the short way.

use ustore::Collections;

let spanned = [people, places];
let entries = [Entry::new(ada, b"Ada"), Entry::new(ada, b"Kent")];
database.head().write(spanned.as_slice(), &entries, Durability::Buffered)?;

let values = database.head().read(Collections::Each(&spanned), &[ada, ada], &mut arena)?;
database.head().write(people, &entries, Durability::Buffered)?; // one for all of them

A Collections::Each whose length is not the length of the batch is refused with Status::InvalidArgument before the call crosses the boundary.

API

StructCollectionA collection addressed by its name, which reads and writes through one view of its Parent, the head of a Database or a Transaction.7
collection.rs:109 ↗
pub struct Collection<'view, Parent = Database>

Every verb goes through a view of one modality: Collection::blobs, Collection::docs or Collection::graph. A call with no arena to pass reads through a one-off arena and hands back what it read copied out of it, while a batch read borrows the Arena it is given. Writes land Durability::Buffered.

Implements

Debug
blobsThe binary values of the collection, as db['posters'].blobs addresses them.
collection.rs:127 ↗
pub fn blobs(&mut self) -> Blobs<'_, 'view, Parent>
docsThe JSON documents of the collection, as db['movies'].docs addresses them.
collection.rs:132 ↗
pub fn docs(&mut self) -> Docs<'_, 'view, Parent>
graphThe edges of the collection, as db['similar'].graph addresses them.
collection.rs:137 ↗
pub fn graph(&mut self) -> Graph<'_, 'view, Parent>
sampleDraws up to wanted keys of a blobs collection uniformly at random into arena, each with its value read through the same view.
collection.rs:143 ↗
pub fn sample<'arena>(&mut self, wanted: usize, arena: &'arena mut Arena) -> Result<Sample<'arena>>
export_arrowThe whole collection as one Arrow stream through the view, whose batches outlive the stream; a head view reads a snapshot the stream holds until dropped.
collection.rs:200 ↗
pub fn export_arrow(&mut self) -> Result<ArrowArrayStream>

Every pull runs the cursor of the collection's modality into an arena of its own, which the exporters of c/ustore/arrow.h hand out as the batch's columns, and which the batch frees once released.

import_arrowWrites every batch of stream through the writes of the collection's modality, answering the rows written.
collection.rs:209 ↗
pub fn import_arrow(&mut self, stream: ArrowArrayStream, durability: Durability) -> Result<usize>

The converters of c/ustore/arrow.h read every batch's columns in place, and the last write pays durability. The call takes the stream over and releases it, even on failure.

ingest_arrowLands every batch of stream as one commit of its own at the head, answering the rows landed.
collection.rs:220 ↗
pub fn ingest_arrow(
    &mut self,
    stream: ArrowArrayStream,
    order: IngestOrder,
    durability: Durability,
) -> Result<usize>

Appends every batch to one ingest of ustore_ingest_init, which ustore_ingest_finish lands. The call takes the stream over and releases it, even on failure.

StructArenaDescriptionWhere an Arena's outputs live, as Arena::describe reports it.
db.rs:1628 ↗
pub struct ArenaDescription

Fields

residencyResidencyResidency::Ram for host pages, Residency::Vram for one device's memory.
deviceOption<u32>The device's ordinal, as gpu_devices lists it; None for host pages.

Implements

Clone, Copy, StructuralPartialEq, PartialEq, Eq, Debug, Hash
StructCollectionIDThe identifier of a collection: a UUIDv7 its create mints once and never reuses, so it stays the same across restarts and never names two collections.
db.rs:1129 ↗
pub struct CollectionID(pub UUID);

The nil UUID names none.

Fields

Implements

Clone, Copy, StructuralPartialEq, PartialEq, Eq, PartialOrd, Ord, Hash, Default, From<UUID>, From<[u8; 16]>, From<u128>, From<u64>, Display, Debug, From<CollectionID>
EnumCollectionsThe collections a batch addresses: one for every task, or one per task.
db.rs:1172 ↗
pub enum Collections<'collections>

The ABI carries a collection per task, so a batch may span as many collections as it has entries; Collections::Every is the common case, and every verb takes a bare CollectionID as one.

Values

Every(<a data-ref="CollectionID">CollectionID</a>)Every task of the batch addresses the same collection.
Each(&amp;'collections [<a data-ref="CollectionID">CollectionID</a>])The task at each position addresses the collection at the same position.

Implements

Clone, Copy, StructuralPartialEq, PartialEq, Eq, Debug, Hash, From<CollectionID>, From<&'collections [CollectionID]>
StructCompactConfigHow a compaction reports; see On::compact.
db.rs:3133 ↗
pub struct CompactConfig<'config>

Fields

progressOption<&'config mut ProgressCallback<'config>>Reports the work done and stops between collections wherever it says to.

Implements

From<Option<&'config mut dyn FnMut(usize, usize) -> ControlFlow<()> + Send>>
StructDescriptionWhat an open database reports about itself, as ustore_database_describe answers it, where every size is the engine's estimate, and zero where the engine keeps none.1
db.rs:2502 ↗
pub struct Description

Fields

engineEngineThe engine serving the database.
isolationIsolationHow transactions see each other: what the RAM engine was started with, and Isolation::Snapshot elsewhere.
keysusizeKeys across every collection.
memory_bytesu64Bytes of memory the engine holds for the data.
disk_bytesu64Bytes the files of the database take on disk.

Implements

Clone, Copy, StructuralPartialEq, PartialEq, Eq, Debug, Hash
supports_*× 2Whether the engine supports transactions.
db.rs:2519 ↗
pub fn supports_transactions(self) -> bool
Symbol
supports_transactions
supports_snapshots
EnumDropModeWhat dropping a collection or clearing a database removes, as ustore_drop_mode_t spells it.
db.rs:1305 ↗
pub enum DropMode

Values

Collection0The collection together with its name and every pair it holds.
Pairs1Every key and value, keeping the collection.
Values2Every value, keeping the keys.

Implements

Clone, Copy, StructuralPartialEq, PartialEq, Eq, Debug, Hash, Display, FromStr
StructKeyThe identifier of a value within one collection.1
db.rs:1069 ↗
pub struct Key(pub UUID);

Fields

Implements

Clone, Copy, StructuralPartialEq, PartialEq, Eq, PartialOrd, Ord, Hash, Default, From<UUID>, From<[u8; 16]>, From<u128>, From<u64>, Display, Debug, From<Key>
nextThe key right after this one in their order, where a scan resuming past it starts; the last key wraps to the first.
db.rs:1074 ↗
pub fn next(self) -> Key
EnumModalityWhat a collection holds, which an engine records beside its name and refuses the verbs of another modality by.
db.rs:1862 ↗
pub enum Modality

Values

Blobs1Binary values.
Docs2JSON documents.
Graph3Vertices and their edges, which only the graph verbs reach.
Strings4Values keyed by strings.
Pages5Ordered documents.

Implements

Clone, Copy, StructuralPartialEq, PartialEq, Eq, Debug, Hash, Display, FromStr
StructUUIDSixteen bytes naming one thing everywhere, ordered and hashed as their bytes, and printed in the canonical thirty-six character form.
db.rs:1028 ↗
pub struct UUID(pub [u8; 16]);

An integer spells as its 128-bit big-endian bytes, as Python's uuid.UUID(int=...) does, so identifiers made from integers order as the integers.

Fields

0[u8; 16]

Implements

ColumnFormat, Clone, Copy, StructuralPartialEq, PartialEq, Eq, PartialOrd, Ord, Hash, Default, From<[u8; 16]>, From<u128>, From<u64>, Display, Debug, From<UUID>, Scalar
StructNamesThe names of collections one listing found, in the order of their text.4
strings.rs:220 ↗
pub struct Names<'arena>

The run borrows the arena it was exported into, and every name in it was checked for UTF-8 once, when the listing returned.

Implements

Clone, Debug, Default, IntoIterator
lenHow many names the listing kept, never above the count it wanted.
strings.rs:226 ↗
pub fn len(&self) -> usize
is_emptyWhether the listing kept nothing.
strings.rs:231 ↗
pub fn is_empty(&self) -> bool
getThe name at index, or None past the end of the listing.
strings.rs:236 ↗
pub fn get(&self, index: usize) -> Option<&'arena str>
iterEvery name the listing kept, in the order of its text.
strings.rs:241 ↗
pub fn iter(&self) -> Copied<Iter<'_, &'arena str>>
StructCollectionListA listing of the collections a view sees; see On::collection_list.
db.rs:3019 ↗
pub struct CollectionList<'arena>

Implements

Debug
StructCollectionDropA removal of the contents of a collection, or of the collection with its name; see On::collection_drop.
db.rs:3064 ↗
pub struct CollectionDrop

Implements

Debug
StructClearAn emptying of every collection at once; see On::clear.
db.rs:3100 ↗
pub struct Clear

Implements

Debug
StructCompactA compaction of every collection; see On::compact.
db.rs:3146 ↗
pub struct Compact<'progress>

Implements

Debug
StructFlushA flush of every commit that returned; see On::flush.
db.rs:3186 ↗
pub struct Flush;

Implements

Debug
StructCollectionFindA lookup of a collection by its name; see On::collection_find.
strings.rs:1026 ↗
pub struct CollectionFind<'arena, Name>

Implements

Debug
StructCollectionNamesA listing of collection names; see On::collection_names.
strings.rs:1084 ↗
pub struct CollectionNames<'arena, Name>

Implements

Debug

Functions

key_unknownThe key that stands for no key, every bit of it set.
db.rs:1208 ↗
pub const fn key_unknown() -> Key