From 4dcd9a5b57618f0ddf041f86f2922bb36699a10b Mon Sep 17 00:00:00 2001 From: Shikhar Bhushan Date: Wed, 16 Oct 2019 22:44:20 -0400 Subject: [PATCH] Eagerly unmap during resize The mmap field gets re-initialized here, so the old object will become garbage-collectible. We should be eagerly unmapping here too, not just for Windows support. --- core/src/main/scala/kafka/log/AbstractIndex.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/scala/kafka/log/AbstractIndex.scala b/core/src/main/scala/kafka/log/AbstractIndex.scala index 7dca8120c3d5b..441eb9d36e402 100644 --- a/core/src/main/scala/kafka/log/AbstractIndex.scala +++ b/core/src/main/scala/kafka/log/AbstractIndex.scala @@ -182,9 +182,10 @@ abstract class AbstractIndex[K, V](@volatile var file: File, val baseOffset: Lon try { val position = mmap.position() - /* Windows won't let us modify the file length while the file is mmapped :-( */ - if (OperatingSystem.IS_WINDOWS) - safeForceUnmap() + // Necessary on Windows, file length cannot be modified without unmapping + // Also, generally a good practice to eagerly unmap rather than leave it to GC (KAFKA-4614) + safeForceUnmap() + raf.setLength(roundedNewSize) _length = roundedNewSize mmap = raf.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, roundedNewSize)