github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/xact/xreg/bucket.go (about) 1 // Package xreg provides registry and (renew, find) functions for AIS eXtended Actions (xactions). 2 /* 3 * Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package xreg 6 7 import ( 8 "net/http" 9 10 "github.com/NVIDIA/aistore/api/apc" 11 "github.com/NVIDIA/aistore/cmn" 12 "github.com/NVIDIA/aistore/cmn/debug" 13 "github.com/NVIDIA/aistore/core" 14 "github.com/NVIDIA/aistore/core/meta" 15 "github.com/NVIDIA/aistore/xact" 16 ) 17 18 type ( 19 TCBArgs struct { 20 DP core.DP 21 BckFrom *meta.Bck 22 BckTo *meta.Bck 23 Msg *apc.TCBMsg 24 Phase string 25 } 26 TCObjsArgs struct { 27 BckFrom *meta.Bck 28 BckTo *meta.Bck 29 DP core.DP 30 } 31 DsortArgs struct { 32 BckFrom *meta.Bck 33 BckTo *meta.Bck 34 } 35 ECEncodeArgs struct { 36 Phase string 37 } 38 BckRenameArgs struct { 39 BckFrom *meta.Bck 40 BckTo *meta.Bck 41 RebID string 42 Phase string 43 } 44 MNCArgs struct { 45 Tag string 46 Copies int 47 } 48 LsoArgs struct { 49 Msg *apc.LsoMsg 50 Hdr http.Header 51 } 52 ) 53 54 ////////////// 55 // registry // 56 ////////////// 57 58 func RegBckXact(entry Renewable) { dreg.regBckXact(entry) } 59 60 func (r *registry) regBckXact(entry Renewable) { 61 debug.Assert(xact.IsSameScope(entry.Kind(), xact.ScopeB, xact.ScopeGB)) 62 r.bckXacts[entry.Kind()] = entry // no locking: all reg-s are done at init time 63 } 64 65 // RenewBucketXact is general function to renew bucket xaction without any 66 // additional or specific parameters. 67 func RenewBucketXact(kind string, bck *meta.Bck, args Args, buckets ...*meta.Bck) (res RenewRes) { 68 e := dreg.bckXacts[kind].New(args, bck) 69 return dreg.renew(e, bck, buckets...) 70 } 71 72 func RenewECEncode(bck *meta.Bck, uuid, phase string) RenewRes { 73 return RenewBucketXact(apc.ActECEncode, bck, Args{Custom: &ECEncodeArgs{Phase: phase}, UUID: uuid}) 74 } 75 76 func RenewMakeNCopies(uuid, tag string) { 77 var ( 78 cfg = cmn.GCO.Get() 79 bmd = core.T.Bowner().Get() 80 provider = apc.AIS 81 ) 82 bmd.Range(&provider, nil, func(bck *meta.Bck) bool { 83 if bck.Props.Mirror.Enabled { 84 rns := RenewBckMakeNCopies(bck, uuid, tag, int(bck.Props.Mirror.Copies)) 85 if rns.Err == nil && !rns.IsRunning() { 86 xact.GoRunW(rns.Entry.Get()) 87 } 88 } 89 return false 90 }) 91 // TODO: remais 92 for name := range cfg.Backend.Providers { 93 ns := cfg.Backend.Providers[name] 94 bmd.Range(&name, &ns, func(bck *meta.Bck) bool { 95 if bck.Props.Mirror.Enabled { 96 rns := RenewBckMakeNCopies(bck, uuid, tag, int(bck.Props.Mirror.Copies)) 97 if rns.Err == nil && !rns.IsRunning() { 98 xact.GoRunW(rns.Entry.Get()) 99 } 100 } 101 return false 102 }) 103 } 104 } 105 106 func RenewBckMakeNCopies(bck *meta.Bck, uuid, tag string, copies int) (res RenewRes) { 107 e := dreg.bckXacts[apc.ActMakeNCopies].New(Args{Custom: &MNCArgs{tag, copies}, UUID: uuid}, bck) 108 return dreg.renew(e, bck) 109 } 110 111 func RenewPromote(uuid string, bck *meta.Bck, args *apc.PromoteArgs) RenewRes { 112 return RenewBucketXact(apc.ActPromote, bck, Args{Custom: args, UUID: uuid}) 113 } 114 115 func RenewBckLoadLomCache(uuid string, bck *meta.Bck) RenewRes { 116 return RenewBucketXact(apc.ActLoadLomCache, bck, Args{UUID: uuid}) 117 } 118 119 func RenewPutMirror(lom *core.LOM) RenewRes { 120 return RenewBucketXact(apc.ActPutCopies, lom.Bck(), Args{Custom: lom}) 121 } 122 123 func RenewTCB(uuid, kind string, custom *TCBArgs) RenewRes { 124 return RenewBucketXact( 125 kind, 126 custom.BckTo, // prevent concurrent copy/transform => same dst 127 Args{Custom: custom, UUID: uuid}, 128 custom.BckFrom, custom.BckTo, // find when renewing 129 ) 130 } 131 132 func RenewDsort(id string, custom *DsortArgs) RenewRes { 133 return RenewBucketXact( 134 apc.ActDsort, 135 custom.BckFrom, 136 Args{Custom: custom, UUID: id}, 137 custom.BckFrom, custom.BckTo, 138 ) 139 } 140 141 func RenewBckRename(bckFrom, bckTo *meta.Bck, uuid string, rmdVersion int64, phase string) RenewRes { 142 custom := &BckRenameArgs{ 143 Phase: phase, 144 RebID: xact.RebID2S(rmdVersion), 145 BckFrom: bckFrom, 146 BckTo: bckTo, 147 } 148 return RenewBucketXact(apc.ActMoveBck, bckTo, Args{Custom: custom, UUID: uuid}) 149 } 150 151 func RenewLso(bck *meta.Bck, uuid string, msg *apc.LsoMsg, hdr http.Header) RenewRes { 152 custom := &LsoArgs{ 153 Msg: msg, 154 Hdr: hdr, 155 } 156 e := dreg.bckXacts[apc.ActList].New(Args{UUID: uuid, Custom: custom}, bck) 157 return dreg.renewByID(e, bck) 158 }