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

How to query and add atomically? #42

Open
romanzenka opened this issue Sep 30, 2022 · 3 comments
Open

How to query and add atomically? #42

romanzenka opened this issue Sep 30, 2022 · 3 comments

Comments

@romanzenka
Copy link

I could not find an API which would do the following:

  1. start transaction
  2. bfcquery for resource X
  3. if absent, bfcadd X
  4. end transaction

I am afraid that I will run into race condition if two processes both query, both get negative result, then they both add at once.

Is there a way to remove a possibility of such a race condition?

@lshep
Copy link
Contributor

lshep commented Oct 3, 2022

There is a built in locking system on the cache that should prevent this.

@lshep lshep closed this as completed Oct 3, 2022
@romanzenka
Copy link
Author

Someone needs to tell the cache that two separate operations are to be performed atomically. If you rely on the write lock on SQLite, this issue still remains, as the write lock will not trigger during the query operation (it is read-only), allowing two separate processes to both simultaneously create and try to add a non-existing resource... I'll see how I can work around it.

@hpages
Copy link
Contributor

hpages commented Oct 12, 2023

@romanzenka FYI we're resuming this conversation here.

@lshep lshep reopened this Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants