mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Ludovic Poitou
16.45.2012 55b5528cb49321dc0973de6c42df96e4c39f7523
Fix OPENDJ-471. FIFOEntryCache may leave stalled data on low memory conditions.
Now, when low memory conditions are detected, the FIFOEntryCache removes the previous version of the updated entry if it exists, instead of just removing the first-in entry.
1 files modified
38 ■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/extensions/FIFOEntryCache.java 38 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/extensions/FIFOEntryCache.java
@@ -23,7 +23,7 @@
 *
 *
 *      Copyright 2006-2008 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 *      Portions Copyright 2011-2012 ForgeRock AS
 */
package org.opends.server.extensions;
@@ -347,18 +347,38 @@
      long usedMemory = runtime.totalMemory() - runtime.freeMemory();
      if (usedMemory > maxAllowedMemory)
      {
        Iterator<CacheEntry> iterator = dnMap.values().iterator();
        if (iterator.hasNext())
        CacheEntry cachedEntry = dnMap.remove(entry.getDN());
        if (cachedEntry == null)
        {
          CacheEntry ce = iterator.next();
          iterator.remove();
          HashMap<Long,CacheEntry> m = idMap.get(ce.getBackend());
          if (m != null)
          // The current entry wasn't there, let's remove an existing entry.
          Iterator<CacheEntry> iterator = dnMap.values().iterator();
          if (iterator.hasNext())
          {
            m.remove(ce.getEntryID());
            CacheEntry ce = iterator.next();
            iterator.remove();
            HashMap<Long,CacheEntry> m = idMap.get(ce.getBackend());
            if (m != null)
            {
              m.remove(ce.getEntryID());
            }
          }
        }
        else
        {
          // Try to remove the entry from the ID list as well.
          Map<Long,CacheEntry> map = idMap.get(backend);
          if (map != null)
          {
            map.remove(cacheEntry.getEntryID());
            // If this backend becomes empty now remove it from the idMap map.
            if (map.isEmpty())
            {
              idMap.remove(backend);
            }
          }
        }
      }
      else
      {