pub struct Bucket { /* private fields */ }s3 only.Expand description
The client of a bucket repository.
Bucket::new opens it from an S3Endpoint, and
Bucket::from_fetcher opens it over a fetcher that the caller built.
Bucket::counted gives a client whose fetcher adds byte counters.
Each method takes a key or a list prefix relative to the prefix of the
repository, and the client adds PREFIX/. A key in a result is relative
to the prefix of the repository too.
§Keys
The client refuses a key that is not a key of a bucket repository, before it sends a request:
config,summary,summary.sig,extensions/ostrya/lock, andextensions/ostrya/lock-probeobjects/XX/<62 hex digits>.<ext>, in lowercase hex, with the extensioncommit,commitmeta,dirtree,dirmeta,filez, ortombstone-commitrefs/heads/<name>, with a ref name thatis_ref_nameacceptsrefs/mirrors/<id>/<name>, with an id of at most 255 bytes thatis_collection_idaccepts, and a ref name thatis_ref_nameacceptsdeltas/<2>/<41>/<target>anddeltas/<2>/<41>-<43>/<target>, with checksums in modified base64, and the targetsuperblockor a part number with no leading zerodelta-indexes/<2>/<41>.index.
A list prefix ends in /, so a list for s3://b/repo never gives the
keys of s3://b/repo2. Its segments are not empty and are not . or
...
The request path of a key encodes each byte other than A-Z, a-z,
0-9, -, ., _, ~, and / as %XX. So a + of a delta key goes
as %2B.
§Requests
The GET requests (get, get stream, the checks for an object, and the
lists) are fetches. The fetcher repeats a fetch after a transport failure
or a 408, 429, or 5xx, as Fetcher::fetch states, and fetches a failed
body of a whole read again. A check for an object is a GET with
Range: bytes=0-0, as exists states. The signature
does not cover the Range header.
The client sends a PUT, a DELETE, and the POST that starts a
multipart upload again after
Error::UploadInterrupted and
after a 408, 429, or 5xx, at most
max_retries times. The
delay starts at 250 ms, doubles each time, and stops at 2 s.
put_if_absent and
delete_if_match state their own rules, and
put_stream states more rules for the POST
requests of a multipart upload.
The client follows no redirect. The body of each listing, of each answer to a request of a multipart upload, and of each error response is at most 4 MiB.
§Errors of the server
An unsuccessful status gives Error::S3, with the code and the message
of the S3 Error document in the body. A response whose
x-amz-bucket-region header or whose Region element names a region
other than the region of the location gives Error::S3Region. An
absent key is not an error, whatever region its response names.
The body of an error response to a PUT or a DELETE that declares a
coding, or a length over 4 MiB, is not read. The status then gives
Error::S3 with no code, and the client does not send a definitive
status again.
The Debug output shows the location and the mirror of the fetcher.
Implementations§
Source§impl Bucket
impl Bucket
Sourcepub async fn new(endpoint: &S3Endpoint) -> Result<Bucket>
pub async fn new(endpoint: &S3Endpoint) -> Result<Bucket>
Opens the client of the bucket repository of endpoint.
The call builds the fetcher. It sends no request.
S3Endpoint states the HTTP options that the client takes.
§Errors
Error::InvalidInputifSigV4::newrefuses the region.Error::FetchifFetcher::newrefuses the options. An example is anhttp://endpoint withallow_cleartext_credentialsset tofalse, because the signer is a credential. Another isbasic_auth, a bearer token, or anAuthorizationheader in the options.
Sourcepub fn from_fetcher(endpoint: &S3Endpoint, fetcher: Fetcher) -> Bucket
pub fn from_fetcher(endpoint: &S3Endpoint, fetcher: Fetcher) -> Bucket
Opens the client of the bucket repository of endpoint over
fetcher.
The call builds no fetcher and sends no request. The client shares
the connection pool, the admission limit, and the counters of
fetcher. The client names each request by its URL under the
bucket_url of the location, so it does not
use the mirrors of fetcher. An example of fetcher is the fetcher
of a pull, from the options that
pull_options gives, whose mirror is the
repository_url.
The client takes the location and the retry count of endpoint.
fetcher must sign each request with the credentials and the region
of endpoint, and follow no redirect, as the fetcher of
Bucket::new does. The call cannot check this.
§Examples
use ostrya_fetch::Fetcher;
use ostrya_remote::s3::{Bucket, Environment, S3Endpoint, Settings};
let endpoint =
S3Endpoint::resolve("s3://builds/exampleos", &Settings::default(), &Environment::Process)
.await?;
let fetcher = Fetcher::new(endpoint.pull_options()?).await?;
let bucket = Bucket::from_fetcher(&endpoint, fetcher.clone());
// The fetcher reads the objects under the repository URL. The client
// reads `summary` with the S3 rules of an absent key and of an error.
let summary = bucket.get("summary", 1 << 20).await?;Sourcepub fn counted(&self, received: Vec<Arc<AtomicU64>>) -> Bucket
pub fn counted(&self, received: Vec<Arc<AtomicU64>>) -> Bucket
Returns a client of the same bucket repository whose fetcher adds counters of received body bytes.
The fetcher of the new client is Fetcher::counted of the fetcher
of this client with received, so it has the counters of this client
and the counters of received. Fetcher::counted states which
bytes each counter gets. The new client has the location, the retry
count, and the request URLs of this client. The counters of this
client do not change.
Sourcepub async fn get(&self, key: &str, max_size: u64) -> Result<Option<Object>>
pub async fn get(&self, key: &str, max_size: u64) -> Result<Option<Object>>
Reads the object of key whole, or returns None if the key holds no
object.
A 404 is an absent key if its body arrived whole and holds the code
NoSuchKey, or holds no S3 code: an empty body, or a body that is
not an S3 Error document. A 404 with another code, for example
NoSuchBucket, is an error, so a missing bucket never reads as an
empty repository. A 404 whose body did not arrive is an error too,
with no code. An absent key is not an error, whatever region its
response names. get_strict reads a key by a
strict rule, and get_for_pull by the rule of
a pull.
The bytes have the capacity of the object and one byte, if the response declares the length of the object.
§Errors
Error::InvalidInputifkeyis not a key of a bucket repository.Error::LimitExceededif the object is larger thanmax_sizebytes. The message names the key.Error::S3andError::S3Regionfor an unsuccessful response.Error::Transportif the server answers with 304. The request sends no validators, so the answer cannot be used.Error::Fetchfor a failure of the fetcher, andError::Iofor a body that failed in transit after the last refetch.
Sourcepub async fn get_strict(
&self,
key: &str,
max_size: u64,
) -> Result<Option<Object>>
pub async fn get_strict( &self, key: &str, max_size: u64, ) -> Result<Option<Object>>
Reads the object of key whole, or returns None if the key holds no
object, by a strict rule of an absent key.
A 404 is an absent key only if its body arrived whole and holds the
code NoSuchKey. Each other 404 is an error, also a 404 with an empty
body or with a body that is not an S3 Error document, for example a
page of a proxy. Use this call where a false absent key causes a loss
of data. Else the call is get.
§Errors
The errors of get. A 404 that is not an absent key
gives Error::S3 with the status 404, and with no code if the body
holds no S3 code.
Sourcepub async fn get_for_pull(
&self,
key: &str,
max_size: u64,
) -> Result<Option<Object>>
pub async fn get_for_pull( &self, key: &str, max_size: u64, ) -> Result<Option<Object>>
Reads the object of key whole, or returns None if the key holds no
object, by the rule of an absent key of a pull.
An answer that get reads as an absent key is an
absent key here too. A 403 is also an absent key if its body arrived
whole and holds the code AccessDenied. S3 answers so for an absent
key to a caller that has no s3:ListBucket on the bucket, so a pull
needs s3:GetObject alone. A 403 with another code, for example
SignatureDoesNotMatch or InvalidAccessKeyId, is an error, so a
wrong key fails at the first read. A key that holds an object that the
credentials cannot read is also an absent key here.
A pull reads summary and summary.sig with this call. It reads
config with get.
§Errors
The errors of get. A 403 that is not an absent key
gives Error::S3 with the status 403, or Error::S3Region.
Sourcepub async fn get_stream(&self, key: &str) -> Result<Option<ObjectStream>>
pub async fn get_stream(&self, key: &str) -> Result<Option<ObjectStream>>
Opens the body of the object of key as a stream, or returns None
if the key holds no object.
The stream holds no more than one chunk of the object in memory.
get states the rule of an absent key.
§Errors
The errors of get, other than the size limit: also
Error::Transport for a 304. A read of the stream fails with an I/O
error if the body fails in transit.
Sourcepub async fn get_stream_strict(&self, key: &str) -> Result<Option<ObjectStream>>
pub async fn get_stream_strict(&self, key: &str) -> Result<Option<ObjectStream>>
Opens the body of the object of key as a stream, or returns None
if the key holds no object, by the strict rule of an absent key of
get_strict.
The stream holds no more than one chunk of the object in memory.
§Errors
The errors of get_stream. A 404 that is not an
absent key gives Error::S3 with the status 404, and with no code
if the body holds no S3 code.
Sourcepub async fn exists(&self, key: &str) -> Result<bool>
pub async fn exists(&self, key: &str) -> Result<bool>
Returns true if the key key holds an object.
The request is GET KEY with Range: bytes=0-0, and the client reads
at most one byte of the object. A 206 and a 200 are an object. A 416
is an object too, because a server gives it for an object of zero
bytes. A server that ignores the range answers 200 with the whole
object. The client then refuses a declared length over one byte, and
reads no byte of it. The fetcher reads a declared body of at most
64 KiB to its end, so the connection goes back to the pool. A larger
body, or a body with no declared length, closes the connection.
The client reads a body that declares a length of at most one byte to its end, so the connection goes back to the pool. If the body fails after the status, the status decides, and the key holds an object. The client does not read a body with no declared length, and its connection closes. So a server that stalls such a body does not hold the check until the progress timeout.
get states the rule of an absent key.
exists_strict reads a key by the strict
rule.
§Errors
Error::InvalidInputifkeyis not a key of a bucket repository.Error::S3andError::S3Regionfor an unsuccessful response.Error::Transportif the server answers with 304. The request sends no validators, so the answer cannot be used.Error::Fetchfor a failure of the fetcher.
Sourcepub async fn exists_strict(&self, key: &str) -> Result<bool>
pub async fn exists_strict(&self, key: &str) -> Result<bool>
Returns true if the key key holds an object, by the strict rule of
an absent key of get_strict.
exists states the request and the rules of an
object.
§Errors
The errors of exists. A 404 that is not an absent
key gives Error::S3 with the status 404, and with no code if the
body holds no S3 code.
Sourcepub async fn put(&self, key: &str, body: Vec<u8>) -> Result<Option<String>>
pub async fn put(&self, key: &str, body: Vec<u8>) -> Result<Option<String>>
Writes body to key, and returns the ETag of the response.
The request is idempotent, so the client sends it again by the rule
of Bucket. A second request shares the bytes of the first one, so
the client holds one copy of the body.
The client hashes a body of more than 1 MiB once, on the blocking pool of the runtime, before the first request. Each request signs that digest. The signer hashes a smaller body on the task of each request.
§Errors
Error::InvalidInputifkeyis not a key of a bucket repository, or ifbodyis larger than 5 GiB, the limit of one S3PUT.Error::S3andError::S3Regionfor an unsuccessful response.Error::Fetchfor a failure of the fetcher, also after the last request that the client sent again.
Sourcepub async fn put_stream<R>(
&self,
key: &str,
body: R,
part_size: u64,
) -> Result<Option<String>>
pub async fn put_stream<R>( &self, key: &str, body: R, part_size: u64, ) -> Result<Option<String>>
Writes the bytes that body gives to key, and returns the ETag
of the answer that wrote the object, as the server wrote it.
Servers give different ETag values for one object of several
parts. Do not compare the result with the ETag of a later read of
the key.
The call reads body in parts of part_size bytes. part_size
gives the part size of an object of a known size. A body of at most
one part goes in one PUT. A longer body goes in a multipart upload:
POST KEY?uploadsstarts the upload and gives the upload id.PUT KEY?partNumber=N&uploadId=IDsends each part, one part after the other. The part numbers start at 1 and have no gap. Each part other than the last one holdspart_sizebytes.POST KEY?uploadId=IDwith aCompleteMultipartUploaddocument completes the upload. The document gives each part number with theETagof its answer, as the server wrote it.
The call holds one part in memory, with the ETag of each part that
it sent and the document that completes the upload. The first part
starts at 8 KiB and doubles up to part_size while the bytes arrive,
so a small body takes a small buffer. After each part, the call takes
the buffer back and reads the next part into it. If the fetcher still
holds the bytes of a part, the next part takes a new buffer. After a
full part, the call reads one byte more to find if the body goes on.
The call hashes each part of more than 1 MiB once, on the blocking
pool of the runtime, before the first request of the part. The part
moves to the pool and back with no copy, and each request of the part
signs that digest. The signer hashes a smaller part on the task of
each request.
The client takes an upload id and an ETag of a part of at most
1 KiB each. So the ETag values of an upload and the document that
completes it have a limit.
The client sends each part again by the rule of Bucket. A part
has the same bytes in each request. The POST that starts the upload
is sent again by the same rule, and also after a 2xx whose body did
not arrive. The POST that completes the upload is sent again after
an interrupted request, after a 408, 429, or 5xx, after a 2xx whose
body cannot be read, and after a 2xx whose body is an S3 Error
document. S3 can send such a document after the head of a 200.
After an interrupted request, a 408, 429, or 5xx, or an unusable 2xx
to the POST that completes the upload, the server can have
completed the upload. If a later request then gets a 404 with the code
NoSuchUpload, the client reads the key as
get_stream does. A Content-Length equal to
the number of bytes of the body gives success with the ETag of the
read, and the client reads no byte of the object. An absent object and
an object of another length give an error.
This check compares the length alone. It is sound for a key whose name sets its content, such as a content-addressed object or a static delta. For a key whose content changes, an older object of the same length passes the check.
After each failure that comes after the start of the upload, the
client sends one DELETE KEY?uploadId=ID to abort the upload, and
ignores its outcome. Then it returns the error of the failure. If the
last answer to a request of the upload is a 404 with the code
NoSuchUpload, the server holds no such upload, and the client sends
no abort.
A dropped future sends no abort, so the upload stays open, and it
holds storage in the bucket. list_uploads
gives each such upload, and abort_upload
aborts it. The prune of a bucket repository of the ostrya crate
aborts each such upload. To remove such uploads with no call of the
client, set a lifecycle rule on the bucket that aborts incomplete
multipart uploads.
§Errors
Error::InvalidInputifkeyis not a key of a bucket repository, or ifpart_sizeis less than 5 MiB or more than 5 GiB, the S3 limits of a part. The call then reads no byte ofbody.Error::Ioif a read ofbodyfails.Error::LimitExceededif the body is longer than 10,000 parts ofpart_sizebytes, the S3 limit of the parts of an upload. The message names the key and the part size.Error::S3andError::S3Regionfor an unsuccessful response, andError::S3for an S3Errordocument with a 2xx after the last request that the client sent again.Error::Transportif the answer that starts the upload has no usable upload id or an upload id of more than 1 KiB, if its body did not arrive after the last request that the client sent again, if the answer to a part has noETagor anETagof more than 1 KiB, or if no answer that completes the upload can be read. Also if the key holds no object or an object of another length after a 404NoSuchUploadto a completion whose outcome is not known. The message then states what the key holds.- The errors of
get_streamfor the read of the key after such a 404NoSuchUpload. Error::Fetchfor a failure of the fetcher, also after the last request that the client sent again.
Sourcepub async fn put_if_absent(
&self,
key: &str,
body: Vec<u8>,
) -> Result<PutIfAbsent>
pub async fn put_if_absent( &self, key: &str, body: Vec<u8>, ) -> Result<PutIfAbsent>
Writes body to key if the key holds no object.
The request carries If-None-Match: *. A 2xx gives
PutIfAbsent::Created. A 412 to the first request gives
PutIfAbsent::Present. A 409 with the code
ConditionalRequestConflict is sent again, at most
max_retries times.
After an interrupted request, the outcome is not known. The client
then reads the key and compares the SHA-256 of what it holds with the
SHA-256 of body:
- The same bytes give
PutIfAbsent::Matches. - Other bytes give
PutIfAbsent::Present. - An absent key sends the request again, within the retry count.
After a 408, 429, or 5xx, the client sends the request again within
the retry count. A 412 after such a status, or after an interrupted
request, can answer a request of this call. So the client then reads
the key and compares it in the same way: the same bytes give
PutIfAbsent::Refused, and other bytes or an absent key give
PutIfAbsent::Present.
The compare reads the object as a stream, in chunks of 64 KiB. A
response that declares a length other than the length of body
holds other bytes, and the client reads none of it. The client
computes the SHA-256 of body on the blocking pool of the runtime:
for a body of more than 1 MiB once before the first request, which
each request signs, and for a smaller body at the first compare.
A server that does not honor If-None-Match writes the object over
the one that the key holds, and gives PutIfAbsent::Created.
§Errors
The errors of put, and the errors of
get for the read of the key.
Sourcepub async fn delete(&self, key: &str) -> Result<()>
pub async fn delete(&self, key: &str) -> Result<()>
Deletes the object of key.
A 2xx and an absent key are success. get states the
rule of an absent key. The client sends the request again by the rule
of Bucket.
§Errors
Error::InvalidInputifkeyis not a key of a bucket repository.Error::S3andError::S3Regionfor an unsuccessful response.Error::Fetchfor a failure of the fetcher, also after the last request that the client sent again.
Sourcepub async fn delete_if_match(
&self,
key: &str,
etag: &str,
) -> Result<DeleteIfMatch>
pub async fn delete_if_match( &self, key: &str, etag: &str, ) -> Result<DeleteIfMatch>
Deletes the object of key if its ETag is etag.
The request is DELETE KEY with If-Match: ETAG. etag goes as the
server wrote it, for example the etag of a read. A
2xx gives DeleteIfMatch::Deleted. A 412 or an absent key to the
first request gives DeleteIfMatch::NotMatched.
get states the rule of an absent key. SeaweedFS 4.36
answers 412 for an absent key.
The client sends the request again by the rule of Bucket. A 412
or an absent key after a request with an unknown outcome can answer a
request of this call. So the client then reads the key as
exists does. An absent key gives
DeleteIfMatch::Deleted, and an object gives
DeleteIfMatch::NotMatched.
A server that does not honor If-Match deletes the object whatever
its ETag is, and gives DeleteIfMatch::Deleted.
rclone serve s3 1.75.1 is such a server.
§Errors
Error::InvalidInputifkeyis not a key of a bucket repository, or ifetagis empty or longer than 1 KiB. The client then sends no request.Error::S3andError::S3Regionfor an unsuccessful response.Error::Fetchfor a failure of the fetcher, also after the last request that the client sent again.- The errors of
existsfor the read of the key.
Sourcepub async fn abort_upload(&self, key: &str, upload_id: &str) -> Result<()>
pub async fn abort_upload(&self, key: &str, upload_id: &str) -> Result<()>
Aborts the multipart upload upload_id of key.
The request is DELETE KEY?uploadId=ID. A 2xx and a 404 with the
code NoSuchUpload are success, so an upload that a server already
removed is not an error. The client sends the request again by the
rule of Bucket.
§Errors
Error::InvalidInputifkeyis not a key of a bucket repository, or ifupload_idis empty.Error::S3andError::S3Regionfor an unsuccessful response.Error::Fetchfor a failure of the fetcher, also after the last request that the client sent again.
Sourcepub async fn list(&self, prefix: &str) -> Result<Listing>
pub async fn list(&self, prefix: &str) -> Result<Listing>
Lists each object under prefix, over all pages.
prefix is relative to the prefix of the repository and ends in /,
for example objects/ab/ or refs/heads/. The request is
ListObjectsV2 with the encoding type url, and the client decodes
each key.
§Errors
Error::InvalidInputifprefixdoes not end in/, or holds an empty segment,.,.., or a character outside the alphabet of a key.Error::Transportif a page cannot be used: a body that the XML reader refuses, a truncated page with no continuation token, a key outside the prefix, or a page that does not move forward. Each key and common prefix of a page comes after each one of the earlier pages, in the byte order of UTF-8. A truncated page that holds no key and no common prefix gives a continuation token that no page gave after the last page with a key or a common prefix. More than 1000 truncated pages in a row with no key and no common prefix fail the list. So a server that gives the same page again, or empty pages with no end, fails the list.Error::Transportif the server answers with 304.Error::LimitExceededif a page is larger than 4 MiB.Error::S3andError::S3Regionfor an unsuccessful response, or for an S3Errordocument with a 200.Error::FetchandError::Ioas forget.
Sourcepub async fn list_delimited(&self, prefix: &str) -> Result<Listing>
pub async fn list_delimited(&self, prefix: &str) -> Result<Listing>
Sourcepub async fn list_uploads(&self) -> Result<Vec<Upload>>
pub async fn list_uploads(&self) -> Result<Vec<Upload>>
Lists the incomplete multipart uploads of the keys of the repository, over all pages.
The request is ListMultipartUploads with the prefix PREFIX/. With
no prefix, the list covers the whole bucket, and the client keeps an
upload only if its key is a key of a bucket repository. A 404 with
the code NoSuchUpload is an empty list, because a server can answer
a bucket with no upload in this way.
§Errors
The errors of list, with the markers of the next
page in place of the continuation token. The rule of progress is
different:
- The
NextKeyMarkerof each truncated page does not come before the key marker of the page before it, in the byte order of UTF-8. - While the key marker stays the same, the
NextUploadIdMarkerof each truncated page is one that no earlier page gave for that key marker. S3 sorts the uploads of one key by the time of their start, and not by the upload id, so the upload id markers of one key have no order.
So a truncated page that holds no upload must move the markers.