Skip to content

Fixing locking issues for document type saves.#15854

Merged
kjac merged 18 commits intov10/devfrom
v10/bugfix/locking-issues
Mar 15, 2024
Merged

Fixing locking issues for document type saves.#15854
kjac merged 18 commits intov10/devfrom
v10/bugfix/locking-issues

Conversation

@bergmania
Copy link
Copy Markdown
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
Copy Markdown
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
@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.

2 participants