Files
seaweedfs/seaweed-block/cmd/blockvolume/ready_latch.go
T
Ping Qiu 5c4f995c55 v0.2 alpha: Day-1 activation and first-volume loop (#48)
Package the Kubernetes alpha into a script-based Day-1 activation loop: activate the stack, create the first PVC-backed volume, verify writer/reader data, collect product-owned observation evidence, render a local read-only report, and clean up.

Includes multi-node-safe activation defaults, first-volume example automation, read-only ops report output, README/quickstart/release note updates, and review-driven hardening for fail-fast configuration, promotion evidence, inventory fail-closed behavior, and test guards.

Validated by Day-1 activation run 20260517-205252-04e9 and read-only report run 20260517-212358-bfba. Local targeted tests passed.
2026-05-18 16:43:35 -07:00

89 lines
2.6 KiB
Go

package main
import (
"context"
"encoding/json"
"fmt"
"io"
"reflect"
"time"
"github.com/seaweedfs/seaweed-block/core/adapter"
"github.com/seaweedfs/seaweed-block/core/frontend"
)
type primaryOpenProvider interface {
Open(context.Context, string) (frontend.Backend, error)
}
type durableIdentityLatchProvider interface {
LatchVolumeIdentity(string) (bool, error)
}
func startReadyAssignmentLoop(ch <-chan adapter.AssignmentInfo, f flags, prov primaryOpenProvider, stdout, stderr io.Writer) {
go func() {
for info := range ch {
handleReadyAssignment(info, f, prov, stdout, stderr)
}
}()
}
func handleReadyAssignment(info adapter.AssignmentInfo, f flags, prov primaryOpenProvider, stdout, stderr io.Writer) {
if f.printReadyLine && stdout != nil {
_ = json.NewEncoder(stdout).Encode(readyLine{
Component: "blockvolume",
Phase: "assignment-received",
VolumeID: info.VolumeID,
ReplicaID: info.ReplicaID,
Epoch: info.Epoch,
EndpointVersion: info.EndpointVersion,
})
}
if providerIsNil(prov) || info.VolumeID != f.volumeID || info.ReplicaID != f.replicaID || info.Epoch == 0 {
return
}
if latcher, ok := prov.(durableIdentityLatchProvider); ok {
latched, err := latcher.LatchVolumeIdentity(info.VolumeID)
if err != nil {
if stderr != nil {
fmt.Fprintf(stderr, "blockvolume: durable lineage latch failed volume=%s replica=%s epoch=%d ev=%d: %v\n",
info.VolumeID, info.ReplicaID, info.Epoch, info.EndpointVersion, err)
}
return
}
if stderr != nil {
fmt.Fprintf(stderr, "blockvolume: durable lineage latched volume=%s replica=%s epoch=%d ev=%d changed=%t\n",
info.VolumeID, info.ReplicaID, info.Epoch, info.EndpointVersion, latched)
}
return
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if _, err := prov.Open(ctx, info.VolumeID); err != nil {
if stderr != nil {
fmt.Fprintf(stderr, "blockvolume: durable primary lineage ensure failed volume=%s replica=%s epoch=%d ev=%d: %v\n",
info.VolumeID, info.ReplicaID, info.Epoch, info.EndpointVersion, err)
}
return
}
if stderr != nil {
fmt.Fprintf(stderr, "blockvolume: durable primary lineage ensured volume=%s replica=%s epoch=%d ev=%d\n",
info.VolumeID, info.ReplicaID, info.Epoch, info.EndpointVersion)
}
}
func providerIsNil(prov primaryOpenProvider) bool {
if prov == nil {
return true
}
v := reflect.ValueOf(prov)
switch v.Kind() {
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Pointer, reflect.Slice:
return v.IsNil()
default:
return false
}
}