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§
Sourcefn create_named(
&self,
name: &StoragePath,
) -> Result<Box<dyn FileWriter>, StorageError>
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.
Sourcefn open(&self, name: &StoragePath) -> Result<Arc<dyn FileReader>, StorageError>
fn open(&self, name: &StoragePath) -> Result<Arc<dyn FileReader>, StorageError>
Opens name for reading.
Sourcefn list(
&self,
parent: &StoragePath,
cb: &mut dyn FnMut(&StoragePath, StorageFileType),
) -> Result<(), StorageError>
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.
fn delete(&self, name: &StoragePath) -> Result<(), StorageError>
fn delete_recursive(&self, name: &StoragePath) -> Result<(), StorageError>
Sourcefn usage(&self) -> Arc<AtomicI64>
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§
Sourcefn create(&self) -> Result<Box<dyn FileWriter>, StorageError>
fn create(&self) -> Result<Box<dyn FileWriter>, StorageError>
Creates a new persistent file used for writing data. The backend selects a name.
Sourcefn create_with_prefix(
&self,
prefix: &StoragePath,
) -> Result<Box<dyn FileWriter>, StorageError>
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.
Sourcefn file_system_path(&self) -> Option<&Path>
fn file_system_path(&self) -> Option<&Path>
Returns the base directory path on the local file system if the storage backend uses local disk.
fn delete_if_exists(&self, name: &StoragePath) -> Result<(), StorageError>
fn exists(&self, name: &StoragePath) -> Result<bool, StorageError>
Sourcefn read(&self, name: &StoragePath) -> Result<Arc<FBuf>, StorageError>
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.
Sourcefn write(&self, name: &StoragePath, content: FBuf) -> Result<(), StorageError>
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
impl dyn StorageBackend
Sourcepub fn new(
config: &StorageConfig,
options: &StorageOptions,
) -> Result<Arc<Self>, StorageError>
pub fn new( config: &StorageConfig, options: &StorageOptions, ) -> Result<Arc<Self>, StorageError>
Creates and returns a new backend configured according to config and options.
pub fn gather_batches_for_checkpoint_uuid( &self, cpm: Uuid, ) -> Result<HashSet<StoragePath>, StorageError>
pub fn gather_batches_for_checkpoint( &self, cpm: &CheckpointMetadata, ) -> Result<HashSet<StoragePath>, StorageError>
Sourcepub fn write_json<V>(
&self,
name: &StoragePath,
value: &V,
) -> Result<(), StorageError>where
V: Serialize,
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§impl dyn StorageBackend + '_
impl dyn StorageBackend + '_
Sourcepub fn read_json<V>(&self, name: &StoragePath) -> Result<V, StorageError>where
V: DeserializeOwned,
pub fn read_json<V>(&self, name: &StoragePath) -> Result<V, StorageError>where
V: DeserializeOwned,
Reads name as JSON.