Skip to content

Commit b8b689b

Browse files
authored
CBG-4923: Prevent Excessive conflict logging in PutCurrentVersion (#7865)
1 parent 29a24be commit b8b689b

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

db/crud.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

db/document.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,17 +1486,25 @@ func (doc *Document) ExtractDocVersion() DocVersion {
14861486
}
14871487

14881488
// IsInConflict is true if the incoming HLV is in conflict with the current document.
1489-
func (doc *Document) IsInConflict(ctx context.Context, db *DatabaseCollectionWithUser, incomingHLV *HybridLogicalVector, putOpts PutDocOptions) HLVConflictStatus {
1489+
func (doc *Document) IsInConflict(ctx context.Context, db *DatabaseCollectionWithUser, incomingHLV *HybridLogicalVector, putOpts PutDocOptions, revTreeConflictCheck, revTreeConflictCheckStatus bool) HLVConflictStatus {
14901490
// If there is no SyncData, then the document can not be in conflict.
14911491
if doc.SyncData.Sequence == 0 {
14921492
return HLVNoConflict
14931493

14941494
}
14951495
// we need to check if local CV version was generated from a revID if so we need to perform conflict check on rev tree history
14961496
if doc.HLV.HasRevEncodedCV() {
1497-
_, _, isConflictErr := db.revTreeConflictCheck(ctx, putOpts.RevTreeHistory, doc, putOpts.NewDoc.Deleted)
1498-
if isConflictErr != nil {
1499-
return HLVConflict
1497+
if revTreeConflictCheck {
1498+
if revTreeConflictCheckStatus {
1499+
return HLVConflict
1500+
} else {
1501+
return HLVNoConflict
1502+
}
1503+
} else {
1504+
_, _, isConflictErr := db.revTreeConflictCheck(ctx, putOpts.RevTreeHistory, doc, putOpts.NewDoc.Deleted)
1505+
if isConflictErr != nil {
1506+
return HLVConflict
1507+
}
15001508
}
15011509
return HLVNoConflict
15021510
}

0 commit comments

Comments
 (0)