mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
Merge branch 'main' into fix/head-version-v11
This commit is contained in:
commit
061a8cd302
8 files changed
+387
-4
No files matched your search
@@ -938,7 +938,11 @@ func runVolume(f flags, exits *processExit) int {
|
||||
shutCancel()
|
||||
}
|
||||
_ = h.Close()
|
||||
return 1
|
||||
code, reason := durableOpenFatalExit(sErr)
|
||||
if reason != "" {
|
||||
return reportWorkspaceExit(workspaceExit{code: code, reason: reason, detail: "the local store was written by a newer version: run a newer binary"})
|
||||
}
|
||||
return code
|
||||
case durableStartupFaulted:
|
||||
fmt.Fprintln(os.Stderr, "blockvolume: durable recovery failed:", evidence)
|
||||
return waitFaultedDurableRecovery(exits.done, h, status, durableProv, evidence)
|
||||
|
||||
@@ -0,0 +1,232 @@
|
||||
//go:build linux && subprocess && chunkstore_integration && systemd_integration
|
||||
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"github.com/seaweedfs/seaweed-block/core/rpc/lifecycleclient"
|
||||
"github.com/seaweedfs/seaweed-block/core/rpc/link"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
// Under the shipped unit's restart policy (Restart=on-failure,
|
||||
// RestartPreventExitStatus=78 79), a holder that meets a local store or a
|
||||
// HEAD written by a newer format exits 78 with its reason and systemd does
|
||||
// not start it again: zero restarts after the restart interval, and the
|
||||
// store's bytes and HEAD's record unchanged. The control: a process of the
|
||||
// same unit policy that exits 1 is restarted.
|
||||
func TestSystemdNewerFormatExits78WithoutRestart(t *testing.T) {
|
||||
if os.Getenv("GAP1_SYSTEMD_AUTHORIZED") != "1" {
|
||||
t.Fatal("explicit real-systemd qualification authorization required; no skip counts as proof")
|
||||
}
|
||||
if os.Geteuid() != 0 {
|
||||
t.Fatal("systemd qualification needs root")
|
||||
}
|
||||
if os.Getenv("CHUNKSTORE_WEED") == "" {
|
||||
t.Fatal("real CHUNKSTORE_WEED binary required")
|
||||
}
|
||||
if err := os.MkdirAll(durable.HostVolumeLockDir, 0o700); err != nil {
|
||||
t.Fatalf("host volume lock directory: %v", err)
|
||||
}
|
||||
fixture := newGAP1Fixture(t)
|
||||
root := fixture.root
|
||||
bin := filepath.Join(root, "bin")
|
||||
if err := os.Mkdir(bin, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, name := range []string{"blockvolume", "blockmaster"} {
|
||||
if pre := os.Getenv("SWB_PREBUILT_BIN"); pre != "" { // a host without a Go toolchain: binaries of the same commit
|
||||
raw, err := os.ReadFile(filepath.Join(pre, name))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(bin, name), raw, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
buildCtx, buildCancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||
cmd := exec.CommandContext(buildCtx, "go", "build", "-p", "4", "-o", filepath.Join(bin, name), "../"+name)
|
||||
cmd.WaitDelay = time.Second
|
||||
out, err := cmd.CombinedOutput()
|
||||
buildCancel()
|
||||
if err != nil {
|
||||
t.Fatalf("real binary build: %v %s", err, out)
|
||||
}
|
||||
}
|
||||
shipped := gap1ShippedPolicy(t)
|
||||
stem := fmt.Sprintf("newerfmt-%d", time.Now().UnixNano())
|
||||
|
||||
// Control: the same unit policy restarts a process that exits 1.
|
||||
control1 := stem + "-exit1"
|
||||
fixture.start(t, control1, true, "/bin/sh", "-c", "exit 1")
|
||||
waitGAP1(t, "control: an exit 1 was not restarted under the shipped policy", 30*time.Second, func() bool {
|
||||
return gap1Unit(t, control1)["NRestarts"] != "0"
|
||||
})
|
||||
restarts := gap1Unit(t, control1)["NRestarts"] // read before the stop, which resets it
|
||||
gap1Systemctl(t, "stop", control1)
|
||||
t.Logf("control: exit 1 restarted (NRestarts=%s) under Restart=%s RestartPreventExitStatus=%s", restarts, shipped["Restart"], shipped["RestartPreventExitStatus"])
|
||||
|
||||
cluster := startWorkspaceWeedAt(t, filepath.Join(root, "weed"))
|
||||
gap1PreserveFailure(t, root, cluster.dir)
|
||||
volume := stem
|
||||
base := "/" + stem
|
||||
masterAddr := leaseBinaryAddress(t)
|
||||
target, masterListen := gap1TargetAddresses(t, masterAddr)
|
||||
dataAddr, ctrlAddr, statusAddr, nvmeAddr := leaseBinaryAddress(t), leaseBinaryAddress(t), leaseBinaryAddress(t), leaseBinaryAddress(t)
|
||||
cfg := fmt.Sprintf("nodes:\n - server_id: s1\n data_addr: %s\n ctrl_addr: %s\n - server_id: s2\n data_addr: %s\n ctrl_addr: %s\nvolumes:\n - id: %s\n size_bytes: 262144\n replication_factor: 1\n placements:\n - server_id: s1\n replica_id: r1\n source: existing_replica\n", dataAddr, ctrlAddr, target.dataAddr, target.ctrlAddr, volume)
|
||||
spec := filepath.Join(root, "cluster.yaml")
|
||||
if err := os.WriteFile(spec, []byte(cfg), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tlsDir := gap1WriteTLS(t, root, target)
|
||||
fixture.start(t, stem+"-master", false, filepath.Join(bin, "blockmaster"),
|
||||
"--listen", masterListen, "--tls-cert", filepath.Join(tlsDir, "master.crt"), "--tls-key", filepath.Join(tlsDir, "master.key"),
|
||||
"--tls-client-ca", filepath.Join(tlsDir, "ca.crt"), "--role-file", filepath.Join(tlsDir, "roles"), "--audit-log", filepath.Join(tlsDir, "audit.log"), "--authority-store", filepath.Join(root, "auth"), "--lifecycle-store", filepath.Join(root, "life"),
|
||||
"--cluster-spec", spec, "--lifecycle-product-loop-interval", "200ms", "--expected-slots-per-volume", "1",
|
||||
"--workspace-rpc", "--chunk-filer", cluster.filerGRPC, "--chunk-path", base)
|
||||
w4WaitTCP(t, masterAddr, 20*time.Second)
|
||||
admin, err := link.ClientCredentials(link.TLSFiles{Cert: filepath.Join(tlsDir, "admin.crt"), Key: filepath.Join(tlsDir, "admin.key"), CA: filepath.Join(tlsDir, "ca.crt")}, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conn, err := grpc.NewClient(masterAddr, admin)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = conn.Close() })
|
||||
var layoutID layout.VolumeID
|
||||
waitGAP1(t, "master never resolved the volume's layout identity", 20*time.Second, func() bool {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
id, e := lifecycleclient.ResolveVolume(ctx, control.NewLifecycleServiceClient(conn), volume)
|
||||
layoutID = id
|
||||
return e == nil
|
||||
})
|
||||
store := filepath.Join(root, "store")
|
||||
args := []string{"--master", masterAddr, "--server-id", "s1",
|
||||
"--master-tls-cert", filepath.Join(tlsDir, "s1.crt"), "--master-tls-key", filepath.Join(tlsDir, "s1.key"), "--master-ca", filepath.Join(tlsDir, "ca.crt"),
|
||||
"--volume-id", volume, "--replica-id", "r1", "--layout-id", layoutID.String(),
|
||||
"--data-addr", dataAddr, "--ctrl-addr", ctrlAddr, "--heartbeat-interval", "200ms", "--t1-readiness", "--status-addr", statusAddr,
|
||||
"--durable-root", store, "--durable-impl", "walstore-chunk", "--durable-blocks", "64",
|
||||
"--chunk-filer", cluster.filerGRPC, "--chunk-path", base, "--chunk-control-endpoint", "--workspace-lease",
|
||||
"--nvme-listen", nvmeAddr, "--nvme-subsysnqn", "nqn.2026-11.test:" + stem}
|
||||
bootstrap := stem + "-bootstrap"
|
||||
fixture.start(t, bootstrap, false, filepath.Join(bin, "blockvolume"), args...)
|
||||
waitGAP1(t, "bootstrap did not attach under a real lease", 60*time.Second, func() bool { return gap1Operational(t, statusAddr, volume) })
|
||||
gap1Systemctl(t, "stop", bootstrap)
|
||||
waitGAP1(t, "bootstrap still running", 30*time.Second, func() bool { return gap1Unit(t, bootstrap)["MainPID"] == "0" })
|
||||
|
||||
// refusedOnce starts a restarting unit and requires it to exit 78 with
|
||||
// reason, then stay down past the restart interval with zero restarts.
|
||||
refusedOnce := func(unit, reason string) {
|
||||
t.Helper()
|
||||
fixture.start(t, unit, true, filepath.Join(bin, "blockvolume"), args...)
|
||||
waitGAP1(t, unit+": never exited 78", 120*time.Second, func() bool {
|
||||
u := gap1Unit(t, unit)
|
||||
return u["MainPID"] == "0" && u["ExecMainStatus"] == "78"
|
||||
})
|
||||
time.Sleep(12 * time.Second) // past RestartSec (shipped 5s), twice
|
||||
u := gap1Unit(t, unit)
|
||||
if u["NRestarts"] != "0" || u["ExecMainStatus"] != "78" || u["MainPID"] != "0" {
|
||||
t.Fatalf("%s: restarted or running after its 78: %+v", unit, u)
|
||||
}
|
||||
out, _ := exec.Command("journalctl", "-u", unit, "--no-pager", "-o", "cat").CombinedOutput()
|
||||
if want := "exiting status=78 reason=" + reason; !strings.Contains(string(out), want) {
|
||||
t.Fatalf("%s: journal lacks %q:\n%s", unit, want, out)
|
||||
}
|
||||
t.Logf("%s: exit 78 %s, NRestarts=0 after %s", unit, reason, shipped["RestartSec"])
|
||||
gap1Systemctl(t, "reset-failed", unit)
|
||||
}
|
||||
|
||||
// 1. The local store written by a newer format: both descriptor slots
|
||||
// carry the chunk-state marker above what this binary reads.
|
||||
var storeFile string // the one file under the durable root that starts with the store's superblock magic
|
||||
if err := filepath.Walk(store, func(p string, fi os.FileInfo, err error) error {
|
||||
if err != nil || !fi.Mode().IsRegular() || fi.Size() < 8192 {
|
||||
return err
|
||||
}
|
||||
head := make([]byte, 4)
|
||||
if f, err := os.Open(p); err == nil {
|
||||
_, _ = f.Read(head)
|
||||
_ = f.Close()
|
||||
}
|
||||
if string(head) == "SWBK" {
|
||||
if storeFile != "" {
|
||||
t.Fatalf("two stores under %s: %s, %s", store, storeFile, p)
|
||||
}
|
||||
storeFile = p
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if storeFile == "" {
|
||||
t.Fatalf("no store under %s", store)
|
||||
}
|
||||
original, err := os.ReadFile(storeFile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
marked := append([]byte(nil), original...)
|
||||
for _, off := range []int{0, 4096} { // descriptor slots A and B, 4096 bytes each, CRC32C in the last 4
|
||||
slot := marked[off : off+4096]
|
||||
binary.LittleEndian.PutUint16(slot[306:], 9) // a chunk-state format newer than any this binary reads
|
||||
binary.LittleEndian.PutUint64(slot[312:], 1)
|
||||
binary.LittleEndian.PutUint32(slot[4092:], crc32.Checksum(slot[:4092], crc32.MakeTable(crc32.Castagnoli)))
|
||||
}
|
||||
if err := os.WriteFile(storeFile, marked, 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
refusedOnce(stem+"-store", "store_format_newer")
|
||||
if after, err := os.ReadFile(storeFile); err != nil || !bytes.Equal(after, marked) {
|
||||
t.Fatalf("the refused open changed the store (%v)", err)
|
||||
}
|
||||
if err := os.WriteFile(storeFile, original, 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// 2. A HEAD written by a newer version.
|
||||
ref := chunkstore.VolumeRef{Name: volume, ID: layoutID}
|
||||
cl := cluster.client(t, "")
|
||||
dir := path.Join(base, ref.Dir())
|
||||
ctx := context.Background()
|
||||
entry, err := cl.LookupEntry(ctx, dir, "HEAD")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var head map[string]any
|
||||
if err := json.Unmarshal(entry.Content, &head); err != nil {
|
||||
t.Fatalf("HEAD record: %v", err)
|
||||
}
|
||||
head["version"] = 9
|
||||
newer, err := json.Marshal(head)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
entry.Content = newer
|
||||
if err := cl.UpdateEntry(ctx, dir, entry, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
refusedOnce(stem+"-head", "head_newer_version")
|
||||
if after, err := cl.LookupEntry(ctx, dir, "HEAD"); err != nil || !bytes.Equal(after.Content, newer) {
|
||||
t.Fatalf("the refused start changed HEAD (%v)", err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
// exitNewerVersion is a startup outcome that ended on a HEAD written by a
|
||||
// newer version.
|
||||
type exitNewerVersion struct{ exitStartupOutcome }
|
||||
|
||||
func (exitNewerVersion) ChunkStartupNewerVersion(string, uint64) bool { return true }
|
||||
|
||||
// A startup ended on a HEAD written by a newer version exits 78
|
||||
// head_newer_version (no restart: a restart reads the same HEAD), where the
|
||||
// same ended startup otherwise exits the restartable 75.
|
||||
func TestANewerHeadVersionExits78NotRestartable(t *testing.T) {
|
||||
h, _ := exitAuthorityHost(t)
|
||||
e := newProcessExit(context.Background())
|
||||
if !chooseChunkStartupExit(e, flags{workspaceLease: true, durableImpl: "walstore-chunk", volumeID: "v"}, h, &exitNewerVersion{exitStartupOutcome{expired: true}}) {
|
||||
t.Fatal("the newer-version startup did not end the process")
|
||||
}
|
||||
if out := <-e.decision; out.code != 78 || out.reason != "head_newer_version" {
|
||||
t.Fatalf("newer-version startup exit = %+v, want 78 head_newer_version", out)
|
||||
}
|
||||
h2, _ := exitAuthorityHost(t)
|
||||
e2 := newProcessExit(context.Background())
|
||||
chooseChunkStartupExit(e2, flags{workspaceLease: true, durableImpl: "walstore-chunk", volumeID: "v"}, h2, &exitStartupOutcome{expired: true})
|
||||
if out := <-e2.decision; out.code != 75 {
|
||||
t.Fatalf("control: an ended startup without the refusal exits %+v, want 75", out)
|
||||
}
|
||||
}
|
||||
|
||||
// A fatal durable open of a store written by a newer format exits 78
|
||||
// store_format_newer; any other fatal open exits 1 as before.
|
||||
func TestAStoreOfANewerFormatExits78(t *testing.T) {
|
||||
if code, reason := durableOpenFatalExit(fmt.Errorf("durable: OpenWALStore x: %w", storage.ErrStoreFormatNewer)); code != 78 || reason != "store_format_newer" {
|
||||
t.Fatalf("newer-format store exit = %d %q, want 78 store_format_newer", code, reason)
|
||||
}
|
||||
if code, reason := durableOpenFatalExit(errors.New("durable: OpenWALStore x: invalid superblock")); code != 1 || reason != "" {
|
||||
t.Fatalf("other fatal open exit = %d %q, want 1", code, reason)
|
||||
}
|
||||
}
|
||||
|
||||
// A master's final refusal keeps its exit when the same startup also ended
|
||||
// on a newer HEAD version: MOVED stays 78 moved, FINAL stays 79 revoked.
|
||||
func TestAMasterFinalExitWinsOverANewerHeadVersion(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
kind control.WorkspaceLeaseRefusal_Kind
|
||||
final string
|
||||
code int
|
||||
reason string
|
||||
}{
|
||||
{control.WorkspaceLeaseRefusal_MOVED, "moved", 78, "moved"},
|
||||
{control.WorkspaceLeaseRefusal_FINAL, "revoked", 79, "revoked"},
|
||||
} {
|
||||
t.Run(tc.final, func(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
refusal, err := status.New(codes.FailedPrecondition, "final refusal").WithDetails(&control.WorkspaceLeaseRefusal{Kind: tc.kind})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h, _ := exitAuthorityHost(t, func(s *exitAssignmentStream) { s.streamRefuse = refusal.Err() })
|
||||
for {
|
||||
if _, final := h.MasterWaitState(); final == tc.final {
|
||||
break
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
t.Fatalf("the master's %s refusal never reached the host", tc.final)
|
||||
case <-time.After(time.Millisecond):
|
||||
}
|
||||
}
|
||||
e := newProcessExit(ctx)
|
||||
if !chooseChunkStartupExit(e, flags{workspaceLease: true, durableImpl: "walstore-chunk", volumeID: "v"}, h, &exitNewerVersion{exitStartupOutcome{expired: true}}) {
|
||||
t.Fatal("no startup decision")
|
||||
}
|
||||
if out := <-e.decision; out.code != tc.code || out.reason != tc.reason {
|
||||
t.Fatalf("final %s with a newer HEAD version chose %+v; want %d %s", tc.final, out, tc.code, tc.reason)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
|
||||
"github.com/seaweedfs/seaweed-block/core/host/volume"
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -136,6 +138,16 @@ func reportWorkspaceExit(out workspaceExit) int {
|
||||
|
||||
// INV-WS-STARTUP-RETRY-001: one decision combines a newer other-replica
|
||||
// authority fact and the provider's generation-bound foreign-HEAD proof.
|
||||
// durableOpenFatalExit is the exit of a fatal durable storage open: 78 with
|
||||
// reason store_format_newer for a store written by a newer format (no
|
||||
// restart can open it), else 1 as before.
|
||||
func durableOpenFatalExit(err error) (int, string) {
|
||||
if errors.Is(err, storage.ErrStoreFormatNewer) {
|
||||
return exitWorkspaceSuperseded, "store_format_newer"
|
||||
}
|
||||
return 1, ""
|
||||
}
|
||||
|
||||
func workspaceRetryOutcome(reason string, h *volume.Host, claimSuperseded bool) workspaceExit {
|
||||
if claimSuperseded || h.IsCurrentReplicaSuperseded() {
|
||||
return workspaceExit{code: exitWorkspaceSuperseded, reason: "superseded"}
|
||||
@@ -262,6 +274,12 @@ func chooseChunkStartupExit(e *processExit, f flags, h *volume.Host, p chunkStar
|
||||
if identity, ok := p.(interface{ ChunkStartupIdentityRefused(string, uint64) bool }); ok && identity.ChunkStartupIdentityRefused(f.volumeID, gen) {
|
||||
out = workspaceExit{code: exitWorkspaceSuperseded, reason: "layout_identity_mismatch", detail: "VOLUME/HEAD disagrees with --layout-id; retry with the layout id from the master's volume record"}
|
||||
}
|
||||
// A HEAD written by a newer version is permanent for this binary: exit 78,
|
||||
// never the restartable 75 (a restart reads the same HEAD again). A master
|
||||
// final reason below (moved, deleted, revoked) still names the exit.
|
||||
if nv, ok := p.(interface{ ChunkStartupNewerVersion(string, uint64) bool }); ok && nv.ChunkStartupNewerVersion(f.volumeID, gen) {
|
||||
out = workspaceExit{code: exitWorkspaceSuperseded, reason: "head_newer_version", detail: "HEAD was written by a newer version: run a newer binary"}
|
||||
}
|
||||
if h != nil {
|
||||
// Typed MOVED/DELETED refusals exit 78 and a recorded revocation
|
||||
// (FINAL) exits 79 at once; both are permanent,
|
||||
|
||||
@@ -336,6 +336,9 @@ type volHandle struct {
|
||||
// startupIdentityRefused is the definite full-id refusal for startupEnded.
|
||||
// endChunkStartup is its decision writer, guarded by p.mu.
|
||||
startupIdentityRefused bool
|
||||
// startupNewerVersion: startupEnded's refusal was a HEAD written by a
|
||||
// newer version (layout.ErrHeadNewerVersion). endChunkStartup writes it.
|
||||
startupNewerVersion bool
|
||||
|
||||
// ImplWALStoreChunk. fresh: the local volume is new and starts from
|
||||
// the remote HEAD. It mirrors the durable fresh marker beside the
|
||||
@@ -1165,6 +1168,7 @@ func (p *DurableProvider) RecoverVolume(ctx context.Context, volumeID string) (R
|
||||
h.startupEnded = 0
|
||||
h.startupSuperseded = false
|
||||
h.startupIdentityRefused = false
|
||||
h.startupNewerVersion = false
|
||||
p.mu.Unlock()
|
||||
}
|
||||
report := recoverContext(ctx, h.storage, volumeID)
|
||||
|
||||
@@ -44,6 +44,15 @@ func (p *DurableProvider) ChunkStartupIdentityRefused(volumeID string, gen uint6
|
||||
return !p.closed && h != nil && gen != 0 && h.recoverGen == gen && h.startupEnded == gen && h.startupIdentityRefused
|
||||
}
|
||||
|
||||
// ChunkStartupNewerVersion reports that this recovery's startup ended on a
|
||||
// HEAD written by a newer version: no restart of this binary can read it.
|
||||
func (p *DurableProvider) ChunkStartupNewerVersion(volumeID string, gen uint64) bool {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
h := p.volumes[volumeID]
|
||||
return !p.closed && h != nil && gen != 0 && h.recoverGen == gen && h.startupEnded == gen && h.startupNewerVersion
|
||||
}
|
||||
|
||||
func (p *DurableProvider) endChunkStartup(h *volHandle, gen uint64, cause error) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
@@ -53,6 +62,7 @@ func (p *DurableProvider) endChunkStartup(h *volHandle, gen uint64, cause error)
|
||||
h.startupEnded = gen
|
||||
h.startupSuperseded = errors.Is(cause, errChunkForeignClaim)
|
||||
h.startupIdentityRefused = errors.Is(cause, layout.ErrIdentity)
|
||||
h.startupNewerVersion = errors.Is(cause, layout.ErrHeadNewerVersion)
|
||||
h.startupCure = ""
|
||||
switch {
|
||||
case errors.Is(cause, layout.ErrStaleLocalRoot):
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package durable
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
|
||||
)
|
||||
|
||||
func TestChunkStartupOutcomeRejectsOldGenerationAndCoalescesWake(t *testing.T) {
|
||||
h := &volHandle{recoverGen: 1}
|
||||
@@ -55,3 +60,20 @@ func TestChunkStartupForeignProofIsGenerationBound(t *testing.T) {
|
||||
t.Fatal("old foreign proof poisoned current retry")
|
||||
}
|
||||
}
|
||||
|
||||
// A startup that ends on a HEAD written by a newer version is latched for
|
||||
// that recovery only; another cause (a malformed HEAD) is not it.
|
||||
func TestChunkStartupNewerVersionIsGenerationBound(t *testing.T) {
|
||||
h := &volHandle{recoverGen: 1}
|
||||
p := &DurableProvider{volumes: map[string]*volHandle{"v": h}, startupUpdates: make(chan struct{}, 1)}
|
||||
p.endChunkStartup(h, 1, fmt.Errorf("attach: %w", layout.ErrHeadNewerVersion))
|
||||
if !p.ChunkStartupNewerVersion("v", 1) || p.ChunkStartupNewerVersion("v", 2) || p.ChunkStartupNewerVersion("other", 1) {
|
||||
t.Fatal("the newer-version refusal escaped its volume or recovery generation")
|
||||
}
|
||||
h2 := &volHandle{recoverGen: 1}
|
||||
p2 := &DurableProvider{volumes: map[string]*volHandle{"v": h2}, startupUpdates: make(chan struct{}, 1)}
|
||||
p2.endChunkStartup(h2, 1, fmt.Errorf("attach: %w", layout.ErrMalformed))
|
||||
if p2.ChunkStartupNewerVersion("v", 1) {
|
||||
t.Fatal("a malformed HEAD was taken for a newer version")
|
||||
}
|
||||
}
|
||||
@@ -923,11 +923,11 @@ Notes:
|
||||
| `INV-WS-FORCED-CONFIRM-HOLDER-001` | A confirmation at an epoch the master reports no holder for, in its lease or its move journal, is refused without sending a move. | M2 lease: Expired → Moved (forced) (the explicit-force guard) | `core/rpc/wsclient/wsclient.go` `holderAt`, `request` | `TestForceMoveResolvesTheHolder` (`core/rpc/wsclient/wsclient_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-FORCED-CONFIRM-NO-BYPASS-001` | No force-move flag bypasses the confirmation, and `--dry-run` is never a confirmation: it sends only a preview, which needs the same confirmation. | M2 lease: Expired → Moved (forced) (the explicit-force guard) | `cmd/sw-block/workspace.go` `runWorkspaceForceMove`, `workspacePreview`; `core/rpc/wsclient/wsclient.go` `PreviewForcedMove` | `TestWorkspaceForceMove_Row2_DryRunPreview`, `TestWorkspaceHelpText` (`cmd/sw-block/workspace_test.go`) | — | ACTIVE |
|
||||
| `INV-ATTACH-ASSIGNMENT-BOUND-001` | Without a master wait, the assignment allowance is checked between attach attempts; it never cancels a granted attempt's manifest read. Per-fetch bounds, recovery progress and provider Close still apply. | M1 Recovering to Serving (wait scheduling only) | `DurableProvider.chunkAuthorityWait` | `TestDefaultAttachAt262144EntriesOutlivesAssignmentWait`, `TestDefaultGrantedAttachFailureEndsAtAssignmentAllowance` (`core/frontend/durable/default_attach_attempt_test.go`); `TestRestoreDeferredAssignmentWaitEndsOnDeadlineAndClose` (`core/frontend/durable/provider_assignment_test.go`) | none (scheduling; authority guards unchanged) | ACTIVE |
|
||||
| `INV-WS-STARTUP-RETRY-001` | A workspace primary exits 75 on assignment timeout or lease expiry after bounded cleanup. A master fact newer than nonzero observed-own, or an exact foreign HEAD at/above the assigned epoch, permits 78. ACK and signal keep normal exit; lease and claim gates never relax. | M2 restart | `cmd/blockvolume/process_exit.go` `superviseProcess`, `workspaceRetryOutcome`; `core/frontend/durable/provider_layout.go` `startLayoutRoot`; `core/frontend/durable/provider_startup.go` `ChunkStartupIdentityRefused`, `endChunkStartup` | `TestChunkAssignmentTimeoutExposesCurrentRecoveryOutcome` (`core/frontend/durable/provider_startup_outcome_test.go`); `TestChunkStartupOutcomeRejectsOldGenerationAndCoalescesWake` (`core/frontend/durable/provider_startup_internal_test.go`); `TestWorkspaceDisplacedClaimUsesAssignedEpoch`, `TestWorkspaceRetryUsesNewestOwnAssignment`, `TestWorkspaceForeignHeadClaimChoosesNoRetry`, `TestWorkspaceOldLocalHolderForeignHeadChoosesNoRetry` (`cmd/blockvolume/process_exit_authority_test.go`); `TestWorkspaceExitFirstOutcomeIsLatched`, `TestWorkspaceExitDoesNotWaitForBlockedFrontendClose`, `TestWorkspacePlannedStopKeepsSuccess` (`cmd/blockvolume/process_exit_test.go`) | Existing WorkspaceRegrant restart transition; no new grant rule | ACTIVE |
|
||||
| `INV-WS-STARTUP-RETRY-001` | A workspace primary exits 75 on assignment timeout or lease expiry after bounded cleanup. A master fact newer than nonzero observed-own, or an exact foreign HEAD at/above the assigned epoch, permits 78. Newer HEAD/store format: 78. ACK and signal keep normal exit; lease and claim gates never relax. | M2 restart | `cmd/blockvolume/process_exit.go` `superviseProcess`, `workspaceRetryOutcome`; `core/frontend/durable/provider_layout.go` `startLayoutRoot`; `core/frontend/durable/provider_startup.go` `ChunkStartupIdentityRefused`, `ChunkStartupNewerVersion`, `endChunkStartup`; `cmd/blockvolume/process_exit.go` `chooseChunkStartupExit`, `durableOpenFatalExit` | `TestANewerHeadVersionExits78NotRestartable`, `TestAStoreOfANewerFormatExits78` (`cmd/blockvolume/newer_version_exit_test.go`); `TestChunkStartupNewerVersionIsGenerationBound` (`core/frontend/durable/provider_startup_internal_test.go`); `TestChunkAssignmentTimeoutExposesCurrentRecoveryOutcome` (`core/frontend/durable/provider_startup_outcome_test.go`); `TestChunkStartupOutcomeRejectsOldGenerationAndCoalescesWake` (`core/frontend/durable/provider_startup_internal_test.go`); `TestWorkspaceDisplacedClaimUsesAssignedEpoch`, `TestWorkspaceRetryUsesNewestOwnAssignment`, `TestWorkspaceForeignHeadClaimChoosesNoRetry`, `TestWorkspaceOldLocalHolderForeignHeadChoosesNoRetry` (`cmd/blockvolume/process_exit_authority_test.go`); `TestWorkspaceExitFirstOutcomeIsLatched`, `TestWorkspaceExitDoesNotWaitForBlockedFrontendClose`, `TestWorkspacePlannedStopKeepsSuccess` (`cmd/blockvolume/process_exit_test.go`) | Existing WorkspaceRegrant restart transition; no new grant rule | ACTIVE |
|
||||
| `INV-WS-MASTER-WAIT-001` | Startup waits without a bound while the master gives no reply or refuses credentials or identity; after contact it ends 30 s beyond the later of recovery's first reply or the master barrier. Typed MOVED or DELETED ends it with 78, including a confirmed moved source without an own assignment. | M2 Awaiting assignment → Process exited | `core/host/volume/master_wait.go` `masterWait` (contact from heartbeat, stream and renewal results; the refusal kind from the status detail only); `core/frontend/durable/provider_chunk.go` `chunkAuthorityWait` (`ChunkMasterWait`); `cmd/blockvolume/process_exit.go` `chooseChunkStartupExit`; `core/host/master/workspace_service.go` `leaseRefusal`, `renewalMoved`; `core/authority/workspace.go` `WorkspaceSourceMoved`; `core/host/master/services.go` `SubscribeAssignments`; `core/authority/workspace_lease_view.go` `LeaseBarrierError`; `core/host/volume/workspace_lease.go` `renewDelay` (sleeps until just past the barrier time, jittered, at most 2 min; then a 200 ms poll for 5 s); `core/rpc/link/link.go` `MasterReconnect` | `TestChunkAuthorityWaitStartsAtFirstContact`, `TestLeaseGuardSleepsUntilTheBarrier`, `TestStatusShowsTheMasterWait`, `TestCredentialsRefusedForAnHourWaitsAndLogs`, `TestHeartbeatLogsTheMasterWait`, `TestFlappingMasterNeverExpiresEarly` (`core/host/volume/master_wait_test.go`); `TestMasterLinkReconnectsWithinTwoSeconds` (`core/host/volume/master_reconnect_test.go`); `TestChunkAuthorityWaitFollowsTheMasterWait`, `TestChunkAuthorityWaitPassesItsOwnStart`, `TestChunkGrantedAttachThatKeepsFailingIsBounded`, `TestChunkAuthorityWaitAttachesAGrantOnTheBoundsTick` (`core/frontend/durable/provider_master_wait_test.go`); `TestIdentityRefusalWaitsVisibly`, `TestChunkAuthorityWaitAfterASlowOpenGetsItsFullLimit`, `TestIdentityRefusalEndsAndDecays` (`core/host/volume/master_wait_test.go`); `TestIdentityRefusalEndsOnADeliveredAssignment` (`cmd/blockvolume/process_exit_authority_test.go`); `TestIdentityRefusalIsTyped` (`core/host/master/workspace_lease_refusal_kind_test.go`); `TestLeaseRefusalKinds`, `TestRenewalReplicaMismatchAtOlderLineEpochIsOther` (`core/host/master/workspace_lease_refusal_kind_test.go`); `TestChunkStartupExitFinalGives78`, `TestRestartedMovedSourceExits78WithoutAnOwnLine` (`cmd/blockvolume/process_exit_authority_test.go`); `TestWorkspaceSourceMovedProof`, `TestMovedSourceProofCallers`, `TestMasterWaitFinalSites`, `TestMovedAssignmentStreamIsFinalWithoutAnyOwnAssignment`; also in `core/authority/workspace_source_moved_test.go`, `core/host/master/workspace_moved_source_guard_test.go` | Real systemd moved-source and prestarted-target controls remain qualification gates. | ACTIVE |
|
||||
|
||||
- `INV-WS-DELETE-NO-LIVE-HOLDER-001`: the verdict is the first admission's only. A rerun of a delete whose token already holds the reservation (or a committed one) is admitted without a new verdict and goes on to the catalog step, whose HEAD compare-and-swap is the fence: a HEAD a holder claimed in between is refused there and the reservation given back, so an interrupted delete strands neither the volume nor its id. A reservation may hold several tokens (one per delete request); a new token on an admitted reservation is decided by the verdict; on a committed one it skips the verdict too (committed only once the HEAD is being purged, so no holder can claim it). The HEAD read before the lock still runs for a rerun, and its result is then unused: it is kept outside the workspace lock on purpose. Availability window: a delete admitted for a never-started line that stops before it marks HEAD leaves the volume reserved for deletion; if the holder then claims HEAD, the volume cannot be used until that delete is re-run (the catalog step then refuses the live HEAD and gives the reservation back). Re-run an interrupted delete.
|
||||
- `INV-WS-STARTUP-RETRY-001`: exit 78 is permitted by a NEWER observed master fact for this volume naming another holder (compared with nonzero observed-own assignment; never-assigned zero retries75 unless the master proves this server was an issued move's source and returns typed MOVED), or by the exact refused HEAD claim image proving another holder at or above the assigned epoch. The provider binds the latter proof to its recovery generation. Both existing-root checks and claim CAS readback use the same epoch-qualified supersede classifier. A lower-epoch foreign HEAD on an existing root retains the move-back diagnostic; a displaced lower-epoch claim on a fresh root retries 75 without serving. A same-holder higher-epoch HEAD fence retries 75. Unknown/no line, same replica at a higher epoch, and status codes alone mean retry 75. A wrong retry costs a bounded restart loop; a wrong 78 causes an outage until an explicit operator start. Sealed same-epoch recovery remains up for read-only replay after assignment; stale local roots, corrupt WAL and I/O faults retain diagnostic wait. The first chosen outcome wins. Process cleanup reuses `WorkspaceDrainTimeout` (5 s), including a blocked Close; only main exits the process.
|
||||
- `INV-WS-STARTUP-RETRY-001`: a startup ended on a HEAD written by a newer version exits 78 `head_newer_version`, and a fatal open of a local store written by a newer format exits 78 `store_format_newer`: no restart of this binary can read either, so neither restarts. Exit 78 is also permitted by a NEWER observed master fact for this volume naming another holder (compared with nonzero observed-own assignment; never-assigned zero retries75 unless the master proves this server was an issued move's source and returns typed MOVED), or by the exact refused HEAD claim image proving another holder at or above the assigned epoch. The provider binds the latter proof to its recovery generation. Both existing-root checks and claim CAS readback use the same epoch-qualified supersede classifier. A lower-epoch foreign HEAD on an existing root retains the move-back diagnostic; a displaced lower-epoch claim on a fresh root retries 75 without serving. A same-holder higher-epoch HEAD fence retries 75. Unknown/no line, same replica at a higher epoch, and status codes alone mean retry 75. A wrong retry costs a bounded restart loop; a wrong 78 causes an outage until an explicit operator start. Sealed same-epoch recovery remains up for read-only replay after assignment; stale local roots, corrupt WAL and I/O faults retain diagnostic wait. The first chosen outcome wins. Process cleanup reuses `WorkspaceDrainTimeout` (5 s), including a blocked Close; only main exits the process.
|
||||
- `INV-WS-MASTER-WAIT-001`: every reply produced by blockmaster's handler starts or continues a contact streak; a transport failure (`Unavailable`, `DeadlineExceeded`, `Canceled`) ends it. So a master that answers and drops in turn postpones the 30 s bound for as long as it flaps, also for an obsolete unit; it never ends the wait early (`TestFlappingMasterNeverExpiresEarly`). The barrier time travels as a duration the master computes from the same two predicates as admission, added by the volume to its own monotonic request start; the master re-checks the barrier on every re-grant, so a wrong duration only moves the 75 exit. The status codes alone still mean retry 75 (`INV-WS-STARTUP-RETRY-001`); only the typed `WorkspaceLeaseRefusal` detail (MOVED, DELETED) permits the early 78. Scale: after a master restart every lapsed volume has the same barrier time T and the master grants them one at a time, each grant one store write W under the publisher lock, so the last of N volumes is granted about T + 0.1 s + N x W; a volume whose grant comes 30 s past T exits 75 and is started again, so that starts at N >= 30 s / W. Measured: W p50 1.03 ms, p99 2.33 ms, max 14.5 ms (400 writes of the file authority store on an NVMe ext4 disk, `TestWorkspaceGrantStoreWriteTime`), so 200 volumes about T + 0.6 s and the 30 s point near 12,900 volumes (p99); 20 real volume processes served at most 0.81 s after T (`TestManyVolumesServeTogetherAfterMasterRestart`). The bound holds for that store device: on a device whose flushes stall (an fsync held for seconds), one stalled write puts every waiting volume behind it, so the blockmaster store's device is a deployment premise of serving within 2 s of the barrier. A granted process whose attach keeps failing (the chunk store unreachable) retries inside the same bound and then exits 75: it does not hold the lease while never serving. An identity refusal has no bound until an identity-checked call (a renewal, a delivered assignment) is accepted, or until 30 s of replies pass with no new identity refusal; the window then opens again. A serving holder that starts getting identity refusals is outside this row: its lease expires and it fences and exits 75 (`lease_expired`).
|
||||
- Part T lineage evidence: `recordSelfAssignment` records the newest identity-validated observed-own assignment before local-readiness admission; `EngineProjection` is the adopted-own lineage. Exit compares the former; fencing compares the latter. Both use `IsSuperseded` with explicit lineage; zero lineage selects retry75 and no fence; neither fact grants I/O. `TestWorkspaceExitAndFenceUseNamedLineages`, `TestWorkspaceExitLineageIncludesBlockedOwnAssignment`, and `TestWorkspaceObservedLineageNeverTrailsAdoption` (`core/host/volume/workspace_startup_test.go`) keep the distinction causal.
|
||||
- Part T evidence scope: `workspaceRetryOutcome` is the one retry/no-retry decision. Startup `chooseChunkStartupExit` supplies the recovery-generation-bound refused-claim HEAD proof; runtime lease-end supplies none. Both combine that input with a foreign master line newer than nonzero observed-own; absent proof means retry 75.
|
||||
|
||||
Reference in new issue
Block a user