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 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 authored and pingqiu committed 2026-12-04 21:30:52 -08:00
1 parent 4eb8b2a2fa
commit ca22f937b5
2 files changed
+14 -25

No files matched your search

@@ -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.
@@ -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 {