Module foundationdb::directory

source ·
Expand description

Directory provides a tool for managing related subspaces.

The FoundationDB API provides directories as a tool for managing related Subspaces. For general guidance on directory usage, see the discussion in the Developer Guide.

Directories are identified by hierarchical paths analogous to the paths in a Unix-like file system. A path is represented as a slice of strings. Each directory has an associated subspace used to store its content. The directory layer maps each path to a short prefix used for the corresponding subspace. In effect, directories provide a level of indirection for access to subspaces. Directory operations are transactional.

It is a direct backport of the Flow implementation.

Examples:

use futures::prelude::*;
use foundationdb::directory::Directory;

async fn async_main() -> foundationdb::FdbResult<()> {
    let db = foundationdb::Database::default()?;

    // creates a transaction
    let trx = db.create_trx()?;

    // creates a directory
    let directory = foundationdb::directory::DirectoryLayer::default();

    let path = vec![String::from("my-awesome-app"), String::from("my-awesome-user")];

    // use the directory to create a subspace to use
    let content_subspace = directory.create_or_open(
        // the transaction used to read/write the directory.
        &trx,
        // the path used, which can view as a UNIX path like `/app/my-app`.
        &path,
        // do not use any custom prefix or layer
        None, None,
    ).await;
    assert_eq!(true, content_subspace.is_ok());

    // Don't forget to commit your transaction to persist the subspace
    trx.commit().await?;

    Ok(())
}

// Safe because drop is called before the program exits
let network = unsafe { foundationdb::boot() };
futures::executor::block_on(async_main()).expect("failed to run");
drop(network);

Structs§

  • A DirectoryLayer defines a new root directory. The node subspace and content subspace control where the directory metadata and contents, respectively, are stored. The default root directory has a node subspace with raw prefix \xFE and a content subspace with no prefix.
  • A DirectoryPartition is a DirectorySubspace whose prefix is preprended to all of its descendant directories’s prefixes. It cannot be used as a Subspace. Instead, you must create at least one subdirectory to store content.
  • A DirectorySubspace represents the contents of a directory, but it also remembers the path with which it was opened and offers convenience methods to operate on the directory at that path. An instance of DirectorySubspace can be used for all the usual subspace operations. It can also be used to operate on the directory with which it was opened.

Enums§

  • The enumeration holding all possible errors from a Directory.
  • DirectoryOutput represents the different output of a Directory.

Traits§

  • Directory represents a subspace of keys in a FoundationDB database, identified by a hierarchical path.