Files
seaweedfs/weed/mount/content_gap.go
T
Chris LuandClaude Opus 5.5 5f97a9d088 mount: keep an unpublished create's writes, unpublished, when a peer renames onto its name (#12960)
* mount: publish an unpublished create's writeback drain after a peer rename onto its name

With -writebackCache, the drain flushes metadata only while the saved path
still maps to the handle's inode. Another mount renaming its file onto the
name of a file this mount created and has not published moves that path to
the peer's inode, so the drain skipped the flush and dropped the writes
without an error or a failed-metadata record.

A local rename or unlink of a draining handle waits for the drain or marks
it, so for an unpublished create a lost mapping means another mount's file
took the name. Skip the guard for it: the create-if-not-exists commit then
keeps a recovery record when the name is taken and publishes when it is free.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(fuse_dlm): accept only EEXIST on O_EXCL as an early second-create refusal

The concurrent create test returned early on any error from the second open,
so an EIO, or an open failure in the O_TRUNC case, passed without writing
either payload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: refuse publishing an unpublished create after a peer renames onto its name

Another mount's rename onto the name of a file this mount created but has
not published takes that name. The create used to publish there later with
create-if-not-exists as soon as the name was free again: after a local unlink
of what the name showed, it reappeared, and after a move of its directory it
landed under a path no longer reachable. markHandleReplaced now records that
the name was taken, and the publication check refuses the handle from then
on: a writeback drain keeps a recovery record and default mode fails close.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 14:09:19 -08:00

88 lines
2.7 KiB
Go

package mount
import (
"fmt"
"sort"
"sync/atomic"
"github.com/seaweedfs/seaweedfs/weed/filer"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
)
// A publication owner carries provider refusal evidence through every retry.
// Helpers and the periodic flusher never retire content that is still owned.
type contentPublication struct {
refused bool
failure *atomic.Bool
// writes is the handle's pageWrites before its pages were flushed. A
// later write is not in the published chunks, so it keeps the handle dirty.
writes uint64
}
func (p *contentPublication) retire(err error) {
if err != nil && p.refused {
p.abandon()
}
}
// An abandoned writeback drain leaves the kernel EOF past the stored one,
// whatever the filer answered.
func (p *contentPublication) abandon() {
if p.failure != nil {
p.failure.Store(true)
}
}
func (wfs *WFS) checkContentPublication(fh *FileHandle, base *filer_pb.Entry) error {
if wfs.option.WritebackCache && (fh.writebackContentError == nil || fh.writebackContentError.Load()) {
return fmt.Errorf("writeback inode awaits Forget after content refusal: %w", filer_pb.ErrPreconditionFailed)
}
if fh.nameTaken {
return fmt.Errorf("another mount renamed a file onto this unpublished create: %w", filer_pb.ErrPreconditionFailed)
}
// This guard shares the CAS version with CreateEntry. A rewritten or
// manifest bounding range cannot conceal the original kernel WRITE frontier.
var eof uint64
if base != nil {
eof = filer.FileSize(base)
}
if !wfs.option.WritebackCache && fh.pendingAppend && fh.pendingAppendOffset > eof {
return fmt.Errorf("append offset %d exceeds committed EOF %d: %w", fh.pendingAppendOffset, eof, filer_pb.ErrPreconditionFailed)
}
return nil
}
// Only used when a peer shrank the file: a merge must not acknowledge a gap
// between that stored EOF and local pending content. Ordinary sparse pwrite
// without a concurrent truncate is unaffected. Compare copies, never reorder
// a handle's chunks. A manifest's bounding range is not proof of coverage.
func contentGapAfter(entry *filer_pb.Entry, start uint64) bool {
end := filer.FileSize(entry)
if start >= end {
return false
}
chunks := append([]*filer_pb.FileChunk(nil), entry.Chunks...)
sort.SliceStable(chunks, func(i, j int) bool { return chunks[i].Offset < chunks[j].Offset })
covered := start
if uint64(len(entry.Content)) > covered {
covered = uint64(len(entry.Content))
}
for _, c := range chunks {
if covered >= end {
return false
}
if c.Offset < 0 || c.Size > ^uint64(0)-uint64(c.Offset) {
return true
}
left, right := uint64(c.Offset), uint64(c.Offset)+c.Size
if right <= covered {
continue
}
if left > covered || c.IsChunkManifest {
return true
}
covered = right
}
return covered < end
}