MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / addToHLVMapPostLoad

Method addToHLVMapPostLoad

db/revision_cache_lru.go:481–505  ·  view source on GitHub ↗

addToHLVMapPostLoad will generate and entry in the CV lookup map for a new document entering the cache

(ctx context.Context, docID, revID string, cv *Version, collectionID uint32)

Source from the content-addressed store, hash-verified

479
480// addToHLVMapPostLoad will generate and entry in the CV lookup map for a new document entering the cache
481func (rc *LRURevisionCache) addToHLVMapPostLoad(ctx context.Context, docID, revID string, cv *Version, collectionID uint32) {
482 legacyKey := IDAndRev{DocID: docID, RevID: revID, CollectionID: collectionID}
483
484 if cv == nil {
485 // no cv defined to populate lookup map, exit early
486 return
487 }
488 key := IDandCV{DocID: docID, Source: cv.SourceID, Version: cv.Value, CollectionID: collectionID}
489
490 rc.lock.Lock()
491 defer rc.lock.Unlock()
492 // check for existing value in rev cache map (due to concurrent fetch by rev ID)
493 _, cvFound := rc.hlvCache[key]
494 revElem, revFound := rc.cache[legacyKey]
495 if !revFound {
496 // its possible the element has been evicted if we don't find the element above (high churn on rev cache)
497 // need to return doc revision to caller still but no need repopulate the cache
498 return
499 }
500 // Check if another goroutine has already updated the cv map
501 if !cvFound {
502 // if not found we need to add the element to the hlv lookup
503 rc.hlvCache[key] = revElem
504 }
505}
506
507// Remove removes a value from the revision cache, if present.
508func (rc *LRURevisionCache) RemoveWithRev(ctx context.Context, docID, revID string, collectionID uint32) {

Callers 2

getFromCacheByRevMethod · 0.95
GetActiveMethod · 0.95

Calls 2

LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected