[infinispan-dev] Key set, value set and size within transaction

Manik Surtani manik at jboss.org
Thu Oct 21 09:55:50 EDT 2010


Guys

I just noticed this in the codebase:

http://fisheye.jboss.org/browse/Infinispan/branches/4.2.x/core/src/main/java/org/infinispan/commands/read/AbstractLocalCommand.java?r=2518#l43

This seems to have come in as a part of changeset 2518 - http://fisheye.jboss.org/changelog/Infinispan/?cs=2518 - for ISPN-679 (Cache.values does not work correctly).

Please be careful when doing stuff like this - the new method added to AbstractLocalCommand effectively creates a new collection the size of the entire data container and loads it with (almost) all keys.  An Infinispan node running close to capacity will almost certainly die with an OOM if you do this.  It will even OOM if you are not necessarily close to capacity (under half your heap used) and you have > 1 thread concurrently invoking this method.  

I presume this is to make Cache.keySet(), Cache.values() and Cache.size() transactionally accurate, but remember that this comes at a huge cost.  Which is why we chose to go with a best-effort approach.  See Javadocs on Cache [1].  The relevant bit states:

"Other methods such as Map.size() provide an approximation-only, and should not be relied on for an accurate picture as to the size of the entire, distributed cache. Remote nodes are not queried and in-fly transactions are not taken into account, even if Map.size() is invoked from within such a transaction."

Could we please discuss why we have added this?

Cheers
Manik

[1] http://docs.jboss.org/infinispan/4.2/apidocs/org/infinispan/Cache.html
--
Manik Surtani
manik at jboss.org
Lead, Infinispan
Lead, JBoss Cache
http://www.infinispan.org
http://www.jbosscache.org







More information about the infinispan-dev mailing list