StorageBackend

Trait StorageBackend 

Source
pub trait StorageBackend: Send + Sync {
Show 13 methods // Required methods fn create_named( &self, name: &StoragePath, ) -> Result<Box<dyn FileWriter>, StorageError>; fn open( &self, name: &StoragePath, ) -> Result<Arc<dyn FileReader>, StorageError>; fn list( &self, parent: &StoragePath, cb: &mut dyn FnMut(&StoragePath, StorageFileType), ) -> Result<(), StorageError>; fn delete(&self, name: &StoragePath) -> Result<(), StorageError>; fn delete_recursive(&self, name: &StoragePath) -> Result<(), StorageError>; fn usage(&self) -> Arc<AtomicI64>; // Provided methods fn create(&self) -> Result<Box<dyn FileWriter>, StorageError> { ... } fn create_with_prefix( &self, prefix: &StoragePath, ) -> Result<Box<dyn FileWriter>, StorageError> { ... } fn file_system_path(&self) -> Option<&Path> { ... } fn delete_if_exists(&self, name: &StoragePath) -> Result<(), StorageError> { ... } fn exists(&self, name: &StoragePath) -> Result<bool, StorageError> { ... } fn read(&self, name: &StoragePath) -> Result<Arc<FBuf>, StorageError> { ... } fn write( &self, name: &StoragePath, content: FBuf, ) -> Result<(), StorageError> { ... }
}
Expand description

A storage backend.

Required Methods§

Source

fn create_named( &self, name: &StoragePath, ) -> Result<Box<dyn FileWriter>, StorageError>

Create a new file with the given name, automatically creating any parent directories within name that don’t already exist.

Source

fn open(&self, name: &StoragePath) -> Result<Arc<dyn FileReader>, StorageError>

Opens name for reading.

Source

fn list( &self, parent: &StoragePath, cb: &mut dyn FnMut(&StoragePath, StorageFileType), ) -> Result<(), StorageError>

Calls cb with the name of each of the files under parent. This is a non-recursive list: it does not include files under sub-directories of parent.

Source

fn delete(&self, name: &StoragePath) -> Result<(), StorageError>

Source

fn delete_recursive(&self, name: &StoragePath) -> Result<(), StorageError>

Source

fn usage(&self) -> Arc<AtomicI64>

Returns a value that represents the number of bytes of storage in use. The storage backend updates this value when its own functions cause more or less storage to be used:

  • Writing to a file.

  • Deleting a file (by dropping a FileWriter without completing, or by dropping a FileReader without marking it for a checkpoint, or by calling functions to delete files.

The backend is not required to:

  • Initially report how much storage is in use. Instead, it just starts out at zero. The client can traverse the storage itself and store the correct initial value.

  • Detect changes made by a different backend or outside any backend.

The value is signed because the problems above can cause it to become negative.

Provided Methods§

Source

fn create(&self) -> Result<Box<dyn FileWriter>, StorageError>

Creates a new persistent file used for writing data. The backend selects a name.

Source

fn create_with_prefix( &self, prefix: &StoragePath, ) -> Result<Box<dyn FileWriter>, StorageError>

Creates a new persistent file used for writing data, giving the file’s name the specified prefix. See also create.

Source

fn file_system_path(&self) -> Option<&Path>

Returns the base directory path on the local file system if the storage backend uses local disk.

Source

fn delete_if_exists(&self, name: &StoragePath) -> Result<(), StorageError>

Source

fn exists(&self, name: &StoragePath) -> Result<bool, StorageError>

Source

fn read(&self, name: &StoragePath) -> Result<Arc<FBuf>, StorageError>

Reads name and returns its contents. The file name is relative to the base of the storage backend.

Source

fn write(&self, name: &StoragePath, content: FBuf) -> Result<(), StorageError>

Writes content to name, automatically creating any parent directories within name that don’t already exist.

Implementations§

Source§

impl dyn StorageBackend

Source

pub fn new( config: &StorageConfig, options: &StorageOptions, ) -> Result<Arc<Self>, StorageError>

Creates and returns a new backend configured according to config and options.

Source

pub fn gather_batches_for_checkpoint_uuid( &self, cpm: Uuid, ) -> Result<HashSet<StoragePath>, StorageError>

Source

pub fn gather_batches_for_checkpoint( &self, cpm: &CheckpointMetadata, ) -> Result<HashSet<StoragePath>, StorageError>

Source§

impl dyn StorageBackend + '_

Source

pub fn write_json<V>( &self, name: &StoragePath, value: &V, ) -> Result<(), StorageError>
where V: Serialize,

Writes content to name as JSON, automatically creating any parent directories within name that don’t already exist.

Source

pub fn read_json<V>(&self, name: &StoragePath) -> Result<V, StorageError>

Reads name as JSON.

Implementors§