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

coulbeck
01.20.2007 31153ccec78ed6187b9543babccdaf996968d6bb
Fix for issue #1262: database becomes empty when importing a not existing ldif file.
3 files modified
77 ■■■■■ changed files
opends/src/server/org/opends/server/backends/jeb/ImportJob.java 48 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/messages/ToolMessages.java 13 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/ImportLDIF.java 16 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/backends/jeb/ImportJob.java
@@ -150,6 +150,15 @@
    envConfig.setConfigParam("je.log.totalBufferBytes", "30000000");
    envConfig.setConfigParam("je.log.fileMax", "100000000");
*/
    // Create an LDIF reader. Throws an exception if the file does not exist.
    reader = new LDIFReader(ldifImportConfig);
    int msgID;
    String message;
    long startTime;
    try
    {
    rootContainer = new RootContainer(config, backend);
    if (ldifImportConfig.appendToExistingData())
    {
@@ -182,8 +191,8 @@
    long bufferSize = config.getImportBufferSize() /
         (importThreadCount*config.getBaseDNs().length);
    int msgID = MSGID_JEB_IMPORT_THREAD_COUNT;
    String message = getMessage(msgID, importThreadCount);
      msgID = MSGID_JEB_IMPORT_THREAD_COUNT;
      message = getMessage(msgID, importThreadCount);
    logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.NOTICE,
             message, msgID);
@@ -216,6 +225,7 @@
      importContext.setBufferSize(bufferSize);
      importContext.setConfig(config);
      importContext.setLDIFImportConfig(this.ldifImportConfig);
        importContext.setLDIFReader(reader);
      importContext.setBaseDN(baseDN);
      importContext.setContainerName(entryContainer.getContainerName());
@@ -231,7 +241,7 @@
    }
    // Make a note of the time we started.
    long startTime = System.currentTimeMillis();
      startTime = System.currentTimeMillis();
    try
    {
@@ -305,6 +315,11 @@
      logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.NOTICE,
               message, msgID);
    }
    }
    finally
    {
      reader.close();
    }
    long finishTime = System.currentTimeMillis();
    long importTime = (finishTime - startTime);
@@ -438,14 +453,14 @@
  }
  /**
   * Open a reader for the LDIF file and create a set of worker threads, one
   * set for each base DN. Read each entry from the LDIF and determine which
   * Create a set of worker threads, one set for each base DN.
   * Read each entry from the LDIF and determine which
   * base DN the entry belongs to. Write the dn2id database, then put the
   * entry on the appropriate queue for the worker threads to consume.
   * Record the entry count for each base DN when all entries have been
   * processed.
   *
   * @return true if is more data to be read from the LDIF file (the import
   * @return true if thre is more data to be read from the LDIF file (the import
   * pass size was reached), false if the entire LDIF file has been read.
   *
   * @throws JebException If an error occurs in the JE backend.
@@ -458,19 +473,8 @@
  {
    boolean moreData = false;
    // Create an LDIF reader if necessary.
    if (reader == null)
    {
      reader = new LDIFReader(ldifImportConfig);
      for (ImportContext ic : importMap.values())
      {
        ic.setLDIFReader(reader);
      }
    }
    ArrayList<ImportThread> threads;
    try
    {
      // Create one set of worker threads for each base DN.
      int importThreadCount = config.getImportThreadCount();
      threads = new ArrayList<ImportThread>(importThreadCount*importMap.size());
@@ -589,14 +593,6 @@
          }
        }
      }
    }
    finally
    {
      if (! moreData)
      {
        reader.close();
      }
    }
    return moreData;
opends/src/server/org/opends/server/messages/ToolMessages.java
@@ -7060,6 +7060,16 @@
  /**
   * The message ID for the message that will be used if one of the LDIF files
   * to be imported cannot be read.  This takes one argument, which is the
   * pathname of a file that cannot be read.
   */
  public static final int MSGID_LDIFIMPORT_CANNOT_READ_FILE =
       CATEGORY_MASK_TOOLS | SEVERITY_MASK_SEVERE_ERROR | 887;
  /**
   * Associates a set of generic messages with the message IDs defined in this
   * class.
   */
@@ -9281,6 +9291,9 @@
                    "shared lock for backend %s:  %s.  This lock should " +
                    "automatically be cleared when the rebuild process " +
                    "exits, so no further action should be required");
    registerMessage(MSGID_LDIFIMPORT_CANNOT_READ_FILE,
                    "The specified LDIF file %s cannot be read");
  }
}
opends/src/server/org/opends/server/tools/ImportLDIF.java
@@ -61,7 +61,7 @@
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.loggers.Error.*;
import static org.opends.server.messages.MessageHandler.*;
import static org.opends.server.messages.MessageHandler.getMessage;
import static org.opends.server.messages.ToolMessages.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
@@ -858,6 +858,20 @@
    if (ldifFiles.isPresent())
    {
      ArrayList<String> fileList = new ArrayList<String>(ldifFiles.getValues());
      int badFileCount = 0;
      for (String pathname : fileList)
      {
        File f = new File(pathname);
        if (!f.canRead())
        {
          int    msgID   = MSGID_LDIFIMPORT_CANNOT_READ_FILE;
          String message = getMessage(msgID, pathname);
          logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
                   message, msgID);
          badFileCount++;
        }
      }
      if (badFileCount > 0) return 1;
      importConfig = new LDIFImportConfig(fileList);
    }
    else