3 Replies Latest reply on Apr 16, 2012 5:06 AM by galder.zamarreno

    Is possible to get negative count of cache entry

    dex80526

      Hi, all:

      I am wondering if possible a cache returns a negative number for number of cache entries.

      For example, in the following code, is possible the count negative?

       

      int count = cache.size();

       

      Can I assume the size() never return negative value in any configurations?

       

      Other questions: how does infinispan keep the count of the size of a cache?  is there any performance penality if I call cache.size() operation periodically?

        • 1. Re: Is possible to get negative count of cache entry
          matlach

          Hi dex,

           

          Have a look at the SizeCommand implementation :

           

          org.infinispan.commands.read

          public class SizeCommand extends AbstractLocalCommand implements VisitableCommand {
          
          
             @Override
             public Integer perform(InvocationContext ctx) throws Throwable {
                if (noTxModifications(ctx)) {
                   return container.size();
                }
          
                int size = container.size();
                for (CacheEntry e: ctx.getLookedUpEntries().values()) {
                   if (e.isCreated()) {
                      size ++;
                   } else  if (e.isRemoved()) {
                      size --;
                   }
                }
          
                return Math.max(size, 0);
             }
          }
          
          

           

          It's definitely impossible to obtain a negative value.

           

          For the performance impact, by reading the code I'm having trouble figuring it out since the size command is replicated across the cluster since it's flagged by both LocalCommand and VisitableCommand (thus ReplicableCommand).

           

          Guess a small breakpoint here in debug and you'll find really soon

          • 2. Re: Is possible to get negative count of cache entry
            dex80526

            thanks for the response. I'll do a debug session as you suggested.

            • 3. Re: Is possible to get negative count of cache entry
              galder.zamarreno

              Thx Mathieu for helping out!