@@ -1337,10 +1337,15 @@ func (db *DatabaseCollectionWithUser) PutExistingCurrentVersion(ctx context.Cont
13371337 // 2. local doc has no hlv
13381338 allowConflictingTombstone := opts .ForceAllowConflictingTombstone && doc .IsDeleted ()
13391339
1340+ // variables to keep track if there was rev tree conflict check and storing the status of the check
1341+ revTreeConflictChecked := false
1342+ revTreeConflictCheckStatus := false
1343+
13401344 // if local doc is a pre-upgraded mutation and the rev tree is conflicting with incoming, assign this local
13411345 // version an implicit hlv based on its rev tree ID + this nodes sourceID to allow HLV conflict resolution to occur
13421346 // between the two versions.
13431347 if doc .HLV == nil && doc .Cas != 0 && ! allowConflictingTombstone {
1348+ revTreeConflictChecked = true
13441349 _ , _ , conflictErr := db .revTreeConflictCheck (ctx , opts .RevTreeHistory , doc , opts .NewDoc .Deleted )
13451350 if conflictErr != nil {
13461351 // conflict detected between incoming rev and local rev revtrees, allow hlv conflict resolvers
@@ -1349,6 +1354,7 @@ func (db *DatabaseCollectionWithUser) PutExistingCurrentVersion(ctx context.Cont
13491354 if err != nil {
13501355 return nil , nil , false , nil , err
13511356 }
1357+ revTreeConflictCheckStatus = true
13521358 base .DebugfCtx (ctx , base .KeyVV , "No existing HLV for existing doc %s, generated implicit CV from rev tree id, updated CV %#v" , base .UD (doc .ID ), doc .HLV .ExtractCurrentVersionFromHLV ())
13531359 }
13541360 }
@@ -1366,7 +1372,7 @@ func (db *DatabaseCollectionWithUser) PutExistingCurrentVersion(ctx context.Cont
13661372 }
13671373 }
13681374 } else {
1369- conflictStatus := doc .IsInConflict (ctx , db , opts .NewDocHLV , opts )
1375+ conflictStatus := doc .IsInConflict (ctx , db , opts .NewDocHLV , opts , revTreeConflictChecked , revTreeConflictCheckStatus )
13701376 switch conflictStatus {
13711377 case HLVNoConflictRevAlreadyPresent :
13721378 base .DebugfCtx (ctx , base .KeyCRUD , "PutExistingCurrentVersion(%q): No new versions to add. existing: %#v new:%#v" , base .UD (opts .NewDoc .ID ), doc .HLV , opts .NewDocHLV )
@@ -1391,11 +1397,17 @@ func (db *DatabaseCollectionWithUser) PutExistingCurrentVersion(ctx context.Cont
13911397 case HLVConflict :
13921398 // if we have been supplied a rev tree from cbl, perform conflict check on rev tree history
13931399 if len (opts .RevTreeHistory ) > 0 && ! opts .ISGRWrite {
1400+ if revTreeConflictChecked && revTreeConflictCheckStatus {
1401+ base .DebugfCtx (ctx , base .KeyCRUD , "conflict detected between the two HLV's for doc %s, and conflict found in rev tree history" , base .UD (doc .ID ))
1402+ return nil , nil , false , nil , base .HTTPErrorf (http .StatusConflict , "Document revision conflict" )
1403+ }
1404+
13941405 parent , currentRevIndex , err := db .revTreeConflictCheck (ctx , opts .RevTreeHistory , doc , opts .NewDoc .Deleted )
13951406 if err != nil {
13961407 base .DebugfCtx (ctx , base .KeyCRUD , "conflict detected between the two HLV's for doc %s, and conflict found in rev tree history" , base .UD (doc .ID ))
13971408 return nil , nil , false , nil , err
13981409 }
1410+
13991411 _ , err = doc .addNewerRevisionsToRevTreeHistory (opts .NewDoc , currentRevIndex , parent , opts .RevTreeHistory )
14001412 if err != nil {
14011413 return nil , nil , false , nil , err
0 commit comments