Skip to content

How to query and add atomically? #42

Open

Description

@romanzenka

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?

Activity

  1. lshep commented on Oct 3, 2022

    @lshep
    Contributor

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

  2. romanzenka commented on Oct 17, 2022

    @romanzenka
    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.

  3. hpages commented on Oct 12, 2023

    @hpages
    Contributor

    @romanzenka FYI we're resuming this conversation here.

  4. reopened this on Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions