MCPcopy
hub / github.com/NVIDIA/aistore / Begin

Method Begin

xs/archive.go:138–199  ·  view source on GitHub ↗

XactCreateArchMultiObj //

(msg *cmn.ArchiveMsg)

Source from the content-addressed store, hash-verified

136////////////////////////////
137
138func (r *XactCreateArchMultiObj) Begin(msg *cmn.ArchiveMsg) (err error) {
139 lom := cluster.AllocLOM(msg.ArchName)
140 if err = lom.InitBck(&msg.ToBck); err != nil {
141 r.raiseErr(err, 0, msg.ContinueOnError)
142 return
143 }
144 debug.Assert(lom.FullName() == msg.FullName()) // relying on it
145
146 wi := &archwi{r: r, msg: msg, lom: lom}
147 wi.fqn = fs.CSM.Gen(wi.lom, fs.WorkfileType, fs.WorkfileCreateArch)
148 wi.cksum.Init(lom.CksumType())
149
150 smap := r.p.T.Sowner().Get()
151 wi.refc.Store(int32(smap.CountTargets() - 1))
152 wi.tsi, err = cluster.HrwTarget(msg.ToBck.MakeUname(msg.ArchName), smap)
153 if err != nil {
154 r.raiseErr(err, 0, msg.ContinueOnError)
155 return
156 }
157
158 // NOTE: creating archive at BEGIN time (see cleanup)
159 if r.p.T.SID() == wi.tsi.ID() {
160 if errExists := cos.Stat(wi.lom.FQN); errExists != nil {
161 wi.fh, err = wi.lom.CreateFile(wi.fqn)
162 } else if wi.msg.AllowAppendToExisting {
163 switch msg.Mime {
164 case cos.ExtTar:
165 err = wi.openTarForAppend()
166 default:
167 err = fmt.Errorf("unsupported archive type %s, only %s is supported", msg.Mime, cos.ExtTar)
168 }
169 } else {
170 err = fmt.Errorf("%s: not allowed to append to an existing %s", r.p.T, msg.FullName())
171 }
172 if err != nil {
173 return
174 }
175 // construct format-specific writer
176 switch msg.Mime {
177 case cos.ExtTar:
178 tw := &tarWriter{}
179 tw.init(wi)
180 case cos.ExtTgz, cos.ExtTarTgz:
181 tzw := &tgzWriter{}
182 tzw.init(wi)
183 case cos.ExtZip:
184 zw := &zipWriter{}
185 zw.init(wi)
186 case cos.ExtMsgpack:
187 mpw := &msgpackWriter{}
188 mpw.init(wi)
189 default:
190 debug.AssertMsg(false, msg.Mime)
191 return
192 }
193 }
194 r.pending.Lock()
195 r.pending.m[msg.TxnUUID] = wi

Callers

nothing calls this directly

Calls 15

openTarForAppendMethod · 0.95
initMethod · 0.95
initMethod · 0.95
initMethod · 0.95
initMethod · 0.95
AllocLOMFunction · 0.92
AssertFunction · 0.92
HrwTargetFunction · 0.92
StatFunction · 0.92
AssertMsgFunction · 0.92
InitBckMethod · 0.80
raiseErrMethod · 0.80

Tested by

no test coverage detected