MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / alignRevTreeHistoryForHLVWrite

Method alignRevTreeHistoryForHLVWrite

db/crud.go:3798–3823  ·  view source on GitHub ↗

alignRevTreeHistoryForHLVWrite will take incoming rev tree list and add any newer revisions to the local document. If skipHistoryCheck is false here and the history between the incoming rev tree and local rev tree differs then the local docs current rev will be tombstoned and incoming history will b

(ctx context.Context, db *DatabaseCollectionWithUser, newDoc *Document, revTreeHistory []string, skipHistoryCheck bool)

Source from the content-addressed store, hash-verified

3796// rev will be tombstoned and incoming history will be active branch. If skipHistoryCheck is true then we are either allowing
3797// conflicting tombstones or we are aligning a rev tree post conflict resolution so here in this situation we want to avoid history check.
3798func (doc *Document) alignRevTreeHistoryForHLVWrite(ctx context.Context, db *DatabaseCollectionWithUser, newDoc *Document, revTreeHistory []string, skipHistoryCheck bool) error {
3799 currentRevIndex, parent := doc.findWhereRevBranchesFromHistory(revTreeHistory)
3800
3801 if !skipHistoryCheck {
3802 localRevID := doc.GetRevTreeID()
3803 if parent != localRevID {
3804 base.DebugfCtx(ctx, base.KeyCRUD, "incoming rev tree history has different history than local doc %s, tombstoning local active branch and writing incoming tree", base.UD(doc.ID))
3805
3806 _, err := db.tombstoneActiveRevision(ctx, doc, localRevID)
3807 if err != nil {
3808 return err
3809 }
3810 }
3811 }
3812
3813 newRev, err := doc.addNewerRevisionsToRevTreeHistory(newDoc, currentRevIndex, parent, revTreeHistory)
3814 if err != nil {
3815 return err
3816 }
3817 // If we are skipping history check we are either allowing conflicting tombstones or we are aligning a rev tree post
3818 // conflict resolution. In both cases we do not want to update the current rev here on the document.
3819 if !skipHistoryCheck {
3820 doc.SetRevTreeID(newRev)
3821 }
3822 return nil
3823}
3824
3825// addNewerRevisionsToRevTreeHistory will add any newer rev tree id's to the local document history
3826func (doc *Document) addNewerRevisionsToRevTreeHistory(newDoc *Document, currentRevIndex int, parent string, docHistory []string) (string, error) {

Callers 2

TestAlignRevTreeHistoryFunction · 0.95

Calls 7

DebugfCtxFunction · 0.92
UDFunction · 0.92
SetRevTreeIDMethod · 0.80
GetRevTreeIDMethod · 0.45

Tested by 1

TestAlignRevTreeHistoryFunction · 0.76