mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
* mount: flush open files before shutdown On SIGTERM the mount unmounted and exited without uploading the buffered writes of files still open, so a pod deletion dropped data the kernel had already acknowledged. The interrupt hook now flushes every dirty open handle like fsync, inside the existing 30s shutdown bound. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: refuse writes once the shutdown flush starts A write admitted after its handle was flushed was acknowledged and then lost when the process exited. The shutdown flush now sets a flag that Write checks under the handle lock, takes every handle lock once to wait out the writes already admitted, and reports whether every flush succeeded. The test now buffers real bytes and checks they are uploaded and committed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: wait for each handle inside the shutdown flush workers Waiting for every handle lock before flushing any file let one slow handle use up the shutdown bound for all the others. Each worker now waits for its own handle and flushes it if dirty. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: refuse copy, fallocate and handle attribute changes during the shutdown flush copy_file_range, fallocate, and setattr/xattr on an open handle also leave their result only in the handle. One that lands after the shutdown flush has passed its handle was acknowledged and then lost at exit, as writes were before. Like Write, they now return EIO once the flush starts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: leave the meta cache open when the shutdown flush times out A flush still running after the 30s bound holds its handle's lock. Closing the meta cache drains queued invalidations, and one for that handle waits on the same lock, so the hook blocked past its bound until the flush gave up. Skip the close in that case, as the write cache removal already is; the process exits right after the hooks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: keep the read cache dir when the shutdown flush times out By default the write cache lives inside the read cache dir, so removing the read cache on the timeout path deleted the swap files that the still running flushes read, along with the meta store left open for them. Remove both dirs only after the flushes drain. The meta store is recreated on the next start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: keep a close's writeback deferral through the shutdown flush A writeback close marks the handle for the background drain. If the shutdown flush started on that handle between the close's flush and its release, it cleared the mark, so the release took the immediate path: it fenced the handle's publication and destroyed its pages while the shutdown flush still uploaded them. Once shutdown starts, a synchronous flush leaves the mark, and the release drains as usual. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
2.4 KiB
Go
83 lines
2.4 KiB
Go
package mount
|
|
|
|
import (
|
|
"syscall"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/go-fuse/v2/fuse"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
)
|
|
|
|
// See https://man7.org/linux/man-pages/man2/fallocate.2.html
|
|
const FALLOC_FL_KEEP_SIZE uint32 = 0x01
|
|
|
|
// Fallocate allocates space for an open file. Volume space is assigned when a
|
|
// write is flushed, so nothing can be reserved up front; only a range past the
|
|
// end of the file has an effect, growing it the way a truncate would.
|
|
func (wfs *WFS) Fallocate(cancel <-chan struct{}, in *fuse.FallocateIn) (code fuse.Status) {
|
|
|
|
// ENOSYS makes the kernel stop sending FUSE_FALLOCATE for every mode, so a
|
|
// mode we cannot honor has to be refused on its own.
|
|
if in.Mode&^FALLOC_FL_KEEP_SIZE != 0 {
|
|
return fuse.ENOTSUP
|
|
}
|
|
|
|
fh := wfs.GetHandle(FileHandleId(in.Fh))
|
|
if fh == nil {
|
|
return fuse.EBADF
|
|
}
|
|
|
|
fhActiveLock := fh.wfs.fhLockTable.AcquireLock("Fallocate", fh.fh, util.ExclusiveLock)
|
|
defer fh.wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock)
|
|
if wfs.shuttingDown.Load() {
|
|
return fuse.EIO
|
|
}
|
|
|
|
entry := fh.GetEntry().GetEntry()
|
|
if entry == nil {
|
|
return fuse.ENOENT
|
|
}
|
|
|
|
oldFileSize := filer.FileSize(entry)
|
|
newFileSize := in.Offset + in.Length
|
|
if in.Mode&FALLOC_FL_KEEP_SIZE != 0 || newFileSize <= oldFileSize {
|
|
return fuse.OK
|
|
}
|
|
|
|
if wfs.IsOverQuotaWithUncommitted() {
|
|
return fuse.Status(syscall.ENOSPC)
|
|
}
|
|
|
|
if wormEnforced, _ := wfs.wormEnforcedForEntry(fh.FullPath(), entry); wormEnforced {
|
|
return fuse.EPERM
|
|
}
|
|
|
|
glog.V(4).Infof("Fallocate %s fh %d grow to %d", fh.FullPath(), fh.fh, newFileSize)
|
|
|
|
// Content inside the entry reads no further than itself: it becomes a
|
|
// write of the handle's, before the file grows past it.
|
|
now := time.Now()
|
|
if err := fh.bufferInlineContent(entry, now.UnixNano()); err != nil {
|
|
glog.Errorf("%v", err)
|
|
return writeErrorToFuseStatus(err)
|
|
}
|
|
entry.Attributes.FileSize = newFileSize
|
|
entry.Attributes.Md5 = nil
|
|
// The writes that fill the range will not grow the file, so they charge
|
|
// nothing; the growth is counted here or the quota never sees it.
|
|
wfs.AddUncommittedBytes(int64(newFileSize - oldFileSize))
|
|
|
|
entry.Attributes.Mtime = now.Unix()
|
|
entry.Attributes.MtimeNs = int32(now.Nanosecond())
|
|
entry.Attributes.Ctime = now.Unix()
|
|
entry.Attributes.CtimeNs = int32(now.Nanosecond())
|
|
|
|
fh.dirtyMetadata = true
|
|
wfs.invalidateOpenMtimeCache(in.NodeId)
|
|
|
|
return fuse.OK
|
|
}
|