Skip to content

Rewrite the background queue to not use locks for the insertion#6299

Merged
dtdesign merged 1 commit into6.1from
61-lock-free-background-job
May 22, 2025
Merged

Rewrite the background queue to not use locks for the insertion#6299
dtdesign merged 1 commit into6.1from
61-lock-free-background-job

Conversation

@dtdesign
Copy link
Copy Markdown
Member

The previous approach used a transaction and a write lock on the unique background jobs. This can cause a deadlock in some situations due to a different ordering of jobs.

Further inspection revealed that the transaction only exists for historic reasons to slightly improve the insert performance. The write lock on the job isn’t necessary because at worst the unique job vanishes the moment the job would have been queued which makes no difference.

Filtering out any already queued unique job first allows us to use a lock-free approach to insert the jobs.

See https://www.woltlab.com/community/thread/311983-could-not-execute-statement-insert-into-wcf1-background-job-job-time-identifier/

The previous approach used a transaction and a write lock on the unique background jobs. This can cause a deadlock in some situations due to a different ordering of jobs.

Further inspection revealed that the transaction only exists for historic reasons to slightly improve the insert performance. The write lock on the job isn’t necessary because at worst the unique job vanishes the moment the job would have been queued which makes no difference.

Filtering out any already queued unique job first allows us to use a lock-free approach to insert the jobs.

See https://www.woltlab.com/community/thread/311983-could-not-execute-statement-insert-into-wcf1-background-job-job-time-identifier/
@dtdesign dtdesign requested a review from BurntimeX May 19, 2025 15:59
@dtdesign dtdesign added the Bug label May 19, 2025
@dtdesign dtdesign merged commit 16c8fb5 into 6.1 May 22, 2025
8 checks passed
@dtdesign dtdesign deleted the 61-lock-free-background-job branch May 22, 2025 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants