github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/reb/qui.go (about) 1 // Package reb provides global cluster-wide rebalance upon adding/removing storage nodes. 2 /* 3 * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package reb 6 7 import ( 8 "time" 9 10 "github.com/NVIDIA/aistore/core" 11 ) 12 13 type quiArgs struct { 14 rargs *rebArgs 15 reb *Reb 16 done func(rargs *rebArgs) bool 17 } 18 19 func (q *quiArgs) quicb(_ time.Duration /*accum. wait time*/) core.QuiRes { 20 if q.done(q.rargs) { 21 return core.QuiDone 22 } 23 if q.reb.laterx.CAS(true, false) { 24 return core.QuiActive 25 } 26 return core.QuiInactiveCB 27 } 28 29 // Uses generic xact.Quiesce to make sure that no objects are received 30 // during a given `maxWait` interval of time. 31 func (reb *Reb) quiesce(rargs *rebArgs, maxWait time.Duration, cb func(rargs *rebArgs) bool) core.QuiRes { 32 q := &quiArgs{rargs, reb, cb} 33 return reb.xctn().Quiesce(maxWait, q.quicb) 34 } 35 36 // Returns true if all transport queues are empty 37 func (reb *Reb) nodesQuiescent(rargs *rebArgs) (quiescent bool) { 38 locStage := reb.stages.stage.Load() 39 for _, si := range rargs.smap.Tmap { 40 if si.ID() == core.T.SID() && !reb.isQuiescent() { 41 return 42 } 43 status, ok := reb.checkStage(si, rargs, locStage) 44 if !ok || !status.Quiescent { 45 return 46 } 47 } 48 return true 49 }