Skip to main content

S3Backend

Struct S3Backend 

Source
pub struct S3Backend { /* private fields */ }
Expand description

Serves the objects of an S3 bucket as files and directories.

A file is an object, and its key is the path of the file below the prefix. A directory is an object with a zero-length body and a key that ends in /, or just the common prefix of the keys below it. A name that is both an object and a directory is the directory. Keys that no client could open, such as one with a : in a name or an empty path component, are left out of listings.

A file or directory has the times and attributes in the user metadata of its object: mtime, btime, atime and ctime as Unix seconds with up to nine fraction digits, and smb-attributes as hexadecimal. The write time is mtime, else src_last_modified_millis (Unix milliseconds), else the time the store last modified the object; a value that does not parse counts as missing. The other times default to the write time. A directory with no marker object has the time the backend was built. Listings read the metadata of the entries the backend has not seen yet, up to listing_metadata_max of them.

What the backend reads from the store is kept for metadata_ttl. Clones share the connection pool and that cache.

A read of a file requests the chunks of read_chunk bytes that hold its bytes, and keeps them for later reads while a handle that reads their version is open. A chunk not kept is requested for the ETag the file last saw. If the object has another ETag by then, the read looks the object up again and reads that version, and the file reports that version’s size and times from then on. An object without an ETag is read as asked for, with no chunks, and a read fails once the answer has an ETag, or a size or modification time that differs from what the file was opened with.

A writable backend keeps what clients change in its cache directory: the bytes written to a file, and the times and attributes set on files and directories. Bytes written and size changes reach the disk when a client flushes the file, when the last handle open on the file closes, or when the backend starts to store it. The record of a closed file is written in the background. After a restart a file has what was last recorded: one made and never recorded is gone, and an object changed and never recorded reads as the bucket has it. A truncate below the length last recorded is recorded at once. Times and attributes reach the disk at once, except those of a file the backend holds bytes of, which reach it when the file is recorded. The share root keeps its times and attributes in memory. A read returns the bytes written and gets the rest from the store; it fails when it needs bytes of the store and the object under the file changed since the file was opened. If the backend stored the file meanwhile, the read returns the bytes from the object it stored. What the backend holds shows in lookups and listings at once. A directory made through the share has its marker object put in the store before the open returns. A file that is deleted or renamed is gone or has its new name in the share at once, and the bucket follows in the background.

A directory can be deleted when nothing is below it, and renamed with everything below it. The share shows the result at once. The objects of a renamed directory are copied and the old keys deleted in the background, and the directory and every directory below it have a marker object in the new place. Both calls wait for the requests in flight that delete keys below the directory, and fail with an I/O error once request_timeout has passed. Both fail with AccessDenied for the share root. A delete fails with NotEmpty if the backend holds a change below the directory, or the bucket has an object there that is not to be deleted. A rename fails with AccessDenied and changes nothing if the directory holds more than max_dir_rename_objects objects, if a key below it cannot move, or if the move is too large for one record in the cache directory. A key cannot move if no client could open its name, if another key lands on the same name, or, when the rename changes only the case of the name, if the parent lists a directory of each spelling and neither is to be deleted. Both fail with Sharing if the directory, one above it or one below it is being renamed or deleted; a rename also if a directory below it is still being made, or if the keys below it keep changing while they are listed. While a directory is being renamed or checked for a delete, a create or a rename that lands below it fails with Sharing. While a rename moves the entries, so does an open of an existing name below it that the backend holds nothing of.

A file the backend holds bytes of is stored in the bucket in the background, upload_delay after its last change, open or not. A file of up to part_size bytes goes up in one request, a larger one as a multipart upload. The object gets the times and attributes of the file and keeps the other metadata it had. A file that has not changed since it was stored loses the bytes the backend held, and is read from the bucket. After a change to a file, the upload under way starts no more requests, a multipart upload is aborted, and a request already sent may still store the earlier content. Another upload starts after the delay. Times and attributes set on a file the backend holds no bytes of are stored by copying the object onto itself with the new metadata, and those set on a directory by putting its marker object, which a directory without one gets. If the store refuses to copy an object onto itself, an object of up to part_size bytes is read and put again, and the times and attributes of a larger one are not stored, with a warning in the log.

Before it stores a file that was changed in part, the backend reads the rest of its bytes from the object. If the object has changed or is gone by then, the file moves to the conflicts directory of the cache directory with an error in the log, and the bucket keeps what it has. If the move fails, the file stays and shows in failures. A file whose bytes are all local replaces the object with no check of what the bucket holds.

An upload, or the delete of the old keys of a renamed file, fails for good when the store refuses a request in a way trying again cannot fix, or when the cache directory cannot be read or written. It is logged, shows in failures, and is tried again when the next backend is built on the cache directory. That backend stores the files and directory markers an earlier one left without waiting for the upload delay, and aborts the multipart uploads the earlier one left running. A bucket should have a lifecycle rule that aborts incomplete multipart uploads. sync waits until what the backend holds for the bucket has reached it.

A renamed file is stored at its new key, and the old key is deleted once the new key holds its content. A file the backend holds no bytes of is copied within the bucket with the metadata the object had, in parts above 5 GiB. The object of a deleted file is deleted in the background, in batches, once no file has been deleted for upload_delay, and at most a minute after the first of them was due. A file made again under the exact name of one that was deleted replaces the object, and the object is not deleted. Before the backend deletes an object it puts a marker object for each directory above it that would be left with no object, so a directory does not vanish with its last file. If the store answers the marker with ObjectParentIsFile or ExistingObjectIsDirectory, the directory is left without a marker; if it refuses the marker any other way, the object stays in the bucket and sync fails (OperationAborted is tried again). A file is stored after the marker of a directory of its name is deleted, and a marker is put after the object of a file of its name is deleted. A directory made at the name of a file that is to be deleted shows at once, and its marker follows the delete. A write whose wait for such a delete would be a wait for the write itself, as when a file takes the name of the directory it was the only file of, is made without the wait, and the store takes it or refuses it. A delete the store refused for good, or one that only a file or directory that failed owns, is not waited for.

Files renamed in a ring, as when two names swap through a third, are stored in turn. For each ring, the backend downloads one file and uploads it again, and that file has to fit in the free space of the cache directory.

When names match without regard to case, which is the default, a job that stores a file or a directory marker and a request that deletes keys wait for each other if their keys differ in case only, and for a file that still copies from such a key. Creating a directory waits the same way for the requests in flight, and fails with an I/O error once request_timeout has passed. Keys that differ in case only can go out in one delete request. A store that treats such names as one name keeps the object under its old spelling when a file is renamed to a new spelling of its name. Before it deletes an object whose name differs in case only from the name of a file the backend holds, and when it has just stored a file or a directory marker under a name that differs in case only from an object it is to delete, the backend asks the store for both names: if they have the same size, ETag and modification time and are not both listed, they are one object, and it is not deleted. A rename of a directory asks the same for each object below it that differs in case only from an object to delete, and does not move the object if the two are one. With case_insensitive(false) the store has to keep case.

Dropping the last clone ends the uploads. The cache directory stays locked until the handles opened through the backend are closed and the requests in flight and the saves of closed files have ended. A change made through a handle after the last clone is dropped is not stored by this backend; the next backend built on the cache directory stores what the directory records.

Build one with S3Backend::builder.

Implementations§

Source§

impl S3Backend

Source

pub async fn sync(&self) -> Result<(), S3Error>

Waits until the files the backend holds bytes of, the times, attributes and names it has not stored, the directories whose marker objects it has not put, and the objects it is to delete are stored in or deleted from the bucket. Only what the backend holds when the call begins counts. A file that keeps changing delays the call, as it delays its upload. The call waits as long as the uploads take, through failures that trying again may fix and through a full disk of the cache directory.

§Errors

Fails with the error of one of those files or directories whose upload failed for good, or whose changes moved to the conflicts directory of the cache directory because the object changed or is gone in the bucket, or with the error of an object the store refuses to delete. Fails with S3Error::Stopped if the background worker has ended.

Source

pub fn failures(&self) -> Vec<(String, S3Error)>

The paths of the files and directories whose upload, or whose delete of keys they own, failed for good, with the error of each. A path has / between its names and no / before the first. A renamed file is on the list with its new path.

A file or directory on the list keeps what the backend holds for it, which clients still see. It gets no other upload until the next backend is built on the cache directory, which tries it again. A file that moved to the conflicts directory is not on the list. Nor is the object of a file that was deleted, or replaced by a rename, when the store refuses to delete it: that is logged and fails sync.

Source§

impl S3Backend

Source

pub fn builder( endpoint: impl Into<String>, region: impl Into<String>, bucket: impl Into<String>, ) -> S3BackendBuilder

Settings for the bucket bucket of the store at endpoint, an https:// or http:// URL with a host, an optional port and no path. region is the region requests are signed for.

Trait Implementations§

Source§

impl Clone for S3Backend

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for S3Backend

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ShareBackend for S3Backend

Source§

fn open<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 SmbPath, opts: OpenOptions, ) -> Pin<Box<dyn Future<Output = SmbResult<(Box<dyn Handle>, OpenAction)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Open or create a file or directory. Returns a fresh handle and what the open did to the file. Read more
Delete a file or an empty directory.
Source§

fn rename<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, from: &'life1 SmbPath, to: &'life2 SmbPath, replace_if_exists: bool, ) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Rename from to to. Read more
Source§

fn capabilities(&self) -> BackendCapabilities

Static capabilities. TREE_CONNECT clamps access to read-only when is_read_only is set.
Source§

fn volume_info<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = SmbResult<VolumeInfo>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Size, free space and identity of the volume behind the share, for the filesystem QUERY_INFO classes. The default returns VolumeInfo::default.
Source§

fn open_stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, file: Box<dyn Handle>, _path: &'life1 SmbPath, _stream: &'life2 StreamName, _opts: OpenOptions, ) -> Pin<Box<dyn Future<Output = SmbResult<(Box<dyn Handle>, OpenAction)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Open or create the named stream stream of the file or directory at path. file is the handle open just gave for path, opened for reading. The backend owns it and closes it, also when this fails; it may keep it for as long as the stream’s handle lasts, so the stream follows the file through renames. opts.intent applies to the stream; opts.directory and opts.non_directory are false. The handle reads and writes the stream: its stat reports the file’s times, attributes and id with the stream’s sizes, set_times and set_attributes change the file, and truncate the stream. A write or size change of the stream updates the file’s last write time, which the protocol layer reports as a change of the file. Read more
Source§

fn remove_stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _path: &'life1 SmbPath, _file_index: u64, _stream: &'life2 StreamName, ) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Remove the named stream of the file or directory at path that stream names, whatever the case of its spelling. Fail with SmbError::NotFound when the file has no such stream. Read more
Source§

fn rename_stream<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _path: &'life1 SmbPath, _file_index: u64, _from: Option<&'life2 StreamName>, _to: Option<&'life3 StreamName>, _replace_if_exists: bool, ) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Rename a stream of the file or directory at path, which has the id file_index as ShareBackend::remove_stream says: the named stream from names, or the default stream when from is None, to the named stream to, or to the default stream when to is None. Names compare without regard to case, and a renamed stream takes the spelling of to. from and to never name the same stream, and a directory, which has no default stream, only renames a named stream to another. Read more
Source§

fn copy_range<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _src: &'life1 dyn Handle, _src_offset: u64, _dst: &'life2 dyn Handle, _dst_offset: u64, _len: u64, ) -> Pin<Box<dyn Future<Output = SmbResult<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Copies len bytes from src_offset of src to dst_offset of dst inside the storage, for a client’s server-side copy, and returns the number copied. dst is a handle this backend gave. src may be a handle of another backend or share, or of the same file as dst. A copy past the end of dst leaves a gap that reads as zeros, as Handle::write does. Read more
Source§

fn clone_range<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _src: &'life1 dyn Handle, _src_offset: u64, _dst: &'life2 dyn Handle, _dst_offset: u64, _len: u64, ) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Makes the len bytes at dst_offset of dst share their storage with the len bytes at src_offset of src, for a client’s duplicate extents request: the bytes read the same, and a later write to either file leaves the other as it is. dst is a handle this backend gave. src may be a handle of another backend or share. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more