pub trait StorageBackend: Send + Sync {
Show 16 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(DirEntry),
) -> 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<Arc<dyn FileCommitter>, StorageError> { ... }
fn commit_all(
&self,
files: &[Arc<dyn FileCommitter>],
) -> Result<(), StorageError> { ... }
fn sync_files(
&self,
files: &[Arc<dyn FileCommitter>],
) -> Result<(), StorageError> { ... }
fn fsync_dir(&self, _dir: &StoragePath) -> 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(DirEntry),
) -> Result<(), StorageError>
fn list( &self, parent: &StoragePath, cb: &mut dyn FnMut(DirEntry), ) -> Result<(), StorageError>
Calls cb with the name and type of each file under parent. This is a
non-recursive list: it does not include files under sub-directories of
parent.
This method can report two classes of errors:
-
The return value indicates errors that could prevent
cbfrom being called for some or all of the files in the directory. These errors indicate thatparentdoes not exist or cannot be (fully) read successfully. If more than one such error occurs, the method returns the last one. -
DirEntry::file_type in the argument to the callback reports errors obtaining the file type. Errors reported this way only mean that there was a problem obtaining metadata for the file itself.
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<Arc<dyn FileCommitter>, StorageError>
fn write( &self, name: &StoragePath, content: FBuf, ) -> Result<Arc<dyn FileCommitter>, StorageError>
Writes content to name, automatically creating any parent
directories within name that don’t already exist.
The returned file is readable but not durable. To make it durable, the
caller must either call commit on it or hand it to the checkpoint
commit phase.
Sourcefn commit_all(
&self,
files: &[Arc<dyn FileCommitter>],
) -> Result<(), StorageError>
fn commit_all( &self, files: &[Arc<dyn FileCommitter>], ) -> Result<(), StorageError>
Makes every file in files durable, and times how long that took.
This is how the checkpoint commit phase makes a checkpoint’s files durable. Backends vary what they do here, so this times the call rather than the syncs inside it: that is the figure the strategies have to be compared on, and for a backend that overlaps its syncs it cannot be recovered by adding up the individual ones.
Override Self::sync_files, not this.
Sourcefn sync_files(
&self,
files: &[Arc<dyn FileCommitter>],
) -> Result<(), StorageError>
fn sync_files( &self, files: &[Arc<dyn FileCommitter>], ) -> Result<(), StorageError>
Makes every file in files durable, however this backend does it best.
Committing each file in turn is the obvious implementation and the
default here, which is right for a backend whose commit is a no-op. On
a real filesystem it is the slowest option available: it keeps exactly
one sync in flight, so nothing the kernel does to batch them applies.
Committing a file that is already durable is harmless, so a backend may
make more files durable than were asked for. files is never empty.
Sourcefn fsync_dir(&self, _dir: &StoragePath) -> Result<(), StorageError>
fn fsync_dir(&self, _dir: &StoragePath) -> Result<(), StorageError>
Flushes the directory entry metadata for dir to stable storage.
POSIX fsync(file) guarantees the file’s data is durable but says
nothing about whether the file’s name in its parent directory is
durable. After renaming files into a directory or creating new
subdirectories, the caller can use this barrier to make those
directory entries durable in one syscall.
Backends that do not have a meaningful notion of directory durability (e.g. object stores) may treat this as a no-op.
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>
Source§impl dyn StorageBackend + '_
impl dyn StorageBackend + '_
Sourcepub fn write_json<V>(
&self,
name: &StoragePath,
value: &V,
) -> Result<Arc<dyn FileCommitter>, StorageError>where
V: Serialize,
pub fn write_json<V>(
&self,
name: &StoragePath,
value: &V,
) -> Result<Arc<dyn FileCommitter>, StorageError>where
V: Serialize,
Writes content to name as JSON, automatically creating any parent
directories within name that don’t already exist.
The returned file is readable but not durable. To make it durable, the
caller must either call commit on it or hand it to the checkpoint
commit phase.
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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".