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

Function HeadObject

api/object.go:142–194  ·  view source on GitHub ↗

object-level API HeadObject returns the object properties; can be conventionally used to establish local (in cluster) presence.

(baseParams BaseParams, bck cmn.Bck, object string, checkExists ...bool)

Source from the content-addressed store, hash-verified

140// HeadObject returns the object properties; can be conventionally used to establish
141// local (in cluster) presence.
142func HeadObject(baseParams BaseParams, bck cmn.Bck, object string, checkExists ...bool) (*cmn.ObjectProps, error) {
143 var (
144 q url.Values
145 checkIsCached bool
146 )
147 if len(checkExists) > 0 {
148 checkIsCached = checkExists[0]
149 }
150 baseParams.Method = http.MethodHead
151
152 if checkIsCached {
153 q = make(url.Values, 4)
154 q = bck.AddToQuery(q)
155 q.Set(apc.QparamHeadObj, strconv.Itoa(apc.HeadObjAvoidRemote)) // TODO: support the entire enum
156 q.Set(apc.QparamSilent, "true")
157 } else {
158 q = bck.AddToQuery(nil)
159 }
160
161 reqParams := AllocRp()
162 defer FreeRp(reqParams)
163 {
164 reqParams.BaseParams = baseParams
165 reqParams.Path = apc.URLPathObjects.Join(bck.Name, object)
166 reqParams.Query = q
167 }
168 resp, err := reqParams.doResp(nil)
169 if err != nil {
170 return nil, err
171 }
172 if checkIsCached {
173 return nil, err
174 }
175
176 // NOTE: compare with `headObject()` in target.go
177 // first, cnm.ObjAttrs
178 op := &cmn.ObjectProps{}
179 op.Cksum = op.ObjAttrs.FromHeader(resp.Header)
180 // second, all the rest
181 err = cmn.IterFields(op, func(tag string, field cmn.IterField) (error, bool) {
182 headerName := cmn.PropToHeader(tag)
183 // skip the missing ones
184 if _, ok := resp.Header[textproto.CanonicalMIMEHeaderKey(headerName)]; !ok {
185 return nil, false
186 }
187 // single-value
188 return field.SetValue(resp.Header.Get(headerName), true /*force*/), false
189 }, cmn.IterOpts{OnlyRead: false})
190 if err != nil {
191 return nil, err
192 }
193 return op, nil
194}
195
196// Given cos.SimpleKVs (map[string]string) keys and values, sets object's custom properties.
197// By default, adds new or updates existing custom keys.

Callers 15

HeadObjectMethod · 0.92
objectCheckExistsFunction · 0.92
showObjPropsFunction · 0.92
HeadObjMethod · 0.92
GetObjReaderMethod · 0.92
PutObjMethod · 0.92
verifyPropsFunction · 0.92
TestObjPropsFunction · 0.92
ecResilverFunction · 0.92
TestECGenerationsFunction · 0.92

Calls 11

IterFieldsFunction · 0.92
PropToHeaderFunction · 0.92
AllocRpFunction · 0.85
FreeRpFunction · 0.85
JoinMethod · 0.80
doRespMethod · 0.80
FromHeaderMethod · 0.80
SetMethod · 0.65
SetValueMethod · 0.65
GetMethod · 0.65
AddToQueryMethod · 0.45

Tested by 7

verifyPropsFunction · 0.74
TestObjPropsFunction · 0.74
ecResilverFunction · 0.74
TestECGenerationsFunction · 0.74