Atomic select/delete

Posts   
 
    
jlew
User
Posts: 3
Joined: 25-Aug-2009
# Posted on: 09-Dec-2009 21:03:08   

I have a db table being used to cache pre-calculated data. My code wants to be able to "extract" (i.e. select and delete) a row so that no two competing threads/processes can extract the same row. The existing code performs an entity fetch followed by an entity delete within a transaction, but this doesn't seem to guarantee lock out reads of the same from other threads, and it sometimes ends up with the same value having been extracted twice. Any idea why, or how to implement a pattern like this in LLBLGEN?

LLBLGEN PRO 2.6 Adapter Model

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Dec-2009 05:15:27   

Hi there,

What you are looking for is Concurrency Control. You can add this control for deletes and saves. So, you add a field (normally a timestamp) to ensure you don't delete a row some other thread has taken.

In your case I think you should do it in two stages:

  1. Update the entity field to a new timestamp (or guid).

  2. When you delete it, you must add concurrency control with the timestamp (or guid) field to ensure no one else has already take it.

David Elizondo | LLBLGen Support Team