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)
| 479 | |
| 480 | // addToHLVMapPostLoad will generate and entry in the CV lookup map for a new document entering the cache |
| 481 | func (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. |
| 508 | func (rc *LRURevisionCache) RemoveWithRev(ctx context.Context, docID, revID string, collectionID uint32) { |
no test coverage detected