mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
Stop lifecycle ancestor sync at the state filesystem boundary
This commit is contained in:
1 parent
94e6fcf61c
commit
d6d06bf7bb
10 files changed
+168
-33
No files matched your search
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@@ -105,15 +104,7 @@ func OpenNodeInventoryStore(dir string) (*NodeInventoryStore, error) {
|
||||
return nil, fmt.Errorf("lifecycle: mkdir node inventory %q: %w", dir, err)
|
||||
}
|
||||
// INV-LIFECYCLE-STORE-DURABLE-001: existence does not prove durability.
|
||||
// Every open syncs the full ancestor chain, also after a failed first open.
|
||||
for parent := filepath.Dir(dir); ; parent = filepath.Dir(parent) {
|
||||
if err := syncBindingParent(parent); err != nil {
|
||||
log.Printf("lifecycle: could not sync %s (%v): the store directory entry may not survive a crash right after its creation", parent, err)
|
||||
}
|
||||
if parent == filepath.Dir(parent) {
|
||||
break
|
||||
}
|
||||
}
|
||||
syncStoreAncestors(dir)
|
||||
|
||||
s := &NodeInventoryStore{
|
||||
dir: dir,
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
@@ -66,15 +65,7 @@ func OpenPlacementIntentStore(dir string) (*PlacementIntentStore, error) {
|
||||
return nil, fmt.Errorf("lifecycle: mkdir placement intent %q: %w", dir, err)
|
||||
}
|
||||
// INV-LIFECYCLE-STORE-DURABLE-001: existence does not prove durability.
|
||||
// Every open syncs the full ancestor chain, also after a failed first open.
|
||||
for parent := filepath.Dir(dir); ; parent = filepath.Dir(parent) {
|
||||
if err := syncBindingParent(parent); err != nil {
|
||||
log.Printf("lifecycle: could not sync %s (%v): the store directory entry may not survive a crash right after its creation", parent, err)
|
||||
}
|
||||
if parent == filepath.Dir(parent) {
|
||||
break
|
||||
}
|
||||
}
|
||||
syncStoreAncestors(dir)
|
||||
|
||||
s := &PlacementIntentStore{
|
||||
dir: dir,
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
@@ -120,15 +119,7 @@ func OpenFileStore(dir string) (*FileStore, error) {
|
||||
return nil, fmt.Errorf("lifecycle: mkdir %q: %w", dir, err)
|
||||
}
|
||||
// INV-LIFECYCLE-STORE-DURABLE-001: existence does not prove durability.
|
||||
// Every open syncs the full ancestor chain, also after a failed first open.
|
||||
for parent := filepath.Dir(dir); ; parent = filepath.Dir(parent) {
|
||||
if err := syncBindingParent(parent); err != nil {
|
||||
log.Printf("lifecycle: could not sync %s (%v): the store directory entry may not survive a crash right after its creation", parent, err)
|
||||
}
|
||||
if parent == filepath.Dir(parent) {
|
||||
break
|
||||
}
|
||||
}
|
||||
syncStoreAncestors(dir)
|
||||
|
||||
s := &FileStore{
|
||||
dir: dir,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//go:build linux
|
||||
|
||||
package lifecycle
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
func directoryDevice(path string) (uint64, error) {
|
||||
var st unix.Stat_t
|
||||
if err := unix.Stat(path, &st); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint64(st.Dev), nil
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
//go:build !linux
|
||||
|
||||
package lifecycle
|
||||
|
||||
import "errors"
|
||||
|
||||
func directoryDevice(string) (uint64, error) {
|
||||
return 0, errors.New("filesystem device comparison is unavailable on this platform")
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package lifecycle
|
||||
|
||||
import (
|
||||
"log"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Isolated subprocess tests replace device lookup without requiring mounts.
|
||||
var statDirectoryDevice = directoryDevice
|
||||
|
||||
// syncStoreAncestors protects every directory entry MkdirAll can create.
|
||||
// A mount point predates product startup: sync its filesystem root, but do not
|
||||
// cross into the installer's filesystem. Unknown devices keep the full walk.
|
||||
// The caller's separate records-directory recovery barrier remains mandatory.
|
||||
func syncStoreAncestors(dir string) {
|
||||
device, err := statDirectoryDevice(dir)
|
||||
checkBoundary := err == nil
|
||||
if err != nil {
|
||||
logDeviceFallback(dir, err)
|
||||
}
|
||||
for parent := filepath.Dir(dir); ; parent = filepath.Dir(parent) {
|
||||
if checkBoundary {
|
||||
parentDevice, err := statDirectoryDevice(parent)
|
||||
if err != nil {
|
||||
logDeviceFallback(parent, err)
|
||||
checkBoundary = false
|
||||
} else if parentDevice != device {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err := syncBindingParent(parent); err != nil {
|
||||
log.Printf("lifecycle: could not sync %s (%v): the store directory entry may not survive a crash right after its creation", parent, err)
|
||||
}
|
||||
if parent == filepath.Dir(parent) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func logDeviceFallback(path string, err error) {
|
||||
log.Printf("lifecycle: could not determine filesystem device for %s (%v): syncing ancestors through the filesystem root", path, err)
|
||||
}
|
||||
@@ -15,11 +15,11 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// INV-LIFECYCLE-STORE-DURABLE-001: every open syncs the full ancestor chain,
|
||||
// including a retry after failed creation; a trailing separator changes no target.
|
||||
// INV-LIFECYCLE-STORE-DURABLE-001: every open syncs the same-device ancestors,
|
||||
// including the mount root; unknown devices retain the full ancestor walk.
|
||||
func TestLifecycleStoreParentSync(t *testing.T) {
|
||||
for _, kind := range []string{"node", "volume", "placement"} {
|
||||
for _, shape := range []string{"nested", "trailing-slash", "failed-parent-sync", "ancestor-permission", "relative-path"} {
|
||||
for _, shape := range []string{"nested", "trailing-slash", "failed-parent-sync", "ancestor-permission", "relative-path", "mount-boundary", "store-is-mount-root", "stat-store-failure", "stat-ancestor-failure", "stat-later-failure"} {
|
||||
t.Run(kind+"/"+shape, func(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
@@ -40,6 +40,17 @@ func TestLifecycleStoreParentSyncChild(t *testing.T) {
|
||||
}
|
||||
shape := os.Getenv("LIFECYCLE_PARENT_SHAPE")
|
||||
dir := filepath.Join(root, "new-parent", "deeper", "store")
|
||||
mountRoot := filepath.Join(root, "new-parent")
|
||||
if shape == "store-is-mount-root" {
|
||||
dir = filepath.Join(root, "mounted-store")
|
||||
mountRoot = dir
|
||||
}
|
||||
if shape == "mount-boundary" || shape == "store-is-mount-root" {
|
||||
// The installer/runtime creates the mount point before product startup.
|
||||
if err := os.MkdirAll(mountRoot, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if shape == "trailing-slash" {
|
||||
dir = filepath.Join(root, "store") + string(os.PathSeparator)
|
||||
}
|
||||
@@ -61,7 +72,40 @@ func TestLifecycleStoreParentSyncChild(t *testing.T) {
|
||||
}
|
||||
want = append(want, "/")
|
||||
ancestor := want[len(want)-2]
|
||||
if shape == "mount-boundary" {
|
||||
want = []string{filepath.Dir(abs), mountRoot}
|
||||
} else if shape == "store-is-mount-root" {
|
||||
want = nil
|
||||
}
|
||||
want = append(want, abs)
|
||||
// Independently remember every directory entry this Open must create.
|
||||
var createdParents []string
|
||||
for entry := abs; ; entry = filepath.Dir(entry) {
|
||||
if _, err := os.Stat(entry); err == nil {
|
||||
break
|
||||
} else if !os.IsNotExist(err) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
createdParents = append(createdParents, filepath.Dir(entry))
|
||||
}
|
||||
statDirectoryDevice = func(path string) (uint64, error) {
|
||||
if (shape == "stat-store-failure" && path == abs) || (shape == "stat-ancestor-failure" && path == filepath.Dir(abs)) || (shape == "stat-later-failure" && path == mountRoot) {
|
||||
return 0, &os.PathError{Op: "stat", Path: path, Err: os.ErrPermission}
|
||||
}
|
||||
if shape == "mount-boundary" || shape == "store-is-mount-root" {
|
||||
if path == mountRoot || strings.HasPrefix(path, mountRoot+"/") {
|
||||
return 2, nil
|
||||
}
|
||||
return 1, nil
|
||||
}
|
||||
if strings.HasPrefix(shape, "stat-") {
|
||||
if path == abs || (shape == "stat-later-failure" && path == filepath.Dir(abs)) {
|
||||
return 2, nil
|
||||
}
|
||||
return 1, nil // a stat error must disable even this later boundary
|
||||
}
|
||||
return 1, nil // keep the original same-device-through-root controls
|
||||
}
|
||||
var calls []string
|
||||
var warnings bytes.Buffer
|
||||
log.SetOutput(&warnings)
|
||||
@@ -115,6 +159,18 @@ func TestLifecycleStoreParentSyncChild(t *testing.T) {
|
||||
if !reflect.DeepEqual(calls, want) {
|
||||
t.Fatalf("parent syncs %v want %v", calls, want)
|
||||
}
|
||||
for _, parent := range createdParents {
|
||||
found := false
|
||||
for _, call := range calls {
|
||||
found = found || call == parent
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("created entry's parent %q was not synced: %v", parent, calls)
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(shape, "stat-") && (!strings.Contains(warnings.String(), "could not determine filesystem device") || !strings.Contains(warnings.String(), "syncing ancestors through the filesystem root")) {
|
||||
t.Fatalf("missing stat-error fallback warning: %s", warnings.String())
|
||||
}
|
||||
if shape == "ancestor-permission" {
|
||||
if strings.Count(warnings.String(), "lifecycle: could not sync ") != 1 || !strings.Contains(warnings.String(), "permission denied") || !strings.Contains(warnings.String(), "the store directory entry may not survive a crash right after its creation") {
|
||||
t.Fatalf("missing permission warning: %s", warnings.String())
|
||||
|
||||
@@ -1031,6 +1031,8 @@ Notes:
|
||||
|
||||
Notes:
|
||||
|
||||
- `INV-LIFECYCLE-STORE-DURABLE-001` directory coverage: volume, node and placement Open share `core/lifecycle/store_parent_sync.go` `syncStoreAncestors`. It syncs same-device ancestors through the mount root; an unknown device retains the full walk. The mandatory records-directory recovery barrier is unchanged. The mount point is installed externally: run `sync` after creating and mounting the state filesystem. See [the durability argument and installation residual](lifecycle-directory-sync.md).
|
||||
|
||||
- `INV-LIFECYCLE-STORE-DURABLE-001` open gaps: Store-directory ancestor sync on Open is best-effort: failures are logged and do not block startup; a new directory entry may not survive an immediate crash when an ancestor cannot be synced. Record-file and store-directory sync after a put remain mandatory. `NodeInventoryStore.RemoveNode`, `PlacementIntentStore.DeletePlacement` and `FileStore.DeleteVolume` do not fsync their directory after deletion, so a removed node, placement or volume record can reappear after a crash. A failed put may still be on disk: if directory fsync fails after rename, restart can load the new record.
|
||||
- `INV-AUTH-PERSIST-BEFORE-PUBLISH-001`: a failure before the rename leaves the old record and is reported failed (the in-memory rollback test); a directory open or fsync failure after the rename leaves the outcome unknown and fail-stops the process, for every record type, so the restart reloads whatever survived and callers re-read. A workspace volume's uncertainty latch (`INV-AUTH-UNCERTAIN-001`) stays for its other causes.
|
||||
- `INV-AUTH-UNCERTAIN-001`: The cited test asserts the refusal after an unknown-outcome lease extension (rename landed, then a failure; the file store fail-stops on a directory fsync failure instead, `INV-AUTH-PERSIST-BEFORE-PUBLISH-001`): the next renewal, a revocation and an endpoint change are all refused. The TLA+ configuration `S5_red_noUncertain` violates `UniqueEpoch` without it. A Revoking lease still gets its bounded drain reply, min(horizon, deadline), never extended: see M2 any (workspace) → Uncertain. A failed move on an uncertain volume is answered as an unknown outcome before any admission refusal, the request's own cancellation or deadline stays typed, and an issued move's replay still returns its stored grant: see M2 Uncertain → Uncertain (move answer). The renewal path reads uncertainty from the lease view (`INV-LEASE-VIEW-001`), not from `persistWorkspaceLocked`.
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
# Lifecycle directory recovery at a filesystem boundary
|
||||
|
||||
Opening a volume, node or placement store first creates missing directories.
|
||||
Each newly created directory entry needs its parent directory synced. The shared
|
||||
`syncStoreAncestors` helper syncs ancestors on the store's filesystem, including
|
||||
its mount root, and stops before the first ancestor with another device id.
|
||||
The separate records-directory recovery barrier remains mandatory before any
|
||||
loaded records are published or equality shortcuts become available.
|
||||
|
||||
The product does not mount filesystems or create their mount points. A mount
|
||||
point already exists when `MkdirAll` runs, so every directory it creates is below
|
||||
that point and every created entry has its parent within the synced range.
|
||||
When the store directory is itself the mount root, the ancestor walk syncs no
|
||||
parent on another filesystem; its own recovery barrier still syncs the store.
|
||||
Same-device paths continue through the filesystem root, including bind mounts.
|
||||
|
||||
A device lookup failure logs the failure and disables boundary detection for
|
||||
the rest of that walk. The helper then syncs through the root as before. Linux
|
||||
uses `stat` device ids; other platforms retain the full walk. Ancestor sync
|
||||
failures keep their existing warning contract. No record-write barrier, import
|
||||
syncfs selection, authority rule or persistent format changes.
|
||||
|
||||
One installation risk remains: a machine crash can lose a newly created mount
|
||||
point's entry on its parent filesystem if that filesystem has not committed it.
|
||||
The stored data remains on the unmounted filesystem. Run `sync` after creating
|
||||
and mounting the state filesystem, before starting blockmaster. A state path
|
||||
that is required to be mounted must not silently fall back to an empty directory
|
||||
on the parent filesystem.
|
||||
|
||||
The optimization avoids syncing unrelated ancestor filesystems. It does not
|
||||
bound waits inside the state filesystem or its records-directory recovery
|
||||
barrier. The walk adds device lookups proportional to path depth; no startup
|
||||
latency improvement is claimed without measurement.
|
||||
|
||||
`TestLifecycleStoreParentSync` covers each constructor, the same-device walk,
|
||||
mount boundary, store-as-mount-root, device lookup failures and independent
|
||||
coverage of every directory entry created by Open. It also retains ancestor
|
||||
sync failures, relative paths, trailing separators and reopen controls.
|
||||
@@ -117,6 +117,8 @@ systemd and root access.
|
||||
|
||||
## 1. Install the binaries and units
|
||||
|
||||
After creating and mounting a dedicated blockmaster state filesystem, run `sync` before starting blockmaster. This commits the installer's mount-point entry on its parent filesystem. Startup syncs the state filesystem through its mount root; it does not commit mount-point entries on another filesystem. See [directory recovery](design/lifecycle-directory-sync.md).
|
||||
|
||||
1. **Get the repository at the release tag, then the binaries.** The repository holds the units in `deploy/`. The
|
||||
binaries are `blockmaster`, `blockvolume` and `sw-block`, all three from the same release. `TAG` is the release,
|
||||
for example `v1.1.1`. Download the release tarball and check it:
|
||||
|
||||
Reference in new issue
Block a user