s365b.storage.backends¶
Storage backends: where repository files physically live.
A backend stores opaque, immutable objects under /-separated keys such as
packs/ab/ab12…. It knows nothing about encryption or deduplication; that
is the repository’s job. New backends (S3, Azure Blob) implement
StorageBackend.
Exceptions¶
Raised for storage errors, such as a missing object. |
|
Raised when a key does not exist. |
Classes¶
Interface every storage backend implements. |
|
Stores objects as files under a root directory. |
Functions¶
|
Check that a key is a safe relative path. |
Module Contents¶
- exception s365b.storage.backends.BackendError[source]¶
Bases:
ExceptionRaised for storage errors, such as a missing object.
- exception s365b.storage.backends.ObjectNotFoundError[source]¶
Bases:
BackendErrorRaised when a key does not exist.
- s365b.storage.backends.validate_key(key: str) str[source]¶
Check that a key is a safe relative path.
- Parameters:
key – Object key such as
index/abc.- Returns:
The key, unchanged.
- Raises:
ValueError – If the key is empty, absolute, or contains
..or unexpected characters.
- class s365b.storage.backends.StorageBackend[source]¶
Bases:
abc.ABCInterface every storage backend implements.
Objects are write-once: the repository never modifies an object in place, which is what makes object-lock immutability possible on S3.
- abstractmethod put(key: str, data: bytes, *, overwrite: bool = False) None[source]¶
- Async:
Store an object atomically.
- Parameters:
key – Object key.
data – Object content.
overwrite – Allow replacing an existing object. Only used for the repository config during key changes.
- Raises:
BackendError – If the object exists and
overwriteis false.
- abstractmethod get(key: str) bytes[source]¶
- Async:
Read a whole object.
- Parameters:
key – Object key.
- Returns:
The object content.
- Raises:
ObjectNotFoundError – If the key does not exist.
- abstractmethod get_range(key: str, offset: int, length: int) bytes[source]¶
- Async:
Read part of an object.
- Parameters:
key – Object key.
offset – First byte to read.
length – Number of bytes to read.
- Returns:
Exactly
lengthbytes.- Raises:
ObjectNotFoundError – If the key does not exist.
BackendError – If the object is shorter than requested.
- abstractmethod exists(key: str) bool[source]¶
- Async:
Return whether an object exists.
- Parameters:
key – Object key.
- Returns:
True if the object exists.
- class s365b.storage.backends.FilesystemBackend(root: pathlib.Path)[source]¶
Bases:
StorageBackendStores objects as files under a root directory.
Works for local disks and for NFS/SMB shares mounted into the container. Writes go to a temporary file that is fsynced and then renamed into place, so a crash never leaves a half-written object under its final name.
- Parameters:
root – Directory holding the repository. Created if missing.
- async put(key: str, data: bytes, *, overwrite: bool = False) None[source]¶
Store an object atomically (see
StorageBackend.put()).
- async get(key: str) bytes[source]¶
Read a whole object (see
StorageBackend.get()).
- async get_range(key: str, offset: int, length: int) bytes[source]¶
Read part of an object (see
StorageBackend.get_range()).
- async exists(key: str) bool[source]¶
Return whether an object exists (see
StorageBackend.exists()).
- async list(prefix: str) collections.abc.AsyncIterator[str][source]¶
Yield keys under a prefix (see
StorageBackend.list()).
- async delete(key: str) None[source]¶
Delete an object (see
StorageBackend.delete()).