@@ -222,7 +222,7 @@ func (rc *LRURevisionCache) getFromCacheByRev(ctx context.Context, docID, revID
222222 // given err is nil if we get to this code we can safely assign error returned from addToHLVMapPostLoad to err
223223 // and in the event we do error adding to the HLV map post load we will remove the value from the rev cache below
224224 // and return the error to the caller
225- err = rc .addToHLVMapPostLoad (docID , docRev .RevID , docRev .CV , collectionID )
225+ err = rc .addToHLVMapPostLoad (ctx , docID , docRev .RevID , docRev .CV , collectionID )
226226 if err != nil {
227227 base .WarnfCtx (ctx , "Error adding to HLV map post load in getFromCacheByRev: %v" , err )
228228 }
@@ -253,7 +253,7 @@ func (rc *LRURevisionCache) getFromCacheByCV(ctx context.Context, docID string,
253253 rc .incrRevCacheMemoryUsage (ctx , value .getItemBytes ())
254254 // check for memory based eviction
255255 rc .revCacheMemoryBasedEviction (ctx )
256- rc .addToRevMapPostLoad (docID , docRev .RevID , docRev .CV , collectionID )
256+ rc .addToRevMapPostLoad (ctx , docID , docRev .RevID , docRev .CV , collectionID )
257257 }
258258
259259 return docRev , err
@@ -291,7 +291,7 @@ func (rc *LRURevisionCache) GetActive(ctx context.Context, docID string, collect
291291 // given err is nil if we get to this code we can safely assign error returned from addToHLVMapPostLoad to err
292292 // and in the event we do error adding to the HLV map post load we will remove the value from the rev cache below
293293 // and return the error to the caller
294- err = rc .addToHLVMapPostLoad (docID , docRev .RevID , docRev .CV , collectionID )
294+ err = rc .addToHLVMapPostLoad (ctx , docID , docRev .RevID , docRev .CV , collectionID )
295295 if err != nil {
296296 base .WarnfCtx (ctx , "Error adding to HLV map post load in GetActive: %v" , err )
297297 }
@@ -329,7 +329,7 @@ func (rc *LRURevisionCache) Put(ctx context.Context, docRev DocumentRevision, co
329329 value .store (docRev )
330330
331331 // add new doc version to the rev id lookup map
332- rc .addToRevMapPostLoad (docRev .DocID , docRev .RevID , docRev .CV , collectionID )
332+ rc .addToRevMapPostLoad (ctx , docRev .DocID , docRev .RevID , docRev .CV , collectionID )
333333
334334 // check for rev cache memory based eviction
335335 rc .revCacheMemoryBasedEviction (ctx )
@@ -457,7 +457,7 @@ func (rc *LRURevisionCache) getValueByCV(ctx context.Context, docID string, cv *
457457}
458458
459459// addToRevMapPostLoad will generate and entry in the Rev lookup map for a new document entering the cache
460- func (rc * LRURevisionCache ) addToRevMapPostLoad (docID , revID string , cv * Version , collectionID uint32 ) {
460+ func (rc * LRURevisionCache ) addToRevMapPostLoad (ctx context. Context , docID , revID string , cv * Version , collectionID uint32 ) {
461461 legacyKey := IDAndRev {DocID : docID , RevID : revID , CollectionID : collectionID }
462462 key := IDandCV {DocID : docID , Source : cv .SourceID , Version : cv .Value , CollectionID : collectionID }
463463
@@ -479,6 +479,8 @@ func (rc *LRURevisionCache) addToRevMapPostLoad(docID, revID string, cv *Version
479479 }
480480 // if CV map and rev map are targeting different list elements, update to have both use the cv map element
481481 rc .cache [legacyKey ] = cvElem
482+ rc ._decrRevCacheMemoryUsage (ctx , - revElem .Value .(* revCacheValue ).getItemBytes ())
483+ rc .cacheNumItems .Add (- 1 )
482484 rc .lruList .Remove (revElem )
483485 } else {
484486 // if not found we need to add the element to the rev lookup (for PUT code path)
@@ -487,7 +489,7 @@ func (rc *LRURevisionCache) addToRevMapPostLoad(docID, revID string, cv *Version
487489}
488490
489491// addToHLVMapPostLoad will generate and entry in the CV lookup map for a new document entering the cache
490- func (rc * LRURevisionCache ) addToHLVMapPostLoad (docID , revID string , cv * Version , collectionID uint32 ) error {
492+ func (rc * LRURevisionCache ) addToHLVMapPostLoad (ctx context. Context , docID , revID string , cv * Version , collectionID uint32 ) error {
491493 legacyKey := IDAndRev {DocID : docID , RevID : revID , CollectionID : collectionID }
492494
493495 if cv == nil {
@@ -519,6 +521,8 @@ func (rc *LRURevisionCache) addToHLVMapPostLoad(docID, revID string, cv *Version
519521 }
520522 // if CV map and rev map are targeting different list elements, update to have both use the cv map element
521523 rc .cache [legacyKey ] = cvElem
524+ rc ._decrRevCacheMemoryUsage (ctx , - revElem .Value .(* revCacheValue ).getItemBytes ())
525+ rc .cacheNumItems .Add (- 1 )
522526 rc .lruList .Remove (revElem )
523527 } else {
524528 // if not found we need to add the element to the hlv lookup
0 commit comments