@@ -34,9 +34,9 @@ type RevisionCache interface {
3434 GetWithRev (ctx context.Context , docID , revID string , collectionID uint32 , includeDelta bool ) (DocumentRevision , error )
3535
3636 // GetWithCV returns the given revision by CV, and stores if not already cached.
37- // When includeBody=true, the returned DocumentRevision will include a mutable shallow copy of the marshaled body.
3837 // When includeDelta=true, the returned DocumentRevision will include delta - requires additional locking during retrieval.
39- GetWithCV (ctx context.Context , docID string , cv * Version , collectionID uint32 , includeDelta bool ) (DocumentRevision , error )
38+ // When loadBackup=true, will load from backup revisions if requested version is not active document
39+ GetWithCV (ctx context.Context , docID string , cv * Version , collectionID uint32 , includeDelta bool , loadBackup bool ) (DocumentRevision , error )
4040
4141 // GetActive returns the current revision for the given doc ID, and stores if not already cached.
4242 GetActive (ctx context.Context , docID string , collectionID uint32 ) (docRev DocumentRevision , err error )
@@ -127,7 +127,7 @@ func DefaultRevisionCacheOptions() *RevisionCacheOptions {
127127type RevisionCacheBackingStore interface {
128128 GetDocument (ctx context.Context , docid string , unmarshalLevel DocumentUnmarshalLevel ) (doc * Document , err error )
129129 getRevision (ctx context.Context , doc * Document , revid string ) ([]byte , AttachmentsMeta , base.Set , error )
130- getCurrentVersion (ctx context.Context , doc * Document , cv Version ) ([]byte , AttachmentsMeta , base.Set , bool , error )
130+ getCurrentVersion (ctx context.Context , doc * Document , cv Version , loadBackup bool ) ([]byte , AttachmentsMeta , base.Set , bool , error )
131131}
132132
133133// collectionRevisionCache is a view of a revision cache for a collection.
@@ -150,8 +150,8 @@ func (c *collectionRevisionCache) GetWithRev(ctx context.Context, docID, revID s
150150}
151151
152152// Get is for per collection access to Get method
153- func (c * collectionRevisionCache ) GetWithCV (ctx context.Context , docID string , cv * Version , includeDelta bool ) (DocumentRevision , error ) {
154- return (* c .revCache ).GetWithCV (ctx , docID , cv , c .collectionID , includeDelta )
153+ func (c * collectionRevisionCache ) GetWithCV (ctx context.Context , docID string , cv * Version , includeDelta bool , loadBackup bool ) (DocumentRevision , error ) {
154+ return (* c .revCache ).GetWithCV (ctx , docID , cv , c .collectionID , includeDelta , loadBackup )
155155}
156156
157157// GetActive is for per collection access to GetActive method
@@ -421,7 +421,7 @@ func revCacheLoader(ctx context.Context, backingStore RevisionCacheBackingStore,
421421
422422// revCacheLoaderForCv will load a document from the bucket using the CV, compare the fetched doc and the CV specified in the function,
423423// and will still return revid for purpose of populating the Rev ID lookup map on the cache
424- func revCacheLoaderForCv (ctx context.Context , backingStore RevisionCacheBackingStore , id IDandCV ) (bodyBytes []byte , history Revisions , channels base.Set , removed bool , attachments AttachmentsMeta , deleted bool , expiry * time.Time , revid string , hlv * HybridLogicalVector , err error ) {
424+ func revCacheLoaderForCv (ctx context.Context , backingStore RevisionCacheBackingStore , id IDandCV , loadBackup bool ) (bodyBytes []byte , history Revisions , channels base.Set , removed bool , attachments AttachmentsMeta , deleted bool , expiry * time.Time , revid string , hlv * HybridLogicalVector , err error ) {
425425 cv := Version {
426426 Value : id .Version ,
427427 SourceID : id .Source ,
@@ -431,7 +431,7 @@ func revCacheLoaderForCv(ctx context.Context, backingStore RevisionCacheBackingS
431431 return bodyBytes , history , channels , removed , attachments , deleted , expiry , revid , hlv , err
432432 }
433433
434- return revCacheLoaderForDocumentCV (ctx , backingStore , doc , cv )
434+ return revCacheLoaderForDocumentCV (ctx , backingStore , doc , cv , loadBackup )
435435}
436436
437437// Common revCacheLoader functionality used either during a cache miss (from revCacheLoader), or directly when retrieving current rev from cache
@@ -471,8 +471,8 @@ func revCacheLoaderForDocument(ctx context.Context, backingStore RevisionCacheBa
471471
472472// revCacheLoaderForDocumentCV used either during cache miss (from revCacheLoaderForCv), or used directly when getting current active CV from cache
473473// nolint:staticcheck
474- func revCacheLoaderForDocumentCV (ctx context.Context , backingStore RevisionCacheBackingStore , doc * Document , cv Version ) (bodyBytes []byte , history Revisions , channels base.Set , removed bool , attachments AttachmentsMeta , deleted bool , expiry * time.Time , revid string , hlv * HybridLogicalVector , err error ) {
475- if bodyBytes , attachments , channels , deleted , err = backingStore .getCurrentVersion (ctx , doc , cv ); err != nil {
474+ func revCacheLoaderForDocumentCV (ctx context.Context , backingStore RevisionCacheBackingStore , doc * Document , cv Version , loadBackup bool ) (bodyBytes []byte , history Revisions , channels base.Set , removed bool , attachments AttachmentsMeta , deleted bool , expiry * time.Time , revid string , hlv * HybridLogicalVector , err error ) {
475+ if bodyBytes , attachments , channels , deleted , err = backingStore .getCurrentVersion (ctx , doc , cv , loadBackup ); err != nil {
476476 return nil , nil , nil , false , nil , false , nil , "" , nil , err
477477 }
478478
@@ -481,9 +481,9 @@ func revCacheLoaderForDocumentCV(ctx context.Context, backingStore RevisionCache
481481 if doc .HLV .ExtractCurrentVersionFromHLV ().Equal (cv ) {
482482 revid = doc .GetRevTreeID ()
483483 deleted = doc .Deleted
484+ hlv = doc .HLV
484485 }
485486
486- hlv = doc .HLV
487487 validatedHistory , getHistoryErr := doc .History .getHistory (revid )
488488 if getHistoryErr != nil {
489489 return bodyBytes , history , channels , removed , attachments , deleted , doc .Expiry , revid , hlv , err
@@ -493,8 +493,12 @@ func revCacheLoaderForDocumentCV(ctx context.Context, backingStore RevisionCache
493493 return bodyBytes , history , channels , removed , attachments , deleted , doc .Expiry , revid , hlv , err
494494}
495495
496- func (c * DatabaseCollection ) getCurrentVersion (ctx context.Context , doc * Document , cv Version ) (bodyBytes []byte , attachments AttachmentsMeta , channels base.Set , deleted bool , err error ) {
496+ func (c * DatabaseCollection ) getCurrentVersion (ctx context.Context , doc * Document , cv Version , loadBackup bool ) (bodyBytes []byte , attachments AttachmentsMeta , channels base.Set , deleted bool , err error ) {
497497 if err = doc .HasCurrentVersion (ctx , cv ); err != nil {
498+ if ! loadBackup {
499+ // do not attempt to fetch backup revision by CV unless specified
500+ return nil , nil , nil , false , ErrMissing
501+ }
498502 bodyBytes , channels , deleted , err = c .getOldRevisionJSON (ctx , doc .ID , base .Crc32cHashString ([]byte (cv .String ())))
499503 if err != nil || bodyBytes == nil {
500504 return nil , nil , nil , false , err
0 commit comments