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

dugan
14.35.2009 1ad16ad47d3a692e66c4b98e302d96dbcbd0d10e
Fix for thread time out problem.Issue 4280
2 files modified
79 ■■■■ changed files
opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java 34 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/backends/jeb/importLDIF/Suffix.java 45 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
@@ -1333,7 +1333,7 @@
          EntryContainer entryContainer = suffix.getEntryContainer();
          for (DN dn = entryContainer.getParentWithinBase(parentDN); dn != null;
               dn = entryContainer.getParentWithinBase(dn)) {
            if((nodeID =  getAncestorID(dn2id, dn)) == null) {
            if((nodeID =  suffix.getParentID(dn)) == null) {
              return false;
            } else {
              IDs.add(nodeID);
@@ -1372,38 +1372,6 @@
      id2subtree.insert(idSubSet, subTreeKeySet, dbSubKey, dbSubVal);
    }
    EntryID getAncestorID(DN2ID dn2id, DN dn)
            throws DatabaseException
    {
      int i=0;
      EntryID nodeID = dn2id.get(null, dn, LockMode.DEFAULT);
      if(nodeID == null) {
        while((nodeID = dn2id.get(null, dn, LockMode.DEFAULT)) == null) {
          try {
            Thread.sleep(50);
            if(i == 10) {
               //Temporary messages until this code is cleaned up.
               Message message =
                   Message.raw(Category.JEB, Severity.SEVERE_ERROR,
                    "ancestorID check failed");
              logError(message);
              return null;
            }
            i++;
          } catch (Exception e) {
               //Temporary messages until this code is cleaned up.
               Message message =
                 Message.raw(Category.JEB, Severity.SEVERE_ERROR,
                "ancestorID exception thrown");
              logError(message);
            return null;
          }
        }
      }
      return nodeID;
    }
    void
    processIndexes(Suffix suffix, Entry entry, EntryID entryID) throws
opends/src/server/org/opends/server/backends/jeb/importLDIF/Suffix.java
@@ -29,6 +29,8 @@
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import org.opends.server.backends.jeb.*;
import org.opends.server.config.ConfigException;
import org.opends.server.types.*;
@@ -53,9 +55,8 @@
  private EntryContainer entryContainer;
  private final Object synchObject = new Object();
  private static final int PARENT_ID_MAP_SIZE = 4096;
  private ConcurrentHashMap<DN,DN> pendingMap =
                      new ConcurrentHashMap<DN, DN>() ;
  private ConcurrentHashMap<DN, CountDownLatch> pendingMap =
                                    new ConcurrentHashMap<DN, CountDownLatch>();
  private HashMap<DN,EntryID> parentIDMap =
    new HashMap<DN,EntryID>(PARENT_ID_MAP_SIZE);
@@ -172,15 +173,14 @@
   * Check if the parent DN is in the pending map.
   *
   * @param parentDN The DN of the parent.
   * @return <CODE>True</CODE> if the parent is in the pending map.
   */
  private boolean isPending(DN parentDN)
  private void checkPending(DN parentDN)  throws InterruptedException
  {
    boolean ret = false;
    if(pendingMap.containsKey(parentDN)) {
      ret = true;
    CountDownLatch l;
    if((l=pendingMap.get(parentDN)) != null)
    {
      l.await();
    }
    return ret;
  }
  /**
@@ -190,17 +190,22 @@
   */
  public void addPending(DN dn)
  {
    pendingMap.putIfAbsent(dn, dn);
    pendingMap.putIfAbsent(dn, new CountDownLatch(1));
  }
  /**
   * Remove the specified DN from the pending map.
   * Remove the specified DN from the pending map, it may not exist if the
   * entries are being migrated so just return.
   *
   * @param dn The DN to remove from the map.
   */
  public void removePending(DN dn)
  {
    pendingMap.remove(dn);
    CountDownLatch l = pendingMap.remove(dn);
    if(l != null)
    {
      l.countDown();
    }
  }
@@ -224,28 +229,14 @@
        return parentID;
      }
    }
    int i=0;
    //If the parent is in the pending map, another thread is working on the
    //parent entry; wait 500 ms until that thread is done with the parent.
    while(isPending(parentDN)) {
      try {
        Thread.sleep(50);
        if(i == 10) {
          //Temporary message until this code is removed.
           Message message = Message.raw(Category.JEB, Severity.SEVERE_ERROR,
               "time out in parentID check");
          logError(message);
          return null;
        }
        i++;
      checkPending(parentDN);
      } catch (Exception e) {
        //Temporary message until this code is removed.
         Message message = Message.raw(Category.JEB, Severity.SEVERE_ERROR,
                "Exception thrown in parentID check");
         logError(message);
        return null;
      }
    }
    parentID = entryContainer.getDN2ID().get(null, parentDN, LockMode.DEFAULT);
    //If the parent is in dn2id, add it to the cache.
    if (parentID != null) {