From 456d9462e50d3f55d4406269b38f4ea5d52ede54 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Sat, 20 Sep 2025 12:51:57 +0800 Subject: [PATCH] fix: after saveRebalanceStats cancel will be empty (#21597) --- cmd/erasure-server-pool-rebalance.go | 19 +++++++------------ cmd/erasure-server-pool.go | 5 +++-- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/cmd/erasure-server-pool-rebalance.go b/cmd/erasure-server-pool-rebalance.go index 031f3e3f3..bb2138a65 100644 --- a/cmd/erasure-server-pool-rebalance.go +++ b/cmd/erasure-server-pool-rebalance.go @@ -98,12 +98,10 @@ type rebalanceInfo struct { // rebalanceMeta contains information pertaining to an ongoing rebalance operation. type rebalanceMeta struct { - cancel context.CancelFunc `msg:"-"` // to be invoked on rebalance-stop - lastRefreshedAt time.Time `msg:"-"` - StoppedAt time.Time `msg:"stopTs"` // Time when rebalance-stop was issued. - ID string `msg:"id"` // ID of the ongoing rebalance operation - PercentFreeGoal float64 `msg:"pf"` // Computed from total free space and capacity at the start of rebalance - PoolStats []*rebalanceStats `msg:"rss"` // Per-pool rebalance stats keyed by pool index + StoppedAt time.Time `msg:"stopTs"` // Time when rebalance-stop was issued. + ID string `msg:"id"` // ID of the ongoing rebalance operation + PercentFreeGoal float64 `msg:"pf"` // Computed from total free space and capacity at the start of rebalance + PoolStats []*rebalanceStats `msg:"rss"` // Per-pool rebalance stats keyed by pool index } var errRebalanceNotStarted = errors.New("rebalance not started") @@ -313,8 +311,6 @@ func (r *rebalanceMeta) loadWithOpts(ctx context.Context, store objectIO, opts O return err } - r.lastRefreshedAt = time.Now() - return nil } @@ -944,7 +940,7 @@ func (z *erasureServerPools) StartRebalance() { return } ctx, cancel := context.WithCancel(GlobalContext) - z.rebalMeta.cancel = cancel // to be used when rebalance-stop is called + z.rebalCancel = cancel // to be used when rebalance-stop is called z.rebalMu.Unlock() z.rebalMu.RLock() @@ -987,10 +983,9 @@ func (z *erasureServerPools) StopRebalance() error { return nil } - if cancel := r.cancel; cancel != nil { - // cancel != nil only on pool leaders - r.cancel = nil + if cancel := z.rebalCancel; cancel != nil { cancel() + z.rebalCancel = nil } return nil } diff --git a/cmd/erasure-server-pool.go b/cmd/erasure-server-pool.go index 3c301bef1..0bd6d997b 100644 --- a/cmd/erasure-server-pool.go +++ b/cmd/erasure-server-pool.go @@ -53,8 +53,9 @@ type erasureServerPools struct { poolMetaMutex sync.RWMutex poolMeta poolMeta - rebalMu sync.RWMutex - rebalMeta *rebalanceMeta + rebalMu sync.RWMutex + rebalMeta *rebalanceMeta + rebalCancel context.CancelFunc deploymentID [16]byte distributionAlgo string