Skip to content

Commit

Permalink
udpated to address comments and fix flaking tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gregns1 committed Dec 10, 2024
1 parent dee04a8 commit e7ab93c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
3 changes: 0 additions & 3 deletions db/blip_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions db/blip_sync_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion db/revision_cache_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit e7ab93c

Please sign in to comment.