MCPcopy
hub / github.com/dgraph-io/dgraph / conflictKeysForNQuad

Method conflictKeysForNQuad

dgraph/cmd/live/batch.go:247–338  ·  view source on GitHub ↗
(nq *api.NQuad)

Source from the content-addressed store, hash-verified

245}
246
247func (l *loader) conflictKeysForNQuad(nq *api.NQuad) ([]uint64, error) {
248 attr := x.NamespaceAttr(nq.Namespace, nq.Predicate)
249 pred, found := l.schema.preds[attr]
250
251 // We don't need to generate conflict keys for predicate with noconflict directive.
252 if found && pred.NoConflict {
253 return nil, nil
254 }
255
256 keys := make([]uint64, 0)
257
258 // Calculates the conflict keys, inspired by the logic in
259 // addMutationInteration in posting/list.go.
260 sid, err := strconv.ParseUint(nq.Subject, 0, 64)
261 if err != nil {
262 return nil, err
263 }
264
265 var oid uint64
266 var de *pb.DirectedEdge
267
268 if nq.ObjectValue == nil {
269 oid, _ = strconv.ParseUint(nq.ObjectId, 0, 64)
270 de = createUidEdge(nq, sid, oid)
271 } else {
272 var err error
273 de, err = createValueEdge(nq, sid)
274 x.Check(err)
275 }
276
277 // If the predicate is not found in schema then we don't have to generate any more keys.
278 if !found {
279 return keys, nil
280 }
281
282 if pred.List {
283 key := fingerprintEdge(de, pred)
284 keys = append(keys, farm.Fingerprint64(x.DataKey(attr, sid))^key)
285 } else {
286 keys = append(keys, farm.Fingerprint64(x.DataKey(attr, sid)))
287 }
288
289 if pred.Reverse {
290 oi, err := strconv.ParseUint(nq.ObjectId, 0, 64)
291 if err != nil {
292 return keys, err
293 }
294 keys = append(keys, farm.Fingerprint64(x.DataKey(attr, oi)))
295 }
296
297 if nq.ObjectValue == nil || !(pred.Count || pred.Index) {
298 return keys, nil
299 }
300
301 val := sid
302 if pred.Upsert {
303 val = 0
304 }

Callers 1

conflictKeysForReqMethod · 0.95

Calls 15

GetValueTypeMethod · 0.95
GetValueMethod · 0.95
NamespaceAttrFunction · 0.92
CheckFunction · 0.92
DataKeyFunction · 0.92
GetTokenizerFunction · 0.92
TypeIDTypeAlias · 0.92
ConvertFunction · 0.92
BuildTokensFunction · 0.92
GetTokenizerForLangFunction · 0.92
IndexKeyFunction · 0.92
createUidEdgeFunction · 0.85

Tested by

no test coverage detected