-
Notifications
You must be signed in to change notification settings - Fork 140
CBG-4806: move conflict detection to common function #7683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
48b879d
8bcf2b7
954d5a5
fe8e72d
4feffe7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,7 +16,6 @@ import ( | |||||
"encoding/base64" | ||||||
"fmt" | ||||||
"iter" | ||||||
"maps" | ||||||
"net/http" | ||||||
"slices" | ||||||
"strconv" | ||||||
|
@@ -325,35 +324,16 @@ func (cd *clientDoc) _hasConflict(t testing.TB, incomingHLV *db.HybridLogicalVec | |||||
incomingCV := incomingHLV.ExtractCurrentVersionFromHLV() | ||||||
localCV := localHLV.ExtractCurrentVersionFromHLV() | ||||||
// safety check - ensure SG is not sending a rev that we already had - ensures changes feed messaging is working correctly to prevent | ||||||
// this check is also performed in the function below but we should keep this here for extra context on FailNow call | ||||||
if localCV.Equal(*incomingCV) { | ||||||
require.FailNow(t, fmt.Sprintf("incoming CV %#+v is equal to local revision %#+v - this should've been filtered via changes response before ending up as a rev. This is only true if there is a single replication occurring, two simultaneous replications (e.g. P2P) could cause this. If there are multiple replications, modify code.", incomingCV, latestRev)) | ||||||
} | ||||||
// standard no conflict case. In the simple case, this happens when: | ||||||
// - SG writes document 1@cbs1 | ||||||
// - CBL pulls document 1@cbs1 | ||||||
// - SG writes document 2@cbs1 | ||||||
if incomingHLV.DominatesSource(*localCV) { | ||||||
return false | ||||||
} | ||||||
|
||||||
// local revision is newer than incoming revision. Common case: | ||||||
// - CBL writes document 1@cbl1 | ||||||
// - CBL pushes to SG as 1@cbl1 | ||||||
// - CBL pulls document 1@cbl1 | ||||||
// | ||||||
// NOTE: without P2P replication, this should not be the case and we would not get this revision, since CBL | ||||||
// would respond to a SG changes message that CBL does not need this revision | ||||||
if localHLV.DominatesSource(*incomingCV) { | ||||||
inConflict, err := db.IsInConflict(t.Context(), &localHLV, incomingHLV) | ||||||
if err != nil { | ||||||
require.FailNow(t, fmt.Sprintf("incoming CV %#+v has lower version than the local revision %#+v - this should've been filtered via changes response before ending up as a rev. blip tester would reply that to Sync Gateway that it doesn't need this revision", incomingCV, localHLV)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error handling logic is incorrect. The FailNow call with the 'lower version' message is triggered when any error occurs from IsInConflict, but according to the new function, errors can occur for multiple reasons including equal CVs or newer local versions. The error message should be updated to reflect the actual error or the error should be properly differentiated.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will leave this as is given the extra context in original message. |
||||||
return false | ||||||
} | ||||||
// Check if conflict has been previously resolved. | ||||||
// - If merge versions are empty, then it has not be resolved. | ||||||
// - If merge versions do not match, then it has not been resolved. | ||||||
if len(incomingHLV.MergeVersions) != 0 && len(localHLV.MergeVersions) != 0 && maps.Equal(incomingHLV.MergeVersions, localHLV.MergeVersions) { | ||||||
return false | ||||||
} | ||||||
return true | ||||||
return inConflict | ||||||
} | ||||||
|
||||||
func (btcc *BlipTesterCollectionClient) _resolveConflict(incomingHLV *db.HybridLogicalVector, incomingBody []byte, localDoc *clientDocRev) (body []byte, hlv db.HybridLogicalVector) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally like %#+v for logging, but I think %#v might be better for HLV and CV since it displays versions in decimal instead of a hexadecimal.
Can you check this? If this is true, can you file a ticket to create a
ruleguard
rule so that we can detect this for the future?If not, disregard this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It only seems to wrap the formatted bit into quotes.
Internally we handle the HLV in uint64 type so logging here for example should be fine although %#v seems to format a uint64 into hex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth filing a ticket to evaluate the places we log this and make sure we don't log in hex, it just makes everything harder to handle. But I can assert https://github.com/couchbaselabs/sg_dev_tools/pull/37 will handle this too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jira.issues.couchbase.com/browse/CBG-4811