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)
| 2013 | // revision. This will be addressed post-Hydrogen with version vector work, but additional analysis |
| 2014 | // of options for Hydrogen should be completed. |
| 2015 | func (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 |
no test coverage detected