Bioconductor/BiocFileCache

How to query and add atomically?

Opened this issue · 3 comments

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 commented

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

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 commented

@romanzenka FYI we're resuming this conversation here.