Skip to content

Conversation

@bbrks
Copy link
Member

@bbrks bbrks commented Dec 1, 2025

CBG-5035

Unclean (please double-check) cherry-pick of #7903 for 3.3.2

Conflicts mostly around CV handling

Integration Tests

@bbrks bbrks requested review from adamcfraser and Copilot December 1, 2025 18:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements a locking mechanism to synchronize delta generation for the same revision across multiple concurrent clients. The change prevents redundant delta computations when multiple clients simultaneously request the same delta by introducing a per-revision cache value lock.

Key changes:

  • Added a deltaLock mutex to revCacheValue to synchronize delta generation per fromRevision
  • Refactored GetDelta to acquire the lock before delta generation and check for cached results
  • Added comprehensive tests and benchmarks to validate concurrent delta generation behavior

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
db/revision_cache_lru.go Adds deltaLock mutex to revCacheValue struct and passes it to DocumentRevision
db/revision_cache_interface.go Adds RevCacheValueDeltaLock field to DocumentRevision struct
db/crud.go Refactors GetDelta to use the new lock for synchronized delta generation with double-check pattern
db/database_test.go Adds test and benchmarks for concurrent delta sync cache population scenarios

if fromRevision.Delta != nil {
if fromRevision.Delta.ToRevID == toRevID {
if initialFromRevision.BodyBytes != nil {
// Acquire a delta lock to generate delta (ensuring only one toRev unmarshalling/diff for this fromRev and allow racing clients to share the result)
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'unmarshalling' to 'unmarshaling' to match Go conventions.

Suggested change
// Acquire a delta lock to generate delta (ensuring only one toRev unmarshalling/diff for this fromRev and allow racing clients to share the result)
// Acquire a delta lock to generate delta (ensuring only one toRev unmarshaling/diff for this fromRev and allow racing clients to share the result)

Copilot uses AI. Check for mistakes.
}

// We didn't unmarshal fromBody earlier (in case we could get by with just the delta), so need do it now
// We didn't unmarshal fromBody earlier (in case we could get by with just the delta), so need do it now.
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing 'to' in 'need do it now' should be 'need to do it now'.

Copilot uses AI. Check for mistakes.
}

// We didn't unmarshal toBody earlier (in case we could get by with just the delta), so need do it now
// We didn't unmarshal toBody earlier (in case we could get by with just the delta), so need do it now.
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing 'to' in 'need do it now' should be 'need to do it now'.

Copilot uses AI. Check for mistakes.
Comment on lines +722 to +725
//{
// name: "5MBDoc",
// docSize: 5 * 1024 * 1024,
//},
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented-out test case or add a comment explaining why it's disabled.

Copilot uses AI. Check for mistakes.
@bbrks
Copy link
Member Author

bbrks commented Dec 1, 2025

TestDeltaSyncWhenFromRevIsChannelRemoval is failing due to this change... Not sure why yet.

@bbrks
Copy link
Member Author

bbrks commented Dec 1, 2025

I think the 4.x version of GetDelta is returning err from the initial revcache value operation, whereas the 3.x version of the code does nil checks to return err (which is now removed as part of the cherry pick)

@adamcfraser adamcfraser merged commit 6ed11ec into release/3.3.2 Dec 1, 2025
44 checks passed
@adamcfraser adamcfraser deleted the CBG-5035 branch December 1, 2025 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants