fix: after saveRebalanceStats cancel will be empty (#21597)

This commit is contained in:
jiuker
2025-09-20 12:51:57 +08:00
committed by GitHub
parent 756f3c8142
commit 456d9462e5
2 changed files with 10 additions and 14 deletions

View File

@@ -98,12 +98,10 @@ type rebalanceInfo struct {
// rebalanceMeta contains information pertaining to an ongoing rebalance operation. // rebalanceMeta contains information pertaining to an ongoing rebalance operation.
type rebalanceMeta struct { type rebalanceMeta struct {
cancel context.CancelFunc `msg:"-"` // to be invoked on rebalance-stop StoppedAt time.Time `msg:"stopTs"` // Time when rebalance-stop was issued.
lastRefreshedAt time.Time `msg:"-"` ID string `msg:"id"` // ID of the ongoing rebalance operation
StoppedAt time.Time `msg:"stopTs"` // Time when rebalance-stop was issued. PercentFreeGoal float64 `msg:"pf"` // Computed from total free space and capacity at the start of rebalance
ID string `msg:"id"` // ID of the ongoing rebalance operation PoolStats []*rebalanceStats `msg:"rss"` // Per-pool rebalance stats keyed by pool index
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") var errRebalanceNotStarted = errors.New("rebalance not started")
@@ -313,8 +311,6 @@ func (r *rebalanceMeta) loadWithOpts(ctx context.Context, store objectIO, opts O
return err return err
} }
r.lastRefreshedAt = time.Now()
return nil return nil
} }
@@ -944,7 +940,7 @@ func (z *erasureServerPools) StartRebalance() {
return return
} }
ctx, cancel := context.WithCancel(GlobalContext) 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.Unlock()
z.rebalMu.RLock() z.rebalMu.RLock()
@@ -987,10 +983,9 @@ func (z *erasureServerPools) StopRebalance() error {
return nil return nil
} }
if cancel := r.cancel; cancel != nil { if cancel := z.rebalCancel; cancel != nil {
// cancel != nil only on pool leaders
r.cancel = nil
cancel() cancel()
z.rebalCancel = nil
} }
return nil return nil
} }

View File

@@ -53,8 +53,9 @@ type erasureServerPools struct {
poolMetaMutex sync.RWMutex poolMetaMutex sync.RWMutex
poolMeta poolMeta poolMeta poolMeta
rebalMu sync.RWMutex rebalMu sync.RWMutex
rebalMeta *rebalanceMeta rebalMeta *rebalanceMeta
rebalCancel context.CancelFunc
deploymentID [16]byte deploymentID [16]byte
distributionAlgo string distributionAlgo string