database: reduce pruneLocks/Unlock transaction. #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
pruneLocks could create deadlocked transactions on PostgreSQL if multiple locks expired and pruneLocks is called by multiple instances because Cayley does not guarantee the order.
InsertNotifications and InsertVulnerabilities also insert multiple independent items in a single same transaction. Doing so in InsertNotifications helps because as the transaction only contains new quads, COPY can be used. For the same reason, it could not create a deadlocked transaction. In the other hand, InsertVulnerabilities may delete some fields. However, just like InsertNotifications, it is called from the updater - which run only once per cluster: it could not create a deadlocked transaction. Additionally, the updater relies on the fact that these two functions will fail and rollback entirely if any of the elements can't be inserted (for any reason) - in which case it will not mark the update as done and will redo it later. I believe that because of the reasons above, they should not be modified.