From ca22f937b57ed798ce062d84ef7993293b6f5fc7 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 4 Dec 2026 21:26:53 -0800 Subject: [PATCH] seaweed-block: the store record wait reuses MasterCallClass storeRecordNoReply repeated the master wait's no-reply classes. Export MasterCallClass and read them from it, so the two waits cannot drift. Co-Authored-By: Claude Opus 5.5 --- .../cmd/blockvolume/store_admission.go | 33 +++++++------------ seaweed-block/core/host/volume/master_wait.go | 6 ++-- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/store_admission.go b/seaweed-block/cmd/blockvolume/store_admission.go index bfedc76598..9bd76c65c1 100644 --- a/seaweed-block/cmd/blockvolume/store_admission.go +++ b/seaweed-block/cmd/blockvolume/store_admission.go @@ -2,9 +2,9 @@ package main import ( "context" - "errors" "time" + "github.com/seaweedfs/seaweed-block/core/host/volume" control "github.com/seaweedfs/seaweed-block/core/rpc/control" "github.com/seaweedfs/seaweed-block/core/storage" "google.golang.org/grpc/codes" @@ -24,14 +24,14 @@ var ( ) // readReplicaStore reads the master's record of this replica's store. While -// blockmaster gives no reply (Unavailable, DeadlineExceeded, Canceled: no -// contact, as the master wait classes them) the process waits and reads -// again, with no bound, so a start during a master outage does not exit and -// burn the unit's start limit. It runs before the store is opened or -// created, so nothing is written meanwhile; waiting reports the wait (for -// /status) and the log repeats it every replicaStoreWaitLogEvery with the -// master's address and the time waited. Any answer, a credentials refusal, or -// ctx's end returns the last result. +// blockmaster gives no reply (volume.MasterCallClass: neither contact nor a +// credentials refusal) the process waits and reads again, with no bound, so +// a start during a master outage does not exit and burn the unit's start +// limit. It runs before the store is opened or created, so nothing is +// written meanwhile; waiting reports the wait (for /status) and the log +// repeats it every replicaStoreWaitLogEvery with the master's address and the +// time waited. Any answer, a credentials refusal, or ctx's end returns the +// last result. func readReplicaStore(ctx context.Context, master string, read func(context.Context) (*control.GetReplicaStoreResponse, error), logf func(string, ...any), waiting func(bool)) (*control.GetReplicaStoreResponse, error) { var since, logged time.Time defer func() { @@ -43,7 +43,8 @@ func readReplicaStore(ctx context.Context, master string, read func(context.Cont qctx, cancel := context.WithTimeout(ctx, replicaStoreQueryTimeout) rec, err := read(qctx) cancel() - if err == nil || !storeRecordNoReply(err) || ctx.Err() != nil { + contact, credentials := volume.MasterCallClass(err) + if contact || credentials || ctx.Err() != nil { if !since.IsZero() && ctx.Err() == nil { logf("blockvolume: the master at %s answered this replica's store record after %s", master, time.Since(since).Round(time.Second)) } @@ -65,18 +66,6 @@ func readReplicaStore(ctx context.Context, master string, read func(context.Cont } } -// storeRecordNoReply says whether err is no reply from blockmaster. -func storeRecordNoReply(err error) bool { - if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) { - return true - } - switch status.Code(err) { - case codes.Unavailable, codes.DeadlineExceeded, codes.Canceled: - return true - } - return false -} - // storeAdmission is how the durable open may treat the local store: with // mustExist it never creates one (a missing store is refused at the open // itself), and a nonzero id is the store it must find. diff --git a/seaweed-block/core/host/volume/master_wait.go b/seaweed-block/core/host/volume/master_wait.go index 476ac2daa1..21a84b234e 100644 --- a/seaweed-block/core/host/volume/master_wait.go +++ b/seaweed-block/core/host/volume/master_wait.go @@ -65,11 +65,11 @@ func newMasterWait(now func() time.Time, logf func(string, ...any)) *masterWait return &masterWait{now: now, logf: logf} } -// masterCallClass sorts a call result: a reply produced by blockmaster's +// MasterCallClass sorts a call result: a reply produced by blockmaster's // handler (any status but the transport codes) is contact; Unavailable, // DeadlineExceeded and Canceled are no reply; Unauthenticated and // PermissionDenied are a credentials refusal. -func masterCallClass(err error) (contact, credentials bool) { +func MasterCallClass(err error) (contact, credentials bool) { if err == nil { return true, false } @@ -95,7 +95,7 @@ func masterCallClass(err error) (contact, credentials bool) { // assignment to accept). The heartbeat does not check identity, so its // answers alone do not end it sooner. func (w *masterWait) call(err error) { - contact, credentials := masterCallClass(err) + contact, credentials := MasterCallClass(err) identity := "" r := leaseRefusalDetail(err) if r != nil && r.GetKind() == control.WorkspaceLeaseRefusal_IDENTITY {