Files
seaweedfs/test/fuse_dlm/concurrent_create_test.go
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

81 lines
2.3 KiB
Go

//go:build linux || darwin
package fuse_dlm
import (
"bytes"
"errors"
"os"
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/require"
)
// TestConcurrentCreateWithoutDLM has two mounts without -dlm create the same
// new file, each before the other closes, with different bytes. Mount 0
// closes first; mount 1 closes once mount 0's entry has had time to reach it.
//
// A close() that returns success must not lose its writes. If mount 1's close
// succeeds, both mounts must read mount 1's bytes; if it fails, the conflict
// was reported and both must read mount 0's bytes.
func TestConcurrentCreateWithoutDLM(t *testing.T) {
if testing.Short() {
t.Skip("skipping FUSE integration test in short mode")
}
cluster := startTestCluster(t, false)
t.Cleanup(cluster.Stop)
wantA := bytes.Repeat([]byte("A"), 4096)
wantB := bytes.Repeat([]byte("B"), 4096)
for _, tc := range []struct {
name string
flags int
}{
{"trunc", os.O_CREATE | os.O_WRONLY | os.O_TRUNC},
{"excl", os.O_CREATE | os.O_WRONLY | os.O_EXCL},
} {
t.Run(tc.name, func(t *testing.T) {
pathA := filepath.Join(cluster.mountPoints[0], tc.name)
pathB := filepath.Join(cluster.mountPoints[1], tc.name)
fa, err := os.OpenFile(pathA, tc.flags, 0644)
require.NoError(t, err)
fb, err := os.OpenFile(pathB, tc.flags, 0644)
if err != nil {
// Refusing the second exclusive create up front is also correct.
require.NoError(t, fa.Close())
require.True(t, tc.flags&os.O_EXCL != 0 && errors.Is(err, os.ErrExist), "open on mount 1: %v", err)
return
}
_, err = fa.Write(wantA)
require.NoError(t, err)
_, err = fb.Write(wantB)
require.NoError(t, err)
require.NoError(t, fa.Close())
// Give mount 0's create time to reach mount 1 before it closes.
time.Sleep(2 * time.Second)
closeB := fb.Close()
t.Logf("close on mount 1: %v", closeB)
want, which := wantB, "mount 1's close succeeded, so its"
if closeB != nil {
want, which = wantA, "mount 1's close failed, so mount 0's"
}
require.Eventually(t, func() bool {
for _, p := range []string{pathA, pathB} {
got, err := os.ReadFile(p)
if err != nil || !bytes.Equal(got, want) {
return false
}
}
return true
}, 10*time.Second, 200*time.Millisecond, "%s bytes must be the file's content on both mounts", which)
})
}
}