Hot Rod's putIfAbsent might have issues on some edge cases:
I want to know whether the putting entry already exists in the remote
cache cluster, or not.I thought that RemoteCache.putIfAbsent() would be useful for that
purpose, i.e.,if (remoteCache.putIfAbsent(k,v) == null) { // new entry. } else { // k already exists. }But no.
The putIfAbsent() for new entry may return non-null value, if one of the
server crushed while putting.
The behavior is like the following:1. Client do putIfAbsent(k,v).
2. The server receives the request and sends replication requests to
other servers. If the server crushed before completing replication, some
servers own that (k,v), but others not.
3. Client receives the error. The putIfAbsent() internally retries the
same request to the next server in the cluster server list.
4. If the next server owns the (k,v), the putIfAbsent() returns the
replicated (k,v) at the step 2, without any error.So, putIfAbsent() is not reliable for knowing whether the putting entry
is exactly new or not.Does anyone have any idea/workaround for this purpose?
A workaround is to do this:
We got a simple solution, which can be applied to our customer's application.
If each value part of putting (k,v) is unique or contains unique value,
the client can do double check wether the entry is new.val = System.nanoTime(); // or uuid is also useful. if ((ret = cache.putIfAbsent(key, val)) == null || ret.equals(val)) { // new entry, if the return value is just the same. } else { // key already exists. }We are proposing this workaround which almost works fine.
However, this is a bit of a cludge.
Hot Rod should be improved with an operation that allows a version to be passed when entry is created, instead of relying on the client generating it.
- blocks
-
ISPN-3533 Design HotRod protocol version 2.0
- Closed
- is related to
-
ISPN-4286 Two concurrent putIfAbsent operations can both return null during rebalance
- Closed
-
ISPN-3918 Inconsistent view of the cache with putIfAbsent in a non-tx cache during state transfer
- Closed
- relates to
-
ISPN-5130 Conditional operation warning should only appear for clustered caches
- Closed
-
ISPN-5129 Add a clustered transactional cache example for Infinispan Server
- Closed
-
ISPN-4795 Warning message about forcing to return previous does not apply to Get operations
- Closed
-
ISPN-5691 Server should enable writeSkew for some configurations by default
- Closed