G9G: verify product loop assignment in subprocess L2

This commit is contained in:
pingqiu committed 2026-05-03 06:20:21 -07:00
1 parent e7e3126d03
commit 962160dbc3
2 files changed
+146

No files matched your search

+16
View File
@@ -26,6 +26,7 @@ type flags struct {
expectedSlotsPerVol int
freshnessWindow time.Duration
pendingGrace time.Duration
lifecycleLoop time.Duration
// printReadyLine: test-only flag that emits a single
// structured JSON line to stdout after the gRPC listener is
// bound, so L2 subprocess tests can parse the ready event.
@@ -43,6 +44,7 @@ func parseFlags(args []string) (flags, error) {
fs.IntVar(&f.expectedSlotsPerVol, "expected-slots-per-volume", 3, "RF/expected slot count per volume; the controller rejects observation snapshots whose slot count differs (default 3, set to 2 for 2-node smoke clusters)")
fs.DurationVar(&f.freshnessWindow, "freshness-window", 30*time.Second, "observation freshness window before a server's heartbeat expires")
fs.DurationVar(&f.pendingGrace, "pending-grace", 1*time.Second, "bootstrap/missing-observation grace before supportability reports unsupported")
fs.DurationVar(&f.lifecycleLoop, "lifecycle-product-loop-interval", 0, "optional G9G product-loop interval; disabled when 0")
fs.BoolVar(&f.printReadyLine, "t0-print-ready", false, "internal test-only: emit one structured JSON line on stdout after listener bound")
fs.SetOutput(os.Stderr)
if err := fs.Parse(args); err != nil {
@@ -105,6 +107,9 @@ func run(f flags) int {
}
h.Start()
if f.lifecycleLoop > 0 {
go runLifecycleProductLoop(h, f.lifecycleLoop)
}
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
@@ -118,3 +123,14 @@ func run(f flags) int {
}
return 0
}
func runLifecycleProductLoop(h *master.Host, interval time.Duration) {
ticker := time.NewTicker(interval)
defer ticker.Stop()
for {
if _, err := h.RunLifecycleProductTick(); err != nil {
fmt.Fprintln(os.Stderr, "blockmaster: lifecycle product loop:", err)
}
<-ticker.C
}
}
@@ -0,0 +1,130 @@
package main_test
import (
"encoding/json"
"os"
"os/exec"
"path/filepath"
"testing"
"time"
"github.com/seaweedfs/seaweed-block/core/lifecycle"
)
func TestG9G_L2ProductLoopPublishesAssignmentToBlockvolume(t *testing.T) {
if testing.Short() {
t.Skip("L2 subprocess product-loop test; -short skip")
}
bins := buildG54Binaries(t)
art := t.TempDir()
lifecycleDir := filepath.Join(art, "lifecycle")
seedG9GExistingReplicaPlacement(t, lifecycleDir)
_, masterAddr := startG9GMaster(t, bins, art, lifecycleDir)
r2Data, r2Status := pickAddr(t), pickAddr(t)
r2Ctrl := pickAddr(t)
_ = startG54Volume(t, bins, art, volOpts{
masterAddr: masterAddr,
serverID: "s2", replicaID: "r2",
dataAddr: r2Data, ctrlAddr: r2Ctrl,
statusAddr: r2Status,
durableRoot: filepath.Join(art, "g9g-r2-store"),
logTag: "g9g-r2",
})
r2Ready := pollStatus(t, r2Status, 10*time.Second, func(b map[string]any) bool {
h, _ := b["Healthy"].(bool)
rid, _ := b["ReplicaID"].(string)
epoch, _ := b["Epoch"].(float64)
return h && rid == "r2" && epoch >= 1
})
if r2Ready == nil {
t.Fatal("r2: no status response after product-loop assignment")
}
if h, _ := r2Ready["Healthy"].(bool); !h {
t.Fatalf("r2 did not become Healthy from product-loop assignment; status=%v", r2Ready)
}
}
func seedG9GExistingReplicaPlacement(t *testing.T, lifecycleDir string) {
t.Helper()
placementStore, err := lifecycle.OpenPlacementIntentStore(filepath.Join(lifecycleDir, "placements"))
if err != nil {
t.Fatalf("open placement store: %v", err)
}
if _, err := placementStore.ApplyPlan(lifecycle.PlacementPlan{
VolumeID: "v1",
DesiredRF: 1,
Candidates: []lifecycle.PlacementCandidate{{
VolumeID: "v1",
ServerID: "s2",
ReplicaID: "r2",
Source: lifecycle.PlacementSourceExistingReplica,
}},
}); err != nil {
t.Fatalf("apply placement: %v", err)
}
if _, err := lifecycle.OpenFileStore(filepath.Join(lifecycleDir, "volumes")); err != nil {
t.Fatalf("open volume store: %v", err)
}
if _, err := lifecycle.OpenNodeInventoryStore(filepath.Join(lifecycleDir, "nodes")); err != nil {
t.Fatalf("open node store: %v", err)
}
}
func startG9GMaster(t *testing.T, bins l2bins, art, lifecycleDir string) (*proc, string) {
t.Helper()
storeDir := filepath.Join(art, "master-store")
_ = os.MkdirAll(storeDir, 0o755)
topo := write2SlotTopology(t, art)
logPath := filepath.Join(art, "master-g9g.log")
lf, err := os.Create(logPath)
if err != nil {
t.Fatalf("master log: %v", err)
}
cmd := exec.Command(bins.master,
"--authority-store", storeDir,
"--lifecycle-store", lifecycleDir,
"--lifecycle-product-loop-interval", "100ms",
"--listen", "127.0.0.1:0",
"--topology", topo,
"--expected-slots-per-volume", "2",
"--freshness-window", "800ms",
"--pending-grace", "100ms",
"--t0-print-ready",
)
stdout, err := cmd.StdoutPipe()
if err != nil {
lf.Close()
t.Fatalf("master stdout pipe: %v", err)
}
cmd.Stderr = lf
if err := cmd.Start(); err != nil {
lf.Close()
t.Fatalf("master start: %v", err)
}
p := &proc{cmd: cmd, logPath: logPath}
t.Cleanup(func() { p.stop(t); lf.Close() })
buf := make([]byte, 512)
n, _ := stdout.Read(buf)
go func() {
for {
b := make([]byte, 1024)
if _, err := stdout.Read(b); err != nil {
return
}
}
}()
var rl struct {
Component, Phase, Addr string
}
if err := json.Unmarshal(buf[:n], &rl); err != nil {
t.Fatalf("parse master ready %q: %v", buf[:n], err)
}
if rl.Addr == "" {
t.Fatalf("master ready: empty addr (line=%q)", buf[:n])
}
return p, rl.Addr
}