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

Fixing locking issues for document type saves. #15854

Merged
merged 18 commits into from Mar 15, 2024
Merged

Conversation

bergmania
Copy link
Member

@bergmania bergmania commented Mar 7, 2024

Description

This PR revert to only use eager locks, to minimize deadlocks.

Further it optimizes what locks are taking when NuCache is rebuilt, and only takes the lock for document, media and members when needed.

The SQL server lock is also optimized to only do one roundtrip to the database per lock instead of two.

Finally, the Sqlite lock did not call the OnExecutedCommand methods so was only passing a test by luck (A SqlCount was only 0 because it was never increased with the used command). This is not fixed by adding a new method on the IUmbracoDatabase with a default implementation, to avoid breaking changes.

I really hope this is the root cause to #14195 🙈

Test

Things should still work, but one way to test it, is to load test the endpoints. This can quite easily be done by using the keyboard shortcuts in backoffice to save many times if you hold the short cuts down for like 30 sec.

Interesting things to test

  • Load test Document Type Save
  • Load test Media Type Save
  • Load test Member Type Save
  • Load test Document Save

All tests needs to be done both with SqlServer and SQLite.

Appendix

Document Type updates before this PR

Screen.Recording.2024-03-15.at.09.29.07.mov

Document Type updates after this PR

Screen.Recording.2024-03-15.at.09.21.05.mov

Document updates after this PR

Screen.Recording.2024-03-15.at.09.24.08.mov

Copy link
Contributor

@kjac kjac left a comment

Choose a reason for hiding this comment

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

This rocks 💪

@kjac kjac merged commit 2c23e67 into v10/dev Mar 15, 2024
15 checks passed
@kjac kjac deleted the v10/bugfix/locking-issues branch March 15, 2024 09:56
bergmania added a commit that referenced this pull request Mar 15, 2024
* Added  ExecuteNonQuery(DbCommand command) on database to ensure we call OnExecutingCommand and OnExecutedCommand when executing DbCommands

* Added Cache Instructions lock, to avoid deadlocks

* Optimized read locks for nucache when only one content type is rebuilt

* Optimized the SqlServer locks, so only one command is executed (and thereby roundtrip) per lock instead of two

* Avoid breaking changes

* Cosmetic changes

* Take locks if everything is rebuild

* Use same lock in scopes, to avoid potential deadlocks between the two

* Use eager locks in PublishedSnapshotService.cs

* Added timeouts to some of the application locks

* Revert "Use eager locks in PublishedSnapshotService.cs"

This reverts commit 01873aa.

* Revert "Added Cache Instructions lock, to avoid deadlocks"

This reverts commit e3fca7c.

* Use single readlock call to lock many

* Use eager locks for reads

* Eager write locks

* Ignore test of lazy locks

* Unique timeout exception messages

---------

Co-authored-by: kjac <kja@umbraco.dk>
(cherry picked from commit 2c23e67)
bergmania added a commit that referenced this pull request Mar 18, 2024
* Added  ExecuteNonQuery(DbCommand command) on database to ensure we call OnExecutingCommand and OnExecutedCommand when executing DbCommands

* Added Cache Instructions lock, to avoid deadlocks

* Optimized read locks for nucache when only one content type is rebuilt

* Optimized the SqlServer locks, so only one command is executed (and thereby roundtrip) per lock instead of two

* Avoid breaking changes

* Cosmetic changes

* Take locks if everything is rebuild

* Use same lock in scopes, to avoid potential deadlocks between the two

* Use eager locks in PublishedSnapshotService.cs

* Added timeouts to some of the application locks

* Revert "Use eager locks in PublishedSnapshotService.cs"

This reverts commit 01873aa.

* Revert "Added Cache Instructions lock, to avoid deadlocks"

This reverts commit e3fca7c.

* Use single readlock call to lock many

* Use eager locks for reads

* Eager write locks

* Ignore test of lazy locks

* Unique timeout exception messages

---------

Co-authored-by: kjac <kja@umbraco.dk>

(cherry picked from commit 2c23e67)
bergmania added a commit that referenced this pull request Mar 18, 2024
* Added  ExecuteNonQuery(DbCommand command) on database to ensure we call OnExecutingCommand and OnExecutedCommand when executing DbCommands

* Added Cache Instructions lock, to avoid deadlocks

* Optimized read locks for nucache when only one content type is rebuilt

* Optimized the SqlServer locks, so only one command is executed (and thereby roundtrip) per lock instead of two

* Avoid breaking changes

* Cosmetic changes

* Take locks if everything is rebuild

* Use same lock in scopes, to avoid potential deadlocks between the two

* Use eager locks in PublishedSnapshotService.cs

* Added timeouts to some of the application locks

* Revert "Use eager locks in PublishedSnapshotService.cs"

This reverts commit 01873aa.

* Revert "Added Cache Instructions lock, to avoid deadlocks"

This reverts commit e3fca7c.

* Use single readlock call to lock many

* Use eager locks for reads

* Eager write locks

* Ignore test of lazy locks

* Unique timeout exception messages

---------

Co-authored-by: kjac <kja@umbraco.dk>

(cherry picked from commit 2c23e67)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants