Skip to content

v0.30.0

Choose a tag to compare

@github-actions github-actions released this 03 Nov 11:03
· 79 commits to main since this release
37687e7

Highlights

This release lowers what osfs roots cost on listing, prefix deletes and ranged reads, and changes what a recursive listing or delete does under a symlinked directory. No on-disk format change.

  • On osfs, a recursive listing, Count or DeleteRecursive whose prefix reaches into a symlinked directory now follows the link, and a delete there removes the target's objects, even when the target lies outside the root (#490). A symlinked directory inside a root is not supported (https://github.com/mojatter/s2/blob/main/docs/backends.md#symlinks-on-osfs), but one set up to serve existing files, say ln -s /srv/media "$S2_SERVER_ROOT/media", has worked for a listing with a delimiter, the console's folder view, Get, Put and a delete by key, on v0.29.0 as on v0.30.0. v0.29.0's recursive walk found nothing under it, so a recursive delete under it removed no object, whether or not it removed the link. v0.30.0 lists, counts and deletes the target's objects; the target directory itself stays. A bucket that is itself a symlink in $S2_SERVER_ROOT is emptied the same way by the console's bucket delete, where v0.29.0 answered 204 and left the link and its target untouched. The follow is a consequence of the fix below, not a feature: the walk now starts at the prefix's directory, and fs.FS offers no way to tell a link from a directory there short of reading its parent, which is the read the fix removes; it also matches what the non-recursive listing and the by-key operations already did. Before upgrading, find links to directories under the root with find -H "${S2_SERVER_ROOT:?}" -type l -exec test -d {} \; -print (-H makes find descend when the root itself is a link) and remove each with rm, then move its target to the link's path to keep its objects. Links to files are unaffected: both versions list one as an object and read it through the link. Details in https://github.com/mojatter/s2/blob/main/docs/upgrading.md#v0300.
    • A recursive delete (DeleteRecursive) into the link, which the console's folder delete sends when no user policy applies, removes the objects under its prefix and then the link, whatever else the target holds.
    • A client that lists and then deletes by key, such as aws s3 rm --recursive or the console's folder delete under a user policy, removes them until a delete empties the target or a directory at its top level and takes the link with it, so the target's other objects can stay on disk while the client reports success.
  • A recursive List, Count or DeleteRecursive on osfs and memfs no longer reads the whole root for a prefix inside a directory (#490, fixes #469). v0.29.0 walked from the storage root, so every page under d/ read and sorted every ancestor directory of the prefix: on an Apple M4, a 100-key page under d/ took 83 ms with 100,000 objects at the root and 0.24 ms after the fix, and DeleteRecursive("d/a") with 100,000 objects in a sibling directory went from 88 ms to 1.10 ms. The walk now starts at the prefix's directory. Results are unchanged on a root without symlinks.
  • ListObjectsV2 and ListParts read metadata files in parallel through the new s2.PrefetchMetadata (#491, part of #260). On osfs, a ListObjectsV2 page opened each object's metadata file one after another to fill in its ETag. s2.PrefetchMetadata(objs) reads the Metadata of a slice of objects on up to 8 goroutines, and ListObjectsV2 and ListParts call it on the objects they are about to render. On an Apple M4, listing 1000 one-byte objects and reading every ETag went from 47.0 ms to 14.7 ms (BenchmarkListETag → BenchmarkListETagPrefetch, README). A page still reads one metadata file per object, as before; only 8 are open at once. Get and Put are unchanged, and #260 stays open.
  • Ranged GETs on osfs are served with sendfile, as full GETs already were (#494, fixes #431). fs's OpenRange wrapped the seeked file in its own reader, so net could not reach the file and the body went through user space. On an Apple M4 over loopback, a ranged GET of almost all of a 2 GiB object cost the server 0.95 s of CPU before and 0.15 s after, about the same as a full GET. Responses are unchanged.
  • The README no longer calls the osfs fsync a durability guarantee (#492). An osfs write fsyncs the object and its metadata file before renaming each into place, but not the directories after the rename, so an acknowledged write can still come back as it was before a power loss or kernel crash. That has been so since the write path first fsynced and is tracked in #493; this release changes the wording, not the write path.

Changes

Fixed

  • fs: recursive List, Count and DeleteRecursive walk from the prefix's directory (path.Dir(prefix)) instead of the root, and DeleteRecursive skips a directory the prefix rules out, as Count already did; a prefix under an object (a.txt/x/) still returns an empty result with no error (#490, fixes #469)
  • fs: on osfs, a recursive List, Count and DeleteRecursive whose prefix reaches into a symlinked directory follow the link, as the non-recursive List already did; before, the recursive walk listed, counted and deleted nothing under it (#490)

Performance

  • s2: new PrefetchMetadata(objs []Object) calls Metadata() on every object, on up to 8 goroutines at once, and returns once all are done; it reports no errors (#491, part of #260)
  • server: ListObjectsV2 prefetches the objects it renders, after the delimiter grouping and the max-keys cut; ListParts prefetches each page of parts (#491)
  • fs, server: a ranged GET on osfs is served with sendfile; fs's range reader exposes its *io.LimitedReader through a LimitedReader() method and server.CopyBody hands it to net; no exported type is added (#494, fixes #431)

Documentation

  • README: the Go-native benchmark table is re-run (storage-layer PUT on osfs 9.4 ms, GET 83 µs), the fsync paragraph now says the PUT path fsyncs the object and its metadata file (7 to 8 ms of the 9.4 ms) and no longer calls that a durability guarantee (see #493), the memfs ratios are GetObject about 60x and PutObject over 1000x, a "Listing" table lists the five List benchmarks, and the warp table is re-run (#492, fixes #261, refs #260)
  • docs/backends.md: a "Symlinks on osfs" section describes what osfs does with a symlink, replacing the one-line note (#490, #496)
  • docs/upgrading.md: a v0.30.0 section (#495)

CI / Build

  • make bench also runs BenchmarkList, BenchmarkListETag, BenchmarkListETagPrefetch, BenchmarkListMemFS and BenchmarkListETagMemFS; the List benchmarks seed their objects without fsync, so make bench takes 35 s instead of 61 s (#492)
  • Bump intra-repo deps to v0.30.0 (#495); v0.29.0 bookkeeping for cmd/s2-server (#489)

Upgrading

  • Submodule consumers: go get github.com/mojatter/s2/<module>@v0.30.0
  • s2-server operators running the image: docker pull mojatter/s2-server:0.30.0 (:latest points at it too)
  • cmd/s2-server/v0.30.0 is published separately, shortly after: go install github.com/mojatter/s2/cmd/s2-server@v0.30.0
  • No module's go directive moved and go.work is unchanged since v0.29.0.
  • No configuration changes and no on-disk format change; downgrading to v0.29.0 is safe. Operators on an osfs root with a symlinked directory under it have something to check before upgrading, in https://github.com/mojatter/s2/blob/main/docs/upgrading.md#v0300.
  • osfs writes are not crash-durable, on this version as on every earlier one: the object and its metadata file are fsynced, the directories after the rename are not (#493). The README said "durability guarantee" until #492; nothing in the write path changed.

Library users

  • s2: PrefetchMetadata(objs []Object) is new. Call it on a List page before reading ETag, ContentType or Metadata of each object. It calls Metadata() once per object on up to 8 goroutines, a fixed count that does not follow GOMAXPROCS, takes no context, and returns once every call is done. It reports no errors: a read fails as the accessor would, and on fs an object whose metadata file is missing or corrupt reports an empty Metadata and ContentType and falls back to the mtime-size ETag form, as it did before. On s3, gcs and azblob, whose List objects already hold their attributes, Metadata() is a field read, so the call costs only the goroutines.
  • fs: a recursive List, Count or DeleteRecursive under a prefix inside a directory, such as d/ or d/2024, no longer reads the root; a prefix at the root's level, such as d, still reads the root, where its keys begin. Results are unchanged on a root without symlinks.
  • fs on osfs: a recursive List or Count whose prefix reaches into a symlinked directory now returns the objects of the link's target, and DeleteRecursive removes the objects under its prefix, even when the target lies outside the root, and then removes the link, whatever else the target holds; the target directory stays. v0.29.0 returned nothing under such a prefix and DeleteRecursive removed no object, whether or not it removed the link. On both versions a prefix that stops at the link lists it as an object, a non-recursive List under it returns the target's entries, Get, Put, Exists and Delete by key go through the link, and a Delete that empties the target or a directory at its top level removes the link as well, and Delete of the link's own key removes nothing and succeeds. A symlink to a file is listed as an object and read through the link on both versions, and a prefix under it returns nothing. memfs has no symlinks. A symlinked directory inside a root stays unsupported.
  • The s2.Storage and s2.Uploader interfaces are unchanged.

Storage implementers

  • s2-server now calls Metadata() on the objects of one List page from up to 8 goroutines at once, in ListObjectsV2 (the objects it is about to render) and ListParts (each page of parts). Each object's Metadata() is called once by the prefetch; the concurrency is across objects of one page, and ETag() and ContentType() are read afterwards on one goroutine. The Concurrency section of the s2 package doc already requires Name, Length, LastModified, Metadata, ContentType and ETag to be safe for concurrent use and a backend that resolves an attribute lazily to synchronize that itself, so an implementation that follows it needs no change.
  • s2test is unchanged between v0.29.0 and v0.30.0, and none of its checks calls an object's accessors from more than one goroutine, so a backend that resolves an attribute lazily without synchronizing it passes s2test and races under s2-server. Run your own test of that under -race until the suite covers it.

s2-server operators

  • Read https://github.com/mojatter/s2/blob/main/docs/upgrading.md#v0300. s3, gcs and azblob roots are unchanged by this release except that ListObjectsV2 and ListParts spend a few goroutines on the prefetch.
  • On osfs and memfs, a ListObjectsV2 without a delimiter, the console's search and the console's folder delete under a prefix inside a directory, such as d/ or d/2024, no longer read the bucket's root; a prefix at the bucket's level, such as d, still does. ListObjectsV2 and ListParts on osfs read up to 8 metadata files at once.
  • On osfs, a symlinked directory inside the root, which is not supported, is now followed by a recursive listing or delete whose prefix reaches into it, even when the target lies outside the root: ListObjectsV2 without a delimiter and the console's search list the objects of the link's target, and the two deletes below reach them; the target directory itself stays. v0.29.0 listed nothing under such a prefix, so such a delete removed no object, whether or not it removed the link. A listing from above the link shows it as an object, and a listing with a delimiter, the console's folder view and a delete by key followed the link, on both versions, so a delete by key under the link removed the target's object on v0.29.0 too. A symlink to a file is unaffected: both versions list it as an object and serve it through the link.
    • A recursive delete under the link, which the console's folder delete sends when no user policy applies, removes the objects under its prefix and then the link, whatever else the target holds.
    • A client that lists and then deletes by key, such as aws s3 rm --recursive s3://<bucket>/<link>/ or the console's folder delete under a user policy, removes them one by one until a delete empties the target or a directory at its top level and takes the link with it, after which the remaining deletes and listings find nothing and succeed, so the target's other objects stay on disk while the client reports success.
  • This includes a bucket that is itself a symlink in $S2_SERVER_ROOT: the console's bucket delete now empties the link's target and removes the link, and DeleteBucket does the same when the target holds nothing but .keep (otherwise both versions answer 409 BucketNotEmpty), where v0.29.0 answered 204 and left the link and its target untouched, so the bucket stayed. Neither version lists such a bucket in ListBuckets or the console. A bucket bind-mounted into the root, as the README's Docker example does, is a directory, not a link, and is unaffected.
  • To find links to directories before upgrading, run find -H "${S2_SERVER_ROOT:?}" -type l -exec test -d {} \; -print; -H makes find descend when the root itself is a link, and the command lists links to directories only. Remove each with rm, then move its target to the link's path to keep its objects: a DeleteObject of the link's key answers 204 and leaves it, on both versions.
  • Ranged GETs on osfs are served with sendfile, as full GETs already were; responses are unchanged. A write error on a ranged GET other than the client going away is now logged at Error, as for a full GET; the client going away stays at Debug.

Full Changelog

v0.29.0...v0.30.0