10 Replies Latest reply on Aug 11, 2010 12:11 PM by manik

    concurrency & transactions question

    ksobolev

      Hi

      I'm looking for a way to use transactional cache together with transactional DB, and I'm intersted in how to resolve the following race condition.

      Suppose we have 2 threads, T1 and T2, some key K and corresponding value V, which reflects DB data.

      1. T1.tx.begin(); T1 is about to change state in DB
      2. T2 (no tx context): cache.get(K) --> miss
      3. T2: V1 = DB.read; (reads 'old' state)
      4. T1: DB.write(V2)
      5. T1: cache.put(K,V2)
      6. T1: tx.commit()
      7. T2: cache.put(K,V1)

       

      Result: DB contains V2, cache contains V1

      Does Infinispan provide anything to fix it? (Explicit locking?)

       

      Thanks