Skip to content

fix(storage): forward on_piece_completed through the storage middlewares - #653

Open
zond wants to merge 1 commit into
ikatson:mainfrom
zond:storage-middleware-forward-on-piece-completed
Open

zond wants to merge 1 commit into
ikatson:mainfrom
zond:storage-middleware-forward-on-piece-completed

Conversation

@zond

@zond zond commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

A storage middleware is transparent: it has an opinion about a couple of methods and everything else has to reach the storage underneath. The three in storage::middleware override pread/pwrite/remove/ensure_len/take/remove_dir/init and stop there, so on_piece_completed - the one method with a default that a storage is likely to implement - never got past the middleware.

Its default does nothing, which is exactly the wrong thing to do on a storage's behalf. It is the callback a storage uses to make a piece durable or visible once it is written and hash-checked: write it under a temporary name and move it into place, flush it, promote it out of a staging area. Wrap such a storage in TimingStorage to find out why it is slow, or in the write-through cache, and the call goes to the middleware's default instead - so nothing is ever promoted, and the storage quietly stops working in the one configuration you added the middleware to debug.

Forward it in all three, and check every wrapper around a storage against a probe that records the completions it was told about, so one that doesn't forward is caught. Box already forwards it and now says so in a test: what a torrent holds is a Box, so a method it drops is one no storage ever gets asked.

Yet another PR created by my Claude Fable, but it looks correct.

A storage middleware is transparent: it has an opinion about a couple of methods
and everything else has to reach the storage underneath. The three in
storage::middleware override pread/pwrite/remove/ensure_len/take/remove_dir/init
and stop there, so on_piece_completed - the one method with a default that a
storage is likely to implement - never got past the middleware.

Its default does nothing, which is exactly the wrong thing to do on a storage's
behalf. It is the callback a storage uses to make a piece durable or visible once
it is written and hash-checked: write it under a temporary name and move it into
place, flush it, promote it out of a staging area. Wrap such a storage in
TimingStorage to find out why it is slow, or in the write-through cache, and the
call goes to the middleware's default instead - so nothing is ever promoted, and
the storage quietly stops working in the one configuration you added the
middleware to debug.

Forward it in all three, and check every wrapper around a storage against a probe
that records the completions it was told about, so one that doesn't forward is
caught. Box<U> already forwards it and now says so in a test: what a torrent
holds is a Box<dyn TorrentStorage>, so a method it drops is one no storage ever
gets asked.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@zond
zond force-pushed the storage-middleware-forward-on-piece-completed branch from 4598ab0 to 1e924f8 Compare September 7, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant