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

Yannick Lecaillez
10.50.2016 b425cbd0d1ea47999a351b07fdca5930d5977953
OPENDJ-2761: Import does not work when using heap buffers.

Fix available heap memory computation.
2 files modified
11 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/OnDiskMergeImporter.java 10 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/PluggableBackendImplTestCase.java 1 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/OnDiskMergeImporter.java
@@ -481,7 +481,7 @@
    private int computeBufferSize(int nbBuffer) throws InitializationException
    {
      final long availableMemory = calculateAvailableMemory();
      final long availableMemory = calculateAvailableHeapMemoryForBuffers();
      logger.info(NOTE_IMPORT_LDIF_TOT_MEM_BUF, availableMemory, nbBuffer);
      final int bufferSize = Math.min((int) (availableMemory / nbBuffer), MAX_BUFFER_SIZE);
@@ -489,7 +489,7 @@
      {
        // Not enough memory.
        throw new InitializationException(ERR_IMPORT_LDIF_LACK_MEM.get(availableMemory, nbBuffer * MIN_BUFFER_SIZE
            + REQUIRED_FREE_MEMORY));
            + DB_CACHE_SIZE + REQUIRED_FREE_MEMORY));
      }
      return bufferSize;
    }
@@ -498,7 +498,7 @@
     * Calculates the amount of available memory which can be used by this import, taking into account whether or not
     * the import is running offline or online as a task.
     */
    private long calculateAvailableMemory()
    private long calculateAvailableHeapMemoryForBuffers()
    {
      final Runtime runtime = Runtime.getRuntime();
      // call twice gc to ensure finalizers are called
@@ -526,9 +526,7 @@
        // Be pessimistic when memory is low.
        importMemPct -= 25;
      }
      final long usedMemory = runtime.totalMemory() - runtime.freeMemory() + DB_CACHE_SIZE + REQUIRED_FREE_MEMORY;
      return (totalAvailableMemory * importMemPct / 100) - usedMemory;
      return (totalAvailableMemory * importMemPct / 100) - (DB_CACHE_SIZE + REQUIRED_FREE_MEMORY);
    }
  }
opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/PluggableBackendImplTestCase.java
@@ -949,6 +949,7 @@
      importConf.setIncludeBranches(Collections.singleton(testBaseDN));
      importConf.setSkipDNValidation(true);
      importConf.setThreadCount(0);
      importConf.setOffHeapSize(0); // Force heap buffer for automatic buffer scaling.
      backend.importLDIF(importConf, DirectoryServer.getInstance().getServerContext());
    }
    assertEquals(rejectedEntries.size(), 0,