github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/xact/xs/rebres.go (about) 1 // Package xs is a collection of eXtended actions (xactions), including multi-object 2 // operations, list-objects, (cluster) rebalance and (target) resilver, ETL, and more. 3 /* 4 * Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved. 5 */ 6 package xs 7 8 import ( 9 "sync" 10 11 "github.com/NVIDIA/aistore/api/apc" 12 "github.com/NVIDIA/aistore/cmn" 13 "github.com/NVIDIA/aistore/cmn/cos" 14 "github.com/NVIDIA/aistore/cmn/debug" 15 "github.com/NVIDIA/aistore/cmn/nlog" 16 "github.com/NVIDIA/aistore/core" 17 "github.com/NVIDIA/aistore/core/meta" 18 "github.com/NVIDIA/aistore/xact" 19 "github.com/NVIDIA/aistore/xact/xreg" 20 ) 21 22 // rebalance & resilver xactions 23 24 type ( 25 rebFactory struct { 26 xreg.RenewBase 27 xctn *Rebalance 28 } 29 resFactory struct { 30 xreg.RenewBase 31 xctn *Resilver 32 } 33 34 Rebalance struct { 35 xact.Base 36 } 37 Resilver struct { 38 xact.Base 39 } 40 ) 41 42 // interface guard 43 var ( 44 _ core.Xact = (*Rebalance)(nil) 45 _ xreg.Renewable = (*rebFactory)(nil) 46 47 _ core.Xact = (*Resilver)(nil) 48 _ xreg.Renewable = (*resFactory)(nil) 49 ) 50 51 /////////////// 52 // Rebalance // 53 /////////////// 54 55 func (*rebFactory) New(args xreg.Args, _ *meta.Bck) xreg.Renewable { 56 return &rebFactory{RenewBase: xreg.RenewBase{Args: args}} 57 } 58 59 func (p *rebFactory) Start() error { 60 p.xctn = NewRebalance(p.Args.UUID, p.Kind()) 61 return nil 62 } 63 64 func (*rebFactory) Kind() string { return apc.ActRebalance } 65 func (p *rebFactory) Get() core.Xact { return p.xctn } 66 67 func (p *rebFactory) WhenPrevIsRunning(prevEntry xreg.Renewable) (wpr xreg.WPR, err error) { 68 xreb := prevEntry.(*rebFactory) 69 wpr = xreg.WprAbort 70 if xreb.Args.UUID > p.Args.UUID { 71 nlog.Errorf("(reb: %s) %s is greater than %s", xreb.xctn, xreb.Args.UUID, p.Args.UUID) 72 wpr = xreg.WprUse 73 } else if xreb.Args.UUID == p.Args.UUID { 74 if cmn.Rom.FastV(4, cos.SmoduleXs) { 75 nlog.Infof("%s already running, nothing to do", xreb.xctn) 76 } 77 wpr = xreg.WprUse 78 } 79 return 80 } 81 82 func NewRebalance(id, kind string) (xreb *Rebalance) { 83 xreb = &Rebalance{} 84 xreb.InitBase(id, kind, nil) 85 return 86 } 87 88 func (*Rebalance) Run(*sync.WaitGroup) { debug.Assert(false) } 89 90 func (xreb *Rebalance) RebID() int64 { 91 id, err := xact.S2RebID(xreb.ID()) 92 debug.AssertNoErr(err) 93 return id 94 } 95 96 func (xreb *Rebalance) Snap() (snap *core.Snap) { 97 snap = &core.Snap{} 98 xreb.ToSnap(snap) 99 snap.RebID = xreb.RebID() 100 101 snap.IdleX = xreb.IsIdle() 102 103 // the number of rebalanced objects _is_ the number of transmitted objects (definition) 104 // (TODO: revisit) 105 snap.Stats.Objs = snap.Stats.OutObjs 106 snap.Stats.Bytes = snap.Stats.OutBytes 107 return 108 } 109 110 ////////////// 111 // Resilver // 112 ////////////// 113 114 func (*resFactory) New(args xreg.Args, _ *meta.Bck) xreg.Renewable { 115 return &resFactory{RenewBase: xreg.RenewBase{Args: args}} 116 } 117 118 func (p *resFactory) Start() error { 119 p.xctn = NewResilver(p.UUID(), p.Kind()) 120 return nil 121 } 122 123 func (*resFactory) Kind() string { return apc.ActResilver } 124 func (p *resFactory) Get() core.Xact { return p.xctn } 125 func (*resFactory) WhenPrevIsRunning(xreg.Renewable) (xreg.WPR, error) { return xreg.WprAbort, nil } 126 127 func NewResilver(id, kind string) (xres *Resilver) { 128 xres = &Resilver{} 129 xres.InitBase(id, kind, nil) 130 return 131 } 132 133 func (*Resilver) Run(*sync.WaitGroup) { debug.Assert(false) } 134 135 func (xres *Resilver) String() string { 136 if xres == nil { 137 return "<xres-nil>" 138 } 139 return xres.Base.String() 140 } 141 142 func (xres *Resilver) Snap() (snap *core.Snap) { 143 snap = &core.Snap{} 144 xres.ToSnap(snap) 145 146 snap.IdleX = xres.IsIdle() 147 return 148 }