MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / findPosting

Method findPosting

posting/list.go:418–490  ·  view source on GitHub ↗

Return if piterator needs to be searched or not after mutable map and the posting if found.

(readTs, uid uint64)

Source from the content-addressed store, hash-verified

416
417// Return if piterator needs to be searched or not after mutable map and the posting if found.
418func (mm *MutableLayer) findPosting(readTs, uid uint64) (bool, *pb.Posting) {
419 if mm == nil {
420 return true, nil
421 }
422
423 deleteAllMarker := mm.populateDeleteAll(readTs)
424
425 // To get the posting from cached values, we need to make sure that it is >= deleteAllMarker
426 // If we get it using mm.iterate (in getPosting), we know that we only see postings >= deleteAllMarker
427 getPostingFromCachedValues := func() (*pb.Posting, uint64) {
428 if readTs == mm.readTs {
429 posI, ok := mm.currentUids[uid]
430 if ok {
431 return mm.currentEntries.Postings[posI], mm.readTs
432 }
433 }
434 posting, ok := mm.committedUids[uid]
435 if ok {
436 return posting, posting.CommitTs
437 }
438 return nil, 0
439 }
440
441 // Check if readTs >= committedUidTime. It lets us figure out if we can use the cached values or not.
442 getPosting := func() *pb.Posting {
443 // If the timestamp that we are reading for is ahead of the cache map, we can check the map and return.
444 // Otherwise we need to iterate (slow) the entire map, and keep the latest entry per the commitTs.
445 if readTs >= mm.committedUidsTime {
446 posting, ts := getPostingFromCachedValues()
447 if posting == nil || ts < deleteAllMarker {
448 return nil
449 }
450 return posting
451 } else {
452 var posting *pb.Posting
453 var tsFound uint64
454 // Since iterate could be out of order, we need to keep a track of the time we saw the posting.
455 mm.iterate(func(ts uint64, pl *pb.PostingList) {
456 for _, mpost := range pl.Postings {
457 if mpost.Uid == uid {
458 if posting == nil {
459 posting = mpost
460 tsFound = ts
461 } else if tsFound <= ts {
462 posting = mpost
463 tsFound = ts
464 }
465 }
466 }
467 }, readTs)
468 return posting
469 }
470 }
471
472 posting := getPosting()
473 if posting != nil {
474 // If we find the posting, either we return it, or it has been deleted. Either ways, we don't search
475 // more in the immutable layer.

Callers

nothing calls this directly

Calls 2

populateDeleteAllMethod · 0.95
iterateMethod · 0.95

Tested by

no test coverage detected