diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c134b78..8cc3da8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,16 +22,18 @@ jobs: - name: go vet run: go vet ./... - - name: Start MinIO + # MinIO stopped publishing images (the community repo is archived), so + # the S3 integration tests run against RustFS instead. + - name: Start RustFS run: | - docker run -d --name minio \ + docker run -d --name rustfs \ -p 9000:9000 \ - -e MINIO_ROOT_USER=minio \ - -e MINIO_ROOT_PASSWORD=miniominio \ - minio/minio server /data - # Wait up to 30 s for MinIO to become ready + -e RUSTFS_ACCESS_KEY=minio \ + -e RUSTFS_SECRET_KEY=miniominio \ + rustfs/rustfs:1.0.6 + # Wait up to 30 s for RustFS to become ready for i in $(seq 1 30); do - curl -sf http://localhost:9000/minio/health/live && break + curl -sf http://localhost:9000/health && break sleep 1 done diff --git a/README.md b/README.md index c11894f..9ff6cd8 100644 --- a/README.md +++ b/README.md @@ -341,9 +341,9 @@ export FUSEY_ACCESS_KEY=... FUSEY_SECRET_KEY=... FUSEY_FORCE_PATH_STYLE=true # Unit tests (no external dependencies) go test ./... -# S3 integration tests (requires a running MinIO instance) -docker run -d -p 9000:9000 -e MINIO_ROOT_USER=test -e MINIO_ROOT_PASSWORD=testtest \ - minio/minio server /data +# S3 integration tests (requires a running S3-compatible server, e.g. RustFS) +docker run -d -p 9000:9000 -e RUSTFS_ACCESS_KEY=test -e RUSTFS_SECRET_KEY=testtest \ + rustfs/rustfs:1.0.6 FUSEY_TEST_ENDPOINT=http://localhost:9000 \ FUSEY_ACCESS_KEY=test FUSEY_SECRET_KEY=testtest \ go test ./internal/chunks/ -run TestS3 diff --git a/internal/chunks/s3_test.go b/internal/chunks/s3_test.go index 221d131..f76906e 100644 --- a/internal/chunks/s3_test.go +++ b/internal/chunks/s3_test.go @@ -17,9 +17,9 @@ import ( // s3TestStore returns an S3Store pointed at a real S3-compatible endpoint, or // skips the test if FUSEY_TEST_ENDPOINT is not set. // -// To run these tests against a local MinIO instance: +// To run these tests against a local RustFS instance: // -// docker run -p 9000:9000 -e MINIO_ROOT_USER=test -e MINIO_ROOT_PASSWORD=testtest minio/minio server /data +// docker run -p 9000:9000 -e RUSTFS_ACCESS_KEY=test -e RUSTFS_SECRET_KEY=testtest rustfs/rustfs:1.0.6 // FUSEY_TEST_ENDPOINT=http://localhost:9000 \ // FUSEY_ACCESS_KEY=test FUSEY_SECRET_KEY=testtest \ // FUSEY_TEST_BUCKET=fusey-test \ diff --git a/internal/fuse/fs.go b/internal/fuse/fs.go index f436d4d..aec4a30 100644 --- a/internal/fuse/fs.go +++ b/internal/fuse/fs.go @@ -40,6 +40,9 @@ type FSIndex interface { SetAttr(ino uint64, mode, uid, gid *uint32, size *int64, atime, mtime *int64, now int64) error CreateInode(fileType index.FileType, mode, uid, gid, rdev uint32, now int64) (uint64, error) AddDirEntry(parentIno uint64, name string, childIno uint64, now int64) error + MakeFile(parentIno uint64, name string, mode, uid, gid, rdev uint32, now int64) (uint64, error) + MakeDir(parentIno uint64, name string, mode, uid, gid uint32, now int64) (uint64, error) + MakeSymlink(parentIno uint64, name, target string, uid, gid uint32, now int64) (uint64, error) RemoveDirEntry(parentIno uint64, name string, now int64) error Rename(srcParent uint64, srcName string, dstParent uint64, dstName string, now int64) error WriteExtent(ino uint64, ext index.Extent, now int64) error diff --git a/internal/journal/journal_test.go b/internal/journal/journal_test.go index d57103f..a7a24ff 100644 --- a/internal/journal/journal_test.go +++ b/internal/journal/journal_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "strings" "testing" "time" @@ -505,3 +506,54 @@ func must(t *testing.T, err error) { t.Fatal(err) } } + +// The atomic make-node ops must be journaled (a plain pass-through to the +// embedded index would skip the journal) and must replay to the same state. +func TestJournaledIndexMakeNodeOpsReplayToLiveState(t *testing.T) { + live := index.New(4096) + j := New(true) + ji := Wrap(live, j) + now := time.Now().UnixNano() + + fileIno, err := ji.MakeFile(1, "f.txt", 0o644, 1000, 1000, 0, now) + must(t, err) + dirIno, err := ji.MakeDir(1, "d", 0o755, 1000, 1000, now+1) + must(t, err) + linkIno, err := ji.MakeSymlink(dirIno, "l", "../f.txt", 1000, 1000, now+2) + must(t, err) + + // File and dir each journal CreateInode+AddDirEntry; the symlink adds SetSymlink. + if got := j.BufferLen(); got != 7 { + t.Fatalf("buffer len: got %d, want 7", got) + } + + if _, err := ji.MakeFile(1, "f.txt", 0o644, 0, 0, 0, now+3); !errors.Is(err, index.ErrExist) { + t.Fatalf("duplicate MakeFile: got %v, want ErrExist", err) + } + if got := j.BufferLen(); got != 7 { + t.Errorf("failed create must not be journaled: buffer len %d, want 7", got) + } + + replayed, err := ReplayUpTo(index.New(4096), j.buffer, now+10) + if err != nil { + t.Fatalf("replay: %v", err) + } + + for _, c := range []struct { + parent uint64 + name string + ino uint64 + }{{1, "f.txt", fileIno}, {1, "d", dirIno}, {dirIno, "l", linkIno}} { + if got, ok := replayed.Lookup(c.parent, c.name); !ok || got != c.ino { + t.Errorf("replayed Lookup(%d, %q) = (%d, %v), want (%d, true)", c.parent, c.name, got, ok, c.ino) + } + want, _ := live.GetInode(c.ino) + got, _ := replayed.GetInode(c.ino) + if got.FileType != want.FileType || got.Nlink != want.Nlink || got.Mode != want.Mode { + t.Errorf("replayed inode %d = %+v, want type/nlink/mode of %+v", c.ino, got, want) + } + } + if target, ok := replayed.GetSymlink(linkIno); !ok || target != "../f.txt" { + t.Errorf("replayed symlink target = (%q, %v), want ../f.txt", target, ok) + } +} diff --git a/internal/journal/wrap.go b/internal/journal/wrap.go index 426da29..7af6947 100644 --- a/internal/journal/wrap.go +++ b/internal/journal/wrap.go @@ -80,6 +80,57 @@ func (ji *JournaledIndex) AddDirEntry(parentIno uint64, name string, childIno ui return nil } +// recordMade journals an atomically created node as the CreateInode + +// AddDirEntry pair that replay expects. The inode is journaled with nlink 0 +// because replay's AddDirEntry is what links it. +func (ji *JournaledIndex) recordMade(parentIno uint64, name string, ino uint64, now int64) { + if inode, ok := ji.Index.GetInode(ino); ok { + ji.j.Append(Op{ + CreateInode: &CreateInode{ + Ino: ino, FileType: inode.FileType, Mode: inode.Mode, + Nlink: 0, UID: inode.UID, GID: inode.GID, Rdev: inode.Rdev, + Atime: inode.Atime, Mtime: inode.Mtime, Ctime: inode.Ctime, + Blksize: inode.Blksize, Blocks: inode.Blocks, + }, + }, now) + } + ji.j.Append(Op{ + AddDirEntry: &AddDirEntry{ParentIno: parentIno, Name: name, ChildIno: ino}, + }, now) +} + +// MakeFile atomically creates and links a file and records the ops. +func (ji *JournaledIndex) MakeFile(parentIno uint64, name string, mode, uid, gid, rdev uint32, now int64) (uint64, error) { + ino, err := ji.Index.MakeFile(parentIno, name, mode, uid, gid, rdev, now) + if err != nil { + return ino, err + } + ji.recordMade(parentIno, name, ino, now) + return ino, nil +} + +// MakeDir atomically creates and links a directory and records the ops. +func (ji *JournaledIndex) MakeDir(parentIno uint64, name string, mode, uid, gid uint32, now int64) (uint64, error) { + ino, err := ji.Index.MakeDir(parentIno, name, mode, uid, gid, now) + if err != nil { + return ino, err + } + ji.recordMade(parentIno, name, ino, now) + return ino, nil +} + +// MakeSymlink atomically creates and links a symlink and records the ops, +// including the SetSymlink that replay needs for the target. +func (ji *JournaledIndex) MakeSymlink(parentIno uint64, name, target string, uid, gid uint32, now int64) (uint64, error) { + ino, err := ji.Index.MakeSymlink(parentIno, name, target, uid, gid, now) + if err != nil { + return ino, err + } + ji.recordMade(parentIno, name, ino, now) + ji.j.Append(Op{SetSymlink: &SetSymlink{Ino: ino, Target: target}}, now) + return ino, nil +} + // RemoveDirEntry removes a directory entry and records a RemoveDirEntry op. // If the removal drops nlink to 0, also records a DeleteInode op. func (ji *JournaledIndex) RemoveDirEntry(parentIno uint64, name string, now int64) error {