Struct fjall::Keyspace

source ·
pub struct Keyspace(/* private fields */);
Expand description

A keyspace is a single logical database which can house multiple partitions

In your application, you should create a single keyspace and keep it around for as long as needed (as long as you are using its partitions).

Implementations§

source§

impl Keyspace

source

pub fn batch(&self) -> Batch

Initializes a new atomic write batch.

Items may be written to multiple partitions, which will be be updated atomically when the batch is committed.

§Examples
let mut batch = keyspace.batch();

assert_eq!(partition.len()?, 0);
batch.insert(&partition, "1", "abc");
batch.insert(&partition, "3", "abc");
batch.insert(&partition, "5", "abc");

assert_eq!(partition.len()?, 0);

batch.commit()?;
assert_eq!(partition.len()?, 3);
source

pub fn write_buffer_size(&self) -> u64

Returns the current write buffer size (active + sealed memtables).

source

pub fn journal_count(&self) -> usize

Returns the amount of journals on disk.

§Examples
assert_eq!(1, keyspace.journal_count());
source

pub fn disk_space(&self) -> u64

Returns the disk space usage of the entire keyspace.

§Examples
assert!(keyspace.disk_space() >= 0);
source

pub fn persist(&self, mode: PersistMode) -> Result<()>

Flushes the active journal to OS buffers. The durability depends on the PersistMode used.

Persisting only affects durability, NOT consistency! Even without flushing data is crash-safe.

§Examples
let keyspace = Config::new(folder).open()?;
let items = keyspace.open_partition("my_items", PartitionCreateOptions::default())?;

items.insert("a", "hello")?;

keyspace.persist(PersistMode::SyncAll)?;
§Errors

Returns error, if an IO error occured.

source

pub fn open(config: Config) -> Result<Self>

Opens a keyspace in the given directory.

§Errors

Returns error, if an IO error occured.

source

pub fn delete_partition(&self, handle: PartitionHandle) -> Result<()>

Destroys the partition, removing all data associated with it.

§Errors

Will return Err if an IO error occurs.

source

pub fn open_partition( &self, name: &str, create_options: PartitionCreateOptions ) -> Result<PartitionHandle>

Creates or opens a keyspace partition.

Partition names can be up to 255 characters long, can not be empty and can only contain alphanumerics, underscore (_) and dash (-).

§Errors

Returns error, if an IO error occured.

§Panics

Panics if the partition name is invalid.

source

pub fn partition_count(&self) -> usize

Returns the amount of partitions

source

pub fn list_partitions(&self) -> Vec<Arc<str>>

Gets a list of all partition names in the keyspace

source

pub fn partition_exists(&self, name: &str) -> bool

Returns true if the partition with the given name exists.

§Examples
assert!(!keyspace.partition_exists("default"));
keyspace.open_partition("default", PartitionCreateOptions::default())?;
assert!(keyspace.partition_exists("default"));
source

pub fn instant(&self) -> Instant

Gets the current sequence number.

Can be used to start a cross-partition snapshot, using PartitionHandle::snapshot_at.

§Examples
let partition1 = keyspace.open_partition("default", PartitionCreateOptions::default())?;
let partition2 = keyspace.open_partition("another", PartitionCreateOptions::default())?;

partition1.insert("abc1", "abc")?;
partition2.insert("abc2", "abc")?;

let instant = keyspace.instant();
let snapshot1 = partition1.snapshot_at(instant);
let snapshot2 = partition2.snapshot_at(instant);

assert!(partition1.contains_key("abc1")?);
assert!(partition2.contains_key("abc2")?);

assert!(snapshot1.contains_key("abc1")?);
assert!(snapshot2.contains_key("abc2")?);

partition1.insert("def1", "def")?;
partition2.insert("def2", "def")?;

assert!(!snapshot1.contains_key("def1")?);
assert!(!snapshot2.contains_key("def2")?);

assert!(partition1.contains_key("def1")?);
assert!(partition2.contains_key("def2")?);

Trait Implementations§

source§

impl Clone for Keyspace

source§

fn clone(&self) -> Keyspace

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Deref for Keyspace

§

type Target = KeyspaceInner

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

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> 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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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>,

§

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>,

§

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.