Repository navigation
Conversation
Below about 25,000 datasets and collections, PostgreSQL ran the storage use update as a scan of the whole table and locked the rows in table order. Concurrent uploads into one collection could take the locks in opposite order and deadlock.
Member
|
@akeldamas thanks for the pull request! We've been too busy to look at it closely but we will! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this PR does / why we need it:
Locks the storage use rows of a dataset and its parent collections in order of id before updating them. Below about 25,000 datasets and collections, PostgreSQL ran the update as a scan of the whole table and locked the rows in the order in which it found them. Concurrent uploads into one collection could take the locks in opposite order, deadlock and fail.
Which issue(s) this PR closes:
Special notes for your reviewer:
The change is one statement in
StorageUseServiceBean.incrementStorageSizeRecursively. AMATERIALIZEDCTE selects the rows withORDER BY storageuse.id FOR UPDATE OF storageuse, and the update joins on it.EXPLAINshowsLockRowsaboveSort, so the locks are taken in order of id whichever join the planner picks.On a large table, where the old statement already locked child before parent, the extra lookup costs some throughput of the statement itself: 3,415 against 4,302 updates a second in one
pgbenchrun with 64 clients, about 0.06 ms per update.Suggestions on how to test this:
FilesIT#testCollectionStorageQuotasandFilesIT#testDatasetStorageQuotascheck the recorded storage use and pass.pgbenchreproduction from the issue, on a tree of 2,000 datasets, 30% to 43% of the updates of the old statement fail on a deadlock. The new statement has no deadlock failures.Does this PR introduce a user interface change? If mockups are available, please link/include them here:
No.
Is there a release notes update needed for this change?:
Yes,
doc/release-notes/storage-use-lock-order.md.Additional documentation:
None.