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

Jean-Noel Rouvignac
05.11.2015 5aca3171444ee4ad8ecf62343726df4720fb7cb0
OPENDJ-1994 Setup with persistit backend containing automatically generated data hangs

Reapply r12193 after https://stash.forgerock.org/projects/COMMONS/repos/forgerock-persistit/commits/85271bef2cd4b154d923d6b775bd5fdaa59f0b1b .

Original commit message was:





Fix continuous integration build failure:

Failed Test: org.opends.server.backends.pluggable.persistit.PersistitTestCase#testImportLDIF
Failure Cause: org.opends.server.types.DirectoryException: IllegalStateException: Database is already open, either the backend is enabled or an import is currently running. (PersistItStorage.java:653 PersistItStorage.java:643 TracedStorage.java:276 Importer.java:1161 Importer.java:1070 Importer.java:905 RootContainer.java:321 RootContainer.java:185 BackendImpl.java:676 PluggableBackendImplTestCase.java:848 NativeMethodAccessorImpl.java:-2 NativeMethodAccessorImpl.java:57 DelegatingMethodAccessorImpl.java:43 Method.java:606 MethodInvocationHelper.java:76 Invoker.java:673 Invoker.java:846 Invoker.java:1170 TestMethodWorker.java:125 TestMethodWorker.java:109 TestRunner.java:1147 ...)
org.opends.server.backends.pluggable.RootContainer.importLDIFWithOnDiskMerge(RootContainer.java:336)
org.opends.server.backends.pluggable.RootContainer.importLDIF(RootContainer.java:185)
org.opends.server.backends.pluggable.BackendImpl.importLDIF(BackendImpl.java:676)
org.opends.server.backends.pluggable.PluggableBackendImplTestCase.testImportLDIF(PluggableBackendImplTestCase.java:848)

The root cause of this problem is that PersisitIt refuses to release exchanges from current thread if it is not the thread that acquired that exchange from the pool.
The fix is to not release the exchanges at all as per http://sources.forgerock.org/cru/CR-6815#c73584 .


PersistItStorage.java:
In ImporterImpl:
- removed the field allExchanges
- in close(), do not release any exchanges since we are about to close the PersistIt instance
1 files modified
15 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java 15 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java
@@ -46,6 +46,8 @@
import java.util.ListIterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedDeque;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
@@ -247,18 +249,29 @@
  private final class ImporterImpl implements Importer
  {
    private final Map<TreeName, Tree> trees = new HashMap<TreeName, Tree>();
    private final Queue<Map<TreeName, Exchange>> allExchanges = new ConcurrentLinkedDeque<>();
    private final ThreadLocal<Map<TreeName, Exchange>> exchanges = new ThreadLocal<Map<TreeName, Exchange>>()
    {
      @Override
      protected Map<TreeName, Exchange> initialValue()
      {
        return new HashMap<TreeName, Exchange>();
        final Map<TreeName, Exchange> value = new HashMap<>();
        allExchanges.add(value);
        return value;
      }
    };
    @Override
    public void close()
    {
      for (Map<TreeName, Exchange> map : allExchanges)
      {
        for (Exchange exchange : map.values())
        {
          db.releaseExchange(exchange);
        }
        map.clear();
      }
      PersistItStorage.this.close();
    }