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

Yannick Lecaillez
15.33.2016 2dc2216b94bcce8ec42ec4873661282e3ed6e9ed
OPENDJ-2992: Windows: rebuild-index sometimes fails with
BufferUnderflowException

Force modifications performed in the mmap regions to be synced to disk
before GC frees it. There is indeed not guarantee that a future mmap()
will be able to read otherwise.
1 files modified
17 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/OnDiskMergeImporter.java 17 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/OnDiskMergeImporter.java
@@ -1564,10 +1564,10 @@
           * performed by the CollectorCursor.
           */
          checkThreadNotInterrupted();
          final FileRegion region = new FileRegion(channel, startOffset, chunk.size());
          final int regionSize;
          try (final SequentialCursor<ByteString, ByteString> source =
              new CollectorCursor<>(chunk.flip(), phaseOneDeduplicator))
          try (final FileRegion region = new FileRegion(channel, startOffset, chunk.size());
               final SequentialCursor<ByteString, ByteString> source =
                new CollectorCursor<>(chunk.flip(), phaseOneDeduplicator))
          {
            regionSize = region.write(source);
          }
@@ -1827,7 +1827,7 @@
     * +------------+--------------+--------------+----------------+
     * </pre>
     */
    static final class FileRegion
    static final class FileRegion implements Closeable
    {
      private final MappedByteBuffer mmapBuffer;
      private final OutputStream mmapBufferOS = new OutputStream()
@@ -1865,6 +1865,15 @@
        return mmapBuffer.position();
      }
      @Override
      public void close()
      {
        // Since this mmapBuffer will be GC'd, we have to ensure that the modified data
        // are synced to disk. Indeed, there is no guarantee that these data
        // will otherwise be available for the future File.map(READ).
        mmapBuffer.force();
      }
      /** Cursor through the specific memory-mapped file's region. */
      static final class Cursor implements MeteredCursor<ByteString, ByteString>
      {