Attempts to retrieve the active revision for a document from the cache. Requires retrieval of the document from the bucket to guarantee the current active revision, but does minimal unmarshalling of the retrieved document to get the current rev from _sync metadata. If active rev is already in the
(ctx context.Context, docID string, collectionID uint32)
| 265 | // rev cache, will use it. Otherwise will add to the rev cache using the raw document obtained in the |
| 266 | // initial retrieval. |
| 267 | func (rc *LRURevisionCache) GetActive(ctx context.Context, docID string, collectionID uint32) (DocumentRevision, error) { |
| 268 | |
| 269 | // Look up active rev for doc. Note - can't rely on DocUnmarshalAll here when includeBody=true, because for a |
| 270 | // cache hit we don't want to do that work (yet). |
| 271 | bucketDoc, getErr := rc.backingStores[collectionID].GetDocument(ctx, docID, DocUnmarshalSync) |
| 272 | if getErr != nil { |
| 273 | return DocumentRevision{}, getErr |
| 274 | } |
| 275 | if bucketDoc == nil { |
| 276 | return DocumentRevision{}, nil |
| 277 | } |
| 278 | |
| 279 | // Retrieve from or add to rev cache |
| 280 | value := rc.getValue(ctx, docID, bucketDoc.GetRevTreeID(), collectionID, true) |
| 281 | |
| 282 | docRev, statEvent, err := value.loadForDoc(ctx, rc.backingStores[collectionID], bucketDoc) |
| 283 | rc.statsRecorderFunc(statEvent) |
| 284 | |
| 285 | if !statEvent && err == nil { |
| 286 | // cache miss so we had to load doc, increment memory count |
| 287 | rc.incrRevCacheMemoryUsage(ctx, value.getItemBytes()) |
| 288 | // check for rev cache memory based eviction |
| 289 | rc.revCacheMemoryBasedEviction(ctx) |
| 290 | // add successfully fetched value to CV lookup map too |
| 291 | // given err is nil if we get to this code we can safely assign error returned from addToHLVMapPostLoad to err |
| 292 | // and in the event we do error adding to the HLV map post load we will remove the value from the rev cache below |
| 293 | // and return the error to the caller |
| 294 | rc.addToHLVMapPostLoad(ctx, docID, docRev.RevID, docRev.CV, collectionID) |
| 295 | } |
| 296 | |
| 297 | if err != nil { |
| 298 | rc.removeValue(value, collectionID) // don't keep failed loads in the cache |
| 299 | } |
| 300 | |
| 301 | return docRev, err |
| 302 | } |
| 303 | |
| 304 | func (rc *LRURevisionCache) statsRecorderFunc(cacheHit bool) { |
| 305 |