mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
* filer: free a closed file's chunks for a download waiting on the budget A weed mount stopped answering reads for three days. Its goroutine dump: 351 downloads waited in ReaderCacheBudget.reserve, all 31 releases sat in SingleChunkCacher.destroy waiting for one of them, all 100 reads waited for one of them as well, and a few goroutines spun in reserve's eviction loop. The stuck reads filled the 128 FUSE background slots, so every read of the mount blocked. Closing a file runs ReaderCache.destroy, which takes the file's chunks out of the map and then destroys them one at a time. When it reaches a download waiting for budget first, it waits for that download, and the budget the download needs can be held by the file's other chunks, which are out of the map as well: - Eviction skips a finished chunk that is out of the map. removeUnpinned refuses it, so reserve puts it back on the idle list and retries at once. When a stream is positioned in it, remove() does nothing, so reserve only takes it off the idle list. - A download that fails is never evictable, and a download destroy() cancels fails too. remove() does nothing for one that is out of the map, so its reservation stays until destroy() reaches it. Since #12616, destroy() cancels the waiting download when nothing reads it. It does not when a stream is positioned in the download because the read that started it gave up, for example because its process was killed: closing a ChunkGroup does not release the streams. Eviction now destroys a chunk that is out of its file's map instead of skipping it. Whoever took it out destroys it too, and destroy() is safe to run twice. A download that fails gives its reservation back at once, also when it is out of the map. TestReaderCacheDestroyWhileDownloadWaitsForBudget closes a file while one of its downloads waits for budget, 30 rounds per case. When the waiting download is a prefetch nobody read, the test passes on master. When a stream is positioned in it, it hangs on master, both when the downloads holding the budget are prefetches the close cancels (the release fixes this) and when streams are positioned in them too (the eviction fixes this). TestReaderCacheBudgetStress runs reads (some given up midway), prefetches, failing downloads and close/reopen on four files that share a budget of four chunks; it hangs in 10 of 10 -race runs on master. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: do not wait for a dropped download while holding another chunk A read registers on its new chunk and only then drops the chunk its stream left (unpin, removeConsumed). When that chunk's download had not finished, removeConsumed cancelled it and then waited for it in destroy(), still holding the new chunk. The download could be evicting that very chunk for budget: reserve falls back to a chunk a stream is positioned in, and destroying it waits for its reads, this one included. Neither went on. A dropped chunk whose download has ended is still destroyed at once. One still downloading, cancelled when it was dropped, is destroyed by a goroutine once the download gives up, so the read goes on. TestReaderCacheBudgetStreamsStress moves eight streams between four chunks under a budget of two and gives up a third of the reads midway. In 20 -race runs it hangs 4 times on master and 8 times with only the previous commit, in this cycle; with this change it does not hang. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>