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

Method resolveDocLocalWins

db/crud.go:2015–2041  ·  view source on GitHub ↗

resolveDocLocalWins makes the following updates to the revision tree: - Adds the remote revision to the rev tree - Makes a copy of the local revision as a child of the remote revision - Tombstones the (original) local revision TODO: This is CBL 2.x handling, and is compatible with the current versi

(ctx context.Context, localDoc *Document, remoteDoc *Document, conflict Conflict, docHistory []string)

Source from the content-addressed store, hash-verified

2013// revision. This will be addressed post-Hydrogen with version vector work, but additional analysis
2014// of options for Hydrogen should be completed.
2015func (db *DatabaseCollectionWithUser) resolveDocLocalWins(ctx context.Context, localDoc *Document, remoteDoc *Document, conflict Conflict, docHistory []string) (resolvedRevID string, updatedHistory []string, err error) {
2016
2017 // Clone the local revision as a child of the remote revision
2018 docBodyBytes, err := localDoc.BodyBytes(ctx)
2019 if err != nil {
2020 return "", nil, fmt.Errorf("Unable to retrieve local document body while resolving conflict: %w", err)
2021 }
2022
2023 var newRevID string
2024 newRevID, docHistory = localWinsConflictResolutionRevTreeHandling(ctx, localDoc, remoteDoc, docBodyBytes, docHistory)
2025
2026 // Update the history for the incoming doc to prepend the cloned revID
2027 docHistory = append([]string{newRevID}, docHistory...)
2028 remoteDoc.RevID = newRevID
2029
2030 localWinsConflictResolutionDocumentHandling(ctx, localDoc, remoteDoc, docHistory, docBodyBytes, newRevID)
2031
2032 // Tombstone the local revision
2033 localRevID := localDoc.GetRevTreeID()
2034 tombstoneRevID, tombstoneErr := db.tombstoneActiveRevision(ctx, localDoc, localRevID)
2035 if tombstoneErr != nil {
2036 return "", nil, tombstoneErr
2037 }
2038
2039 base.DebugfCtx(ctx, base.KeyReplicate, "Resolved conflict for doc %s as localWins - local rev %s moved to %s, and tombstoned with %s", base.UD(localDoc.ID), localRevID, newRevID, tombstoneRevID)
2040 return newRevID, docHistory, nil
2041}
2042
2043// resolveDocMerge makes the following updates to the revision tree
2044// - Tombstones the local revision

Callers 1

resolveConflictMethod · 0.95

Calls 8

DebugfCtxFunction · 0.92
UDFunction · 0.92
ErrorfMethod · 0.80
BodyBytesMethod · 0.45
GetRevTreeIDMethod · 0.45

Tested by

no test coverage detected