2 Replies Latest reply on Mar 30, 2015 4:20 AM by yairogen

    Pessimistic Locking and dirty reads

    yairogen

      I am using Infinispan 7.1.1.

       

      When using transactions with thw wrote lock flag:

       

      cache.getAdvancedCache.withFlags(Flag.FORCE_WRITE_LOCK).get(id)
      

       

      How do we handle dirty reads? I.w. assume 2 threads reading the data with write flag, how do we correlate the changes so that once first thread updates the cache the other won't simply override the new cache with it's own value? I want to other thread to know it's data is dirty and allow it to see the other updated entry?

       

      Or maybe FORCE_WRITE_LOCK is not what I should use?

        • 1. Re: Pessimistic Locking and dirty reads
          rvansa

          With this flag, once you read the data it stays locked until the transaction in which you read the data commits. Therefore, processing of the second transaction is blocked. Naturally, this works only with pessimistic locking.

           

          With optimistic locking, we remember version of entry read and when (and only if) the same transaction later updates this entry, it checks that it's updating the same version as was read. If another transaction modified the data in between, the transaction rollbacks. This is called write skew check.

          • 2. Re: Pessimistic Locking and dirty reads
            yairogen

            Naturally, the locks are only for the same key, right?