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

chore(server): refactor locks #5953

Merged
merged 8 commits into from
Dec 27, 2023
Merged

chore(server): refactor locks #5953

merged 8 commits into from
Dec 27, 2023

Conversation

mertalev
Copy link
Contributor

Description

This PR moves locking functionality to the new database repository. Specifically, it adds three methods and replaces existing lock usages with them:

  • withLock takes a lock type and an async callback and acquires an async lock as well as a Postgres advisory lock. It wraps the callback in a try / finally clause that ensures the advisory lock is released.
  • isBusy is a synchronous check to see if a lock is being used without actually acquiring it
  • wait asynchronously waits for the lock to be released by acquiring and immediately releasing it
    • It is more lightweight than withLock for this purpose as it only relies on the async lock, not a Postgres advisory lock

How Has This Been Tested?

The server booted, running a Smart Search job worked, and changing the CLIP model while jobs were running had the same behavior (i.e. the active jobs waited for the update to complete, then errored because they had different size embeddings, while later jobs completed successfully).

Copy link

cloudflare-pages bot commented Dec 23, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: b94b59e
Status: ✅  Deploy successful!
Preview URL: https://03445fae.immich.pages.dev
Branch Preview URL: https://chore-refactor-locks.immich.pages.dev

View logs

@mertalev mertalev merged commit 8119d4b into main Dec 27, 2023
20 checks passed
@mertalev mertalev deleted the chore/refactor-locks branch December 27, 2023 23:36
martabal pushed a commit that referenced this pull request Jan 9, 2024
* lock refactor

* add mocks

* add await

* move database repo injection to service

* update tests

* add mock implementation

* remove unused imports

* this
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