Skip to content
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

Gracefully handle unique constraint violations #3648

Conversation

nscuro
Copy link
Member

@nscuro nscuro commented Apr 28, 2024

Description

When uploading many BOMs in bulk, it can happen that vulnerability and repository metadata analysis is performed multiple times for the same component identity in parallel. It is more likely to happen when the BOMs being uploaded have big overlap in terms of components they contain.

This can lead to unique constraint violations when DT updates the COMPONENTANALYSISCACHE table. Occurrences of this are non-critical, and kind of expected. Instead of letting the task crash, simply "accept" the exception and consider the job done.

Note that DataNucleus will log a warning even when we handle the exception.

Addressed Issue

N/A

Additional Details

N/A

Checklist

  • I have read and understand the contributing guidelines
  • This PR fixes a defect, and I have provided tests to verify that the fix is effective
  • This PR implements an enhancement, and I have provided tests to verify that it works as intended
  • This PR introduces changes to the database model, and I have added corresponding update logic
  • This PR introduces new or alters existing behavior, and I have updated the documentation accordingly

@nscuro nscuro added the enhancement New feature or request label Apr 28, 2024
@nscuro nscuro added this to the 4.11 milestone Apr 28, 2024
@nscuro nscuro force-pushed the gracefully-handle-unique-constraint-violations branch from cfed094 to a8d0ba7 Compare April 28, 2024 15:12
Copy link

codacy-production bot commented Apr 28, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.08% (target: -1.00%) 17.65% (target: 70.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (3efdd24) 21982 16463 74.89%
Head commit (9ae124a) 22019 (+37) 16472 (+9) 74.81% (-0.08%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3648) 34 6 17.65%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy will stop sending the deprecated coverage status from June 5th, 2024. Learn more

When uploading many BOMs in bulk, it can happen that vulnerability and repository metadata analysis is performed multiple times for the same component identity in parallel. It is more likely to happen when the BOMs being uploaded have big overlap in terms of components they contain.

This can lead to unique constraint violations when DT updates the `COMPONENTANALYSISCACHE` table. Occurrences of this are non-critical, and kind of expected. Instead of letting the task crash, simply "accept" the exception and consider the job done.

Note that DataNucleus will log a warning even when we handle the exception.

Signed-off-by: nscuro <nscuro@protonmail.com>
@nscuro nscuro force-pushed the gracefully-handle-unique-constraint-violations branch from a8d0ba7 to 9ae124a Compare April 28, 2024 16:21
@nscuro
Copy link
Member Author

nscuro commented Apr 28, 2024

Purposefully not adding tests since the conditions require race conditions in order to be triggered. Such tests have proven to be incredibly flaky. The changes made are low risk.

@nscuro nscuro merged commit 4e90c89 into DependencyTrack:master Apr 28, 2024
10 of 12 checks passed
@nscuro nscuro deleted the gracefully-handle-unique-constraint-violations branch April 28, 2024 19:30
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant