seaweed-block: stop lifecycle ancestor sync at the state filesystem boundary (#13475)

* Stop lifecycle ancestor sync at the state filesystem boundary

* docs(block): preserve existing master state when changing filesystems

* docs(block): sync the migrated master state before remounting

* docs(block): require the migrated state mount before master startup

* docs(block): keep blockmaster from starting during the state migration

A stopped but enabled blockmaster starts at the next boot, and a v1.1.0
volume unit's restart pulls it in through Wants=. Either can start it
against the source being copied or the empty state path. Disable it for
the migration, stop v1.1.0 volume units first, and enable it with the
final start.

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

* docs(block): keep an old state filesystem as the migration backup

When the old state directory is itself a mount point, moving it aside
moves only the empty mount-point directory; the stores stay on the old
filesystem. Unmount it, keep it intact as the backup, and drop its
persistent mount so it does not come back over the new one.

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

* docs(block): unmount a dedicated master state filesystem before removal

rm -rf on the mounted state path deletes its contents, then fails on the
mount root, and the && chain never removes the units, binaries or user.
Empty and unmount it first, drop its persistent mount, and remove the
blockmaster drop-in with the other unit overrides.

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

* docs(block): disable stopped v1.1.0 volume units during the state migration

A v1.1.0 volume stop only stops the unit, and the v1.1.0 unit Wants=
blockmaster, so a reboot mid-migration started the volume and with it
the disabled blockmaster before the mount guard was installed.

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

* docs(block): move aside the directory an old state mount uncovers

Unmounting an old state filesystem can expose older files that the
mount hid, so that directory is not empty; leaving it at the state path
would put stale stores beneath the new mount.

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

* docs(block): install the units before a new install's state mount drop-in

The new-install sentence sent the operator to the mount drop-in before the
units were installed, and `systemctl edit` refuses a unit that does not
exist yet. Install the units first, then mount the state filesystem and
configure its persistent mount and drop-in, before the first start.

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

* docs(block): verify the lifecycle store only when one is configured

The shipped blockmaster.env leaves --lifecycle-store unset, so an
installation on it has only the authority store; the migration's
verification step required a lifecycle store it could not find. Check
the authority store, and the lifecycle store when --lifecycle-store is
set.

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

* docs(block): keep the sw-block removal off filesystems mounted below it

find and rm -rf both descend into a filesystem mounted below the state
or volume directories and delete its contents before failing on the
mount point. Unmount such filesystems first, and run the removal with
-xdev and --one-file-system so a missed one stops it with its data kept.

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

* docs(block): refuse the sw-block removal while a bind mount sits below it

-xdev and --one-file-system compare device numbers, so a bind mount from the
same filesystem looks like a plain directory to them and the removal deletes
its source's contents. Both removal commands now list mounts below the
sw-block directories and remove nothing while one remains.

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

* docs(block): require removal of same-device nested mounts

* docs(block): scope state isolation to measured directory syncs

* docs(block): refuse mounts at removal operand roots

* docs(block): name the state filesystem where 'it' lost its antecedent

911890f385 moved the measurements in front of "Run sync after creating and
mounting it", so in the release note "it" followed "a start-time promise",
and in the manual it followed "the shared filesystem". Both now say the state
filesystem, as does the release note's "keep holders' data off" sentence.

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

* docs(block): match removal mount guards against resolved paths

findmnt reports a mount made through a symlinked ancestor under the
resolved path, so the literal patterns let a bind mount through the alias
pass both guards. Build the patterns from realpath -m of each directory.

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

* docs(block): guard every directory the final removal deletes

The final removal also deletes the systemd drop-in directories and
/run/sw-block, but its mount check covered only the three data roots.
Include them in the same resolved-path check.

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

* docs(block): keep grants the copied stores took during a failed migration check

Step 7 starts blockmaster before the reload is verified, so reconnecting
holders can already have grants in the copied stores. The failure path now
says to keep them and correct the copy in place rather than recopy from the
retained original.

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

* docs(block): compare removal mount guards literally

Resolved paths went into grep -E as a pattern: a path with a regex
metacharacter such as an unmatched [ made grep fail, and the leading !
turned that failure into a pass. Compare each mount against the resolved
directories with awk index(), so an awk error stops the command too.

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

* docs(block): decode escaped mount targets before removal

---------

Co-authored-by: pingqiu <pingqiu@users.noreply.github.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-12-05 19:53:21 -08:00
1 parent 2a7cee5dda
commit ee547ef399
11 files changed
+266 -53

No files matched your search

+1 -10
View File
@@ -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,
+1 -10
View File
@@ -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())
+2
View File
@@ -1066,6 +1066,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.
+98 -18
View File
@@ -117,21 +117,74 @@ systemd and root access.
## 1. Install the binaries and units
**Plan blockmaster's state storage before starting it.** Keep the holders' local data off both the state
directory's filesystem and the filesystem holding its ancestors. In practice, put the holders' data on its own
filesystem, not the root filesystem. With the shipped unit, the state directory is `/var/lib/sw-block-master`,
including the authority and lifecycle stores. A different directory on the same filesystem is not enough. A
dedicated state-directory mount alone does not isolate every startup sync: opening the store also syncs ancestor
directories up to `/`, including `/var/lib` and `/var` with this layout. Keep write load low on those filesystems
when restarting too. Under heavy writes, an `fsync` when blockmaster opens its state directory can wait for the
**Plan blockmaster's state storage before starting it.** Keep the holders' local data off blockmaster's state
filesystem. With the shipped unit, the state directory is `/var/lib/sw-block-master`, including the authority
store and any lifecycle store. A different directory on the same filesystem is not enough.
In v1.1.2, with the state directory on its own filesystem, blockmaster's start no longer syncs any directory on
the shared filesystem. Run `sync` after creating and mounting the state filesystem. This commits the installer's
mount-point entry on its parent filesystem. A failed device lookup logs a fallback to the full ancestor walk. See
[directory recovery](design/lifecycle-directory-sync.md).
Under one buffered-write load, three starts per case measured shared-filesystem warm/cold medians of
31.3/122.9 seconds, versus 1.6/2.5 seconds on a dedicated state filesystem; the dedicated warm maximum was
13.2 seconds. The warm startup directory-fsync count fell from 30 to 15, with shared root-filesystem directory
fsyncs falling from 30 to 0. These are measurements under that load, not a start-time promise.
**Do not mount an empty filesystem over existing blockmaster state.** It hides the existing stores
beneath the mount, and starting blockmaster there can create a separate state history. For a new install,
install the units (step 2 below), then create and mount the state filesystem and configure its persistent mount
and the unit's mount dependency as migration step 5 shows, all before the first start in
[section 2](#2-cluster-spec-and-blockmaster).
Migrating existing state stops service: volumes fence once blockmaster's downtime outlasts their leases.
To migrate an existing installation:
1. Stop and disable blockmaster with `sudo systemctl disable --now sw-blockmaster`, so a reboot does not start it,
and keep it stopped throughout the migration. With v1.1.0 volume units on this host, stop those volumes first
([section 4](#4-stop-a-volume)) and disable each with `sudo systemctl disable sw-blockvolume@<volume>`: their
restart or their start at boot starts blockmaster again, and a v1.1.0 `volume stop` leaves the unit enabled.
2. Mount the new filesystem at a temporary location. Copy the entire existing state directory onto it,
preserving file contents, ownership, permissions and directory structure, including hidden files.
3. Verify the copy against the stopped source, run `sync`, then unmount the temporary location. Retain the original state
until the migration has been verified; do not initialize an empty replacement store.
4. With the old state directory unmounted, move it aside to an unused backup path outside the mount point.
If the old state directory is itself a mount point, unmount that filesystem and keep it intact as the backup,
and remove its persistent mount configuration. The directory it uncovers is not the backup, but it can hold
older files the mount hid: move it aside as well, to a separate path.
Create an empty directory at the original state path. Do not leave the old stores under the mount: a missing
mount at boot must not expose stale state as a usable fallback.
5. Configure the new filesystem's persistent mount, for example in `/etc/fstab`. While blockmaster is still
stopped, run `sudo systemctl edit sw-blockmaster` and add the following drop-in for the shipped state path:
```ini
[Unit]
RequiresMountsFor=/var/lib/sw-block-master
AssertPathIsMountPoint=/var/lib/sw-block-master
```
If the state path differs, change both paths to the actual mount point. Run `sudo systemctl daemon-reload`.
The dependency orders the service after its mount; the assertion refuses startup if the mount is absent,
including if its configuration is lost. Keep these protections installed after the migration.
6. Mount the copied filesystem at the configured state directory, verify that it contains the copied authority
store, the lifecycle store if `--lifecycle-store` is set, and their permissions, and run `sync`.
7. Enable and start blockmaster with `sudo systemctl enable --now sw-blockmaster` and verify that it opens the
copied stores and reloads the existing records before considering the migration complete.
If verification fails, stop it with `sudo systemctl disable --now sw-blockmaster`, keep it stopped, and correct
the mount or copy before retrying. Once it has started, the copied stores can already hold grants issued to
reconnecting holders: keep them, correct the copy in place, and do not overwrite it from the retained original.
Once it verifies, start any volumes stopped in step 1 again with `volume start`, which enables their units.
Remove the moved original, or the old state filesystem, only after this successful startup and state verification.
Under heavy writes on the state filesystem, an `fsync` when blockmaster opens its state directory can wait for the
filesystem journal. In v1.1.2, startup also runs a `syncfs` for each store with changed import records on ext4, XFS,
btrfs or tmpfs (Linux 5.8 or later), which waits for every pending write on that filesystem, including the holders'
data. Starts took from about 20 seconds to over 150 seconds in our tests (one start was not ready after 2 minutes);
this is not an upper bound. A volume whose lease expires stops serving until blockmaster is back; it is then
granted again on the same holder, with its data. A forced move during that time can lose writes after the last
published HEAD (see [forced move](volume-lifecycle.md#after-a-crash)).
Restart blockmaster at low write load, including when the cluster spec has not changed. See the
[restart known issue](releases/v1.1.1.md#known-issue-blockmaster-restart-can-stall-on-a-busy-filesystem).
btrfs or tmpfs (Linux 5.8 or later), which waits for every pending write on that filesystem, including any holders'
data there. Starts took from about 20 seconds to over 150 seconds in our shared-filesystem tests (one start was not
ready after 2 minutes); this is not an upper bound. A volume whose lease expires stops serving until blockmaster is
back; it is then granted again on the same holder, with its data. A forced move during that time can lose writes
after the last published HEAD (see [forced move](volume-lifecycle.md#after-a-crash)). Restart blockmaster at low
write load on the state filesystem, including when the cluster spec has not changed. v1.1.1 still syncs ancestors
through `/`; its [restart known issue](releases/v1.1.1.md#known-issue-blockmaster-restart-can-stall-on-a-busy-filesystem)
retains the earlier isolation guidance.
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,
@@ -906,16 +959,43 @@ two hosts, follow the host-by-host order there. Where SeaweedFS was already runn
```
3. **Remove sw-block.** The removal runs only after the same check succeeds in the same command. A failed query
removes nothing:
removes nothing. If section 1 put blockmaster's state on its own filesystem, empty and unmount it first, then
delete its persistent mount configuration (its `/etc/fstab` line): `rm -rf` cannot remove a mount point, so
the removal below would stop there. Unmount anything else mounted below these directories first, bind mounts
included. `-xdev` and `--one-file-system` stop only at another filesystem: a bind mount from the same
filesystem looks like a plain directory to them, and its source's contents would be deleted. Both commands
below print nested mounts and remove nothing while one remains; `findmnt` lists the mounts, under their resolved
paths. The commands decode the raw output's hex escapes once before comparing each directory's `realpath`;
encoded line breaks refuse removal because the comparison is line-based. The final removal checks every directory
it deletes, and also refuses mounts at those directories themselves. The empty-and-unmount step intentionally
allows blockmaster's state mount itself so it can empty and unmount that filesystem first.
```sh
units=$(systemctl list-units 'sw-blockvolume*' 'sw-blockmaster*' --state=active,activating,deactivating --no-legend) &&
test -z "$units" &&
sudo rm -rf /var/lib/sw-block-volume /var/lib/sw-block-master /etc/sw-block &&
test -z "$units" && mounts=$(findmnt -rno TARGET) &&
printf '%s\n' "$mounts" | awk '/\\x0[aAdD]/ { bad = 1 } END { exit bad }' &&
roots=$(realpath -m /var/lib/sw-block-volume /var/lib/sw-block-master /etc/sw-block) &&
/usr/bin/printf '%b\n' "$mounts" | R="$roots" awk 'BEGIN { n = split(ENVIRON["R"], d, "\n") }
{ for (i = 1; i <= n; i++) if (index($0, d[i] "/") == 1) { print; f = 1 } } END { exit f }' &&
mountpoint -q /var/lib/sw-block-master &&
sudo find /var/lib/sw-block-master -xdev -mindepth 1 -delete && sudo umount /var/lib/sw-block-master
```
Then remove everything else:
```sh
units=$(systemctl list-units 'sw-blockvolume*' 'sw-blockmaster*' --state=active,activating,deactivating --no-legend) &&
test -z "$units" && mounts=$(findmnt -rno TARGET) &&
printf '%s\n' "$mounts" | awk '/\\x0[aAdD]/ { bad = 1 } END { exit bad }' &&
roots=$(realpath -m /var/lib/sw-block-volume /var/lib/sw-block-master /etc/sw-block /run/sw-block \
/etc/systemd/system/sw-blockvolume@*.service.d /etc/systemd/system/sw-blockmaster.service.d) &&
/usr/bin/printf '%b\n' "$mounts" | R="$roots" awk 'BEGIN { n = split(ENVIRON["R"], d, "\n") }
{ for (i = 1; i <= n; i++) if ($0 == d[i] || index($0, d[i] "/") == 1) { print; f = 1 } } END { exit f }' &&
sudo rm -rf --one-file-system /var/lib/sw-block-volume /var/lib/sw-block-master /etc/sw-block &&
sudo rm -f /etc/systemd/system/sw-blockmaster.service /etc/systemd/system/sw-blockvolume.service \
/etc/systemd/system/sw-blockvolume@.service /etc/systemd/system/sw-blockvolume-ublk.service \
/etc/tmpfiles.d/sw-block.conf /usr/local/bin/blockmaster /usr/local/bin/blockvolume /usr/local/bin/sw-block &&
sudo rm -rf /etc/systemd/system/sw-blockvolume@*.service.d /run/sw-block &&
sudo rm -rf /etc/systemd/system/sw-blockvolume@*.service.d /etc/systemd/system/sw-blockmaster.service.d /run/sw-block &&
sudo systemctl daemon-reload && sudo userdel sw-block
sudo rmdir /mnt/v1 /mnt/v2 2>/dev/null || true # the guest mount points (section 5's restore target too), if empty
```
+2 -2
View File
@@ -11,9 +11,9 @@ v1.1.2 is not yet released.
## Known issue: blockmaster restart can stall on a busy filesystem
- **Trigger:** blockmaster's state directory or its ancestors share a filesystem with heavy writes, such as the holders' local data.
- **Trigger:** blockmaster's state filesystem also holds heavy writes, such as the holders' local data.
- **Effect:** blockmaster's start syncs its state directories, which can wait for the filesystem journal. When the import has changed records, it also runs a `syncfs` for each store with changed records on ext4, XFS, btrfs or tmpfs (Linux 5.8 or later), which waits for every pending write on that filesystem, including the holders' data. Starts took from about 20 seconds to over 150 seconds in our tests (one start was not ready after 2 minutes); this is not an upper bound. A volume whose lease expires stops serving until blockmaster is back; it is then granted again on the same holder, with its data. A forced move during that time can lose writes after the last published HEAD (see [forced move](../volume-lifecycle.md#after-a-crash)).
- **What to do:** keep the holders' data off both the state directory's filesystem and the filesystem holding its ancestor directories. In practice, put the holders' data on its own filesystem, not the root filesystem. A different directory on the same filesystem is not enough. A dedicated state-directory mount alone does not isolate every startup sync: opening the store also syncs ancestors up to `/`, including `/var/lib` and `/var` with the shipped layout. Restart blockmaster at low write load on all those filesystems. This limitation also applies when the cluster spec has not changed.
- **What to do:** In v1.1.2, with the state directory on its own filesystem, blockmaster's start no longer syncs any directory on the shared filesystem. Under one buffered-write load, three starts per case measured shared warm/cold medians of 31.3/122.9 seconds and dedicated medians of 1.6/2.5 seconds, with a dedicated warm maximum of 13.2 seconds. Warm directory fsyncs fell from 30 to 15; shared root-filesystem directory fsyncs fell from 30 to 0. These are measurements under that load, not a start-time promise. Run `sync` after creating and mounting the state filesystem. For a new install, install the units, then mount it and configure its persistent mount and the unit's mount dependency before the first start. Migrating existing state stops service; volumes fence once the downtime outlasts their leases. Stop and disable blockmaster (with v1.1.0 volume units, stop and disable the host's volumes first), copy all state preserving ownership and permissions, verify and sync the copy, then move the unmounted original directory aside (if it is a mount point itself, unmount it, keep that filesystem as the backup, and move the directory it uncovers aside too) and create an empty mount point. Configure the persistent mount and the unit's `RequiresMountsFor` plus `AssertPathIsMountPoint` drop-in, mount the copy, verify its stores and run `sync`. Enable and start blockmaster and confirm that it opens the copied stores and reloads existing records; only then remove the moved original. Never leave stale stores beneath the mount or start against an empty replacement. Follow the [state migration steps](../operations-manual.md#1-install-the-binaries-and-units). Keep holders' data off the state filesystem; a different directory on it is not enough. Restart blockmaster at low write load on the state filesystem, including when the cluster spec has not changed. If device lookup fails, a logged fallback retains the full ancestor walk.
## Lifecycle persistence failures