diff --git a/db/blip_handler.go b/db/blip_handler.go index 67dcd00219..379a5926f9 100644 --- a/db/blip_handler.go +++ b/db/blip_handler.go @@ -1084,9 +1084,6 @@ func (bh *blipHandler) processRev(rq *blip.Message, stats *processRevStats) (err if deltaSrcRevID, isDelta := revMessage.DeltaSrc(); isDelta && !revMessage.Deleted() { if !bh.sgCanUseDeltas { return base.HTTPErrorf(http.StatusBadRequest, "Deltas are disabled for this peer") - } else if !bh.useHLV() { - // Disable delta sync for protocol versions < 4, CBG-3748 (backwards compatibility for revID delta sync) - return base.HTTPErrorf(http.StatusBadRequest, "backwards compatibility for revTree deltas not yet implemented") } // TODO: Doing a GetRevCopy here duplicates some rev cache retrieval effort, since deltaRevSrc is always diff --git a/db/blip_sync_context.go b/db/blip_sync_context.go index 9fd8eab56a..c16165773c 100644 --- a/db/blip_sync_context.go +++ b/db/blip_sync_context.go @@ -355,16 +355,17 @@ func (bsc *BlipSyncContext) handleChangesResponse(ctx context.Context, sender *b } // The first element of the knownRevsArray returned from CBL is the parent revision to use as deltaSrc for - // revtree clients, for HLV clients the first element is the HLV + // revtree clients. For HLV clients, use the cv as deltaSrc if bsc.useDeltas && len(knownRevsArray) > 0 { if revID, ok := knownRevsArray[0].(string); ok { if bsc.useHLV() { msgHLV, err := extractHLVFromBlipMessage(revID) if err != nil { - base.ErrorfCtx(ctx, "Invalid known rev format for hlv on doc: %s", docID) - return nil + base.DebugfCtx(ctx, base.KeySync, "Invalid known rev format for hlv on doc: %s falling back to full body replication.", docID) + deltaSrcRevID = "" // will force falling back to full body replication below + } else { + deltaSrcRevID = msgHLV.GetCurrentVersionString() } - deltaSrcRevID = msgHLV.GetCurrentVersionString() } else { deltaSrcRevID = revID } @@ -373,6 +374,13 @@ func (bsc *BlipSyncContext) handleChangesResponse(ctx context.Context, sender *b for _, rev := range knownRevsArray { if revID, ok := rev.(string); ok { + msgHLV, err := extractHLVFromBlipMessage(revID) + if err == nil { + // extract cv as string + revID = msgHLV.GetCurrentVersionString() + } + // we can assume here that if we fail to parse hlv, we have received a rev id in known revs. If we don't fail to parse hlv + // then we have extracted cv from it and can assign the cv string to known revs here knownRevs[revID] = true } else { base.ErrorfCtx(ctx, "Invalid response to 'changes' message") diff --git a/db/revision_cache_interface.go b/db/revision_cache_interface.go index c43f952c04..46bf3679a9 100644 --- a/db/revision_cache_interface.go +++ b/db/revision_cache_interface.go @@ -453,6 +453,7 @@ func revCacheLoaderForDocumentCV(ctx context.Context, backingStore RevisionCache base.ErrorfCtx(ctx, "pending CBG-3814 support of channel removal for CV: %v", err) } + deleted = doc.Deleted channels = doc.SyncData.getCurrentChannels() revid = doc.CurrentRev hlv = doc.HLV @@ -462,7 +463,7 @@ func revCacheLoaderForDocumentCV(ctx context.Context, backingStore RevisionCache func (c *DatabaseCollection) getCurrentVersion(ctx context.Context, doc *Document, cv Version) (bodyBytes []byte, attachments AttachmentsMeta, err error) { if err = doc.HasCurrentVersion(ctx, cv); err != nil { - bodyBytes, err = c.getOldRevisionJSON(ctx, doc.ID, doc.CurrentRev) + bodyBytes, err = c.getOldRevisionJSON(ctx, doc.ID, cv.String()) if err != nil || bodyBytes == nil { return nil, nil, err }