mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* mount: buffer a write in memory when the swap file cannot take it The dirty pages of a random write, or of more files than the memory budget holds, go to a swap file under -cacheDirWrite (by default -cacheDir). On a full cache disk the swap file cannot be created, or a write into it fails, and the FUSE write failed with EIO (#12655; before it the mount panicked or acknowledged a write it had not kept). The data was still in hand. Such a chunk now stays in memory. A chunk whose swap write fails is sealed with what it holds, so its upload keeps that, and the data goes into a chunk in memory. The file then keeps chunks in memory for a 10s backoff before it tries its swap file again. The sealed chunk uploads through the swap read-back of #13198: if its earlier bytes cannot be read back either, the flush fails, while the data written again into memory still uploads. Memory stays bounded, as the sequential path bounds it: past 8 writable chunks in the file, or past the shared memory-chunk ceiling, the file seals a chunk before it creates another. Sealing waits for an upload slot, so a writer that outpaces its uploads slows down instead of filling memory. The #12655 tests made a write fail through an unusable swap directory. They now make the dirty pages refuse the write directly, and a new test checks that an unusable swap directory no longer fails it. A pipeline test covers a sealed chunk whose swap file can no longer be read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: move a refused swap chunk into memory instead of sealing it When the swap file refused a write, the first commit sealed the swap chunk with what it held and wrote the data again into a new chunk in memory at the same index. Two chunks at one index fail in two ways: - A disk that takes part of an overwrite, as a full copy-on-write disk can, leaves the swap chunk with the new first half and the old second half. Its upload joins the two under the overwrite's timestamp, and the memory chunk uploads the new bytes under the same timestamp. Equal timestamps resolve to the chunk the entry lists last, so when the swap upload finished last the old bytes came back. - Sealing the memory chunk while the swap chunk was still uploading replaced the swap chunk in the sealed slot. Until its upload finished, reads of the bytes only it held found nothing. Now the swap chunk's ranges are read back into the new memory chunk, each under its own timestamp, before the write goes in. The swap chunk then gives back its slot without an upload, so the index keeps one chunk. When the swap file cannot be read back either, or memory holds the shared ceiling of chunks, the write stores only what the swap file took and reports a short write, as master does. Memory now stays under the shared ceiling of memory chunks. Before, a file with no chunk of its own to seal allocated a new chunk past the ceiling anyway, so memory grew with the number of open files writing sparse chunks. Now that write fails. A file that has a chunk seals it to make room for the new one, as before. The per-file bound is also checked again after each seal, since a seal releases the lock. refusingDirtyPages moves to a test file built on every platform, because the copy range test also uses it on FreeBSD. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: seal a memory chunk at the shared ceiling and recheck both bounds At the shared ceiling, a file made room for a new chunk in memory by sealing any one of its writable chunks. A swap chunk left by a refused write frees no memory when it uploads, so memory went past the ceiling by one chunk for each file in that state. At the ceiling a file now seals one of its memory chunks, and if it has none the write fails. Sealing releases the lock, and other writers may create chunks meanwhile. The per-file bound was checked again after a seal made for it, but not after a seal made for the shared ceiling. One loop now checks both bounds again after every seal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: drop an empty swap chunk the swap file refused at the shared ceiling At the shared ceiling, a swap chunk created for a write that the swap file then refuses cannot move into memory. It was left in place, holding nothing. Such chunks count against the file's bound, but nothing can seal an empty chunk, so after enough refused writes a later write found nothing to seal and created a chunk past the bound anyway. The empty chunk is now dropped, giving back its slot and its write budget. A write that still finds nothing to seal at the bound fails instead of going past it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: seal a memory chunk of the file before moving a refused swap chunk at the ceiling At the shared memory ceiling a new chunk seals one of the file's memory chunks and carries on, but a swap chunk whose write the swap file refused failed the write instead. That is the first write after every backoff on a full cache disk, and every write into an existing swap chunk. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: keep the per-file bound when a refused swap chunk moves into memory A file may hold more swap chunks than swapRefusedWritableChunks. When the swap file refuses a write into a chunk created past that count, moving it into memory left the file over the bound with every chunk in memory. Seal another chunk of the file first, as a new chunk does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: write again when a refused swap chunk is sealed during a seal Moving a refused swap chunk into memory may first seal another chunk, which releases the lock. If another writer or the flusher sealed the swap chunk meanwhile, the write failed although a new chunk could take it. Write into the chunk now at the index instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Concurrent writers to one file from different mounts require -dlm; without it, a conflicting write fails with EIO and the file may refuse further appends until reopened after the cache drops.