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

Avoid constantly attempting to acquire a lock #491

Merged
merged 1 commit into from
Sep 16, 2024
Merged

Conversation

ddaspit
Copy link
Contributor

@ddaspit ddaspit commented Sep 13, 2024

  • ignore expiration timeout on WaitForChangesAsync when there are queued writer locks

This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented Sep 13, 2024

Codecov Report

Attention: Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.

Project coverage is 57.06%. Comparing base (8c5f802) to head (80f4c6e).

Files with missing lines Patch % Lines
...ine.Shared/Services/DistributedReaderWriterLock.cs 76.92% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #491   +/-   ##
=======================================
  Coverage   57.05%   57.06%           
=======================================
  Files         277      277           
  Lines       14165    14168    +3     
  Branches     1901     1902    +1     
=======================================
+ Hits         8082     8085    +3     
  Misses       5495     5495           
  Partials      588      588           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ddaspit ddaspit mentioned this pull request Sep 14, 2024
@johnml1135
Copy link
Collaborator

This appears to prevent the infinite cycling. Still, if there is an expired writer on the queue (with a different lock Id), it will never be cleared away. Such could happen if the database is inaccessible when trying to remove the lock.

I see that you don't put any ExpiresAt on the WriterQueue, leaving it null - they will hold forever (unless there is something else that causes it to crash out). Would this be plausible for the WriterQueue?

  • Have a timeout refresh interval of 10 seconds
  • Set the ExpiresAt interval to 31 seconds
  • Every time we try to acquire the writer lock and fail, we upsert the queued item with a new ExpiresAt time (31 seconds later)
  • When we want to check for nothing queued, we look for non-expired items in the WriterQueue.

Is that overkill? Should we try for this fix and see if it resolves it?

Copy link
Collaborator

@johnml1135 johnml1135 left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ddaspit)

Copy link
Contributor Author

@ddaspit ddaspit left a comment

Choose a reason for hiding this comment

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

There are circumstances where the writer queue doesn't get cleared properly. Your proposed solution would definitely work. It would result in extra queries/updates to the database. We would be trying to acquire the lock every 10 seconds instead of waiting until the currently acquired lock expired. Also, we would need to do an extra update for the ExpiresAt property. Another option would be to add a timeout when attempting to acquire a lock. The timeout value could be used to set the ExpiresAt property for the writer queue entry. If we want to deal with this possible case, we can do it in another PR.

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ddaspit)

@johnml1135
Copy link
Collaborator

Sure.

- ignore expiration timeout on WaitForChangesAsync when there are queued writer locks
@johnml1135 johnml1135 merged commit 19f6f95 into main Sep 16, 2024
3 checks passed
@ddaspit ddaspit deleted the acquire-lock-spike branch September 16, 2024 23:06
@Nateowami Nateowami added the sf_watching Scripture Forge should be updated when this is resolved or updated label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sf_watching Scripture Forge should be updated when this is resolved or updated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants