-
1. Re: Inifinispan : add pessimistic read lock
rvansa Aug 20, 2018 8:06 AM (in response to oqpwcf2)Short answer: No.
Long answer: In pessimistic tx cache you can do cache.getAdvancedCache().withFlags(Flag.FORCE_WRITE_LOCK) but that won't work as you'd expect. Since reads don't visit all owners (these are satisfied by any owner) this would lock just some nodes and you could be in trouble. It would work only in distributed mode with single owner (or at least I *think* it would work).
If you really need to lock the entry, you could read it and conditionally replace it (and verify that the replace succeeded). Writes will acquire those locks. Or you can go for optimistic locking and let the transaction fail with write skew if the entry gets changed.
Could you describe your use case?
-
2. Re: Inifinispan : add pessimistic read lock
oqpwcf2 Aug 28, 2018 3:54 AM (in response to rvansa)Hi Radim
Thank you for your response,
we need to ensure that a entry could only get once, so kind of "read lock".
-
3. Re: Inifinispan : add pessimistic read lock
rvansa Sep 3, 2018 10:13 AM (in response to oqpwcf2)In transaction with REPEATABLE_READ isolation level (default since Infinispan 9 or so) you store all read entries in a transaction context (imagine 1st level cache/session cache in JPA world), therefore you couldn't read two different values in one transaction even if it's modified by another transaction in the meantime.