MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / insertPosting

Method insertPosting

posting/list.go:354–401  ·  view source on GitHub ↗

insertPosting inserts a new posting in the mutable layers. It updates the currentUids map.

(mpost *pb.Posting, hasCountIndex bool)

Source from the content-addressed store, hash-verified

352
353// insertPosting inserts a new posting in the mutable layers. It updates the currentUids map.
354func (mm *MutableLayer) insertPosting(mpost *pb.Posting, hasCountIndex bool) {
355 if mm.readTs != 0 {
356 x.AssertTruef(mpost.StartTs == mm.readTs, "Diffrenent read ts and start ts found %d %d", mpost.StartTs, mm.readTs)
357 }
358
359 mm.readTs = mpost.StartTs
360
361 if hasDeleteAll(mpost) {
362 if mpost.CommitTs > mm.deleteAllMarker {
363 mm.deleteAllMarker = mpost.CommitTs
364 }
365 }
366
367 if mpost.Uid != 0 {
368 // If hasCountIndex, in that case while inserting uids, if there's a delete, we only delete from the
369 // current entries, we dont' insert the delete posting. If we insert the delete posting, there won't be
370 // any set posting in the list. This would mess up the count. We can do this for all types, however,
371 // there might be a performance hit becasue of it.
372 mm.populateUidMap(mm.currentEntries)
373 if postIndex, ok := mm.currentUids[mpost.Uid]; ok {
374 if hasCountIndex && mpost.Op == Del {
375 // If the posting was there before, just remove it from the map, and then remove it
376 // from the array.
377 post := mm.currentEntries.Postings[postIndex]
378 if post.Op == Del {
379 // No need to do anything
380 mm.currentEntries.Postings[postIndex] = mpost
381 return
382 }
383 res := mm.currentEntries.Postings[:postIndex]
384 if postIndex+1 <= len(mm.currentEntries.Postings) {
385 res = append(res,
386 mm.currentEntries.Postings[(postIndex+1):]...)
387 }
388 mm.currentUids = nil
389 mm.currentEntries.Postings = res
390 return
391 }
392 mm.currentEntries.Postings[postIndex] = mpost
393 } else {
394 mm.currentEntries.Postings = append(mm.currentEntries.Postings, mpost)
395 mm.currentUids[mpost.Uid] = len(mm.currentEntries.Postings) - 1
396 }
397 return
398 }
399
400 mm.currentEntries.Postings = append(mm.currentEntries.Postings, mpost)
401}
402
403func (mm *MutableLayer) print() string {
404 if mm == nil {

Callers 1

updateMutationLayerMethod · 0.80

Calls 3

populateUidMapMethod · 0.95
AssertTruefFunction · 0.92
hasDeleteAllFunction · 0.85

Tested by

no test coverage detected