kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jun...@apache.org
Subject kafka git commit: KAFKA-4614; Forcefully unmap mmap of OffsetIndex to prevent long GC pause
Date Thu, 19 Jan 2017 17:48:44 GMT
Repository: kafka
Updated Branches:
  refs/heads/0.10.2 ae5591a3a -> 770bab399


KAFKA-4614; Forcefully unmap mmap of OffsetIndex to prevent long GC pause

Issue: https://issues.apache.org/jira/browse/KAFKA-4614

Fixes the problem that the broker threads suffered by long GC pause.
When GC thread collects mmap objects which were created for index files, it unmaps memory
mapping so kernel turns to delete a file physically. This work may transparently read file's
metadata from physical disk if it's not available on cache.
This seems to happen typically when we're using G1GC, due to it's strategy to left a garbage
for a long time if other objects in the same region are still alive.
See the link for the details.

Author: Yuto Kawamura <kawamuray.dadada@gmail.com>

Reviewers: Apurva Mehta <apurva.1618@gmail.com>, Guozhang Wang <wangguoz@gmail.com>,
Ismael Juma <ismael@juma.me.uk>,

Closes #2352 from kawamuray/KAFKA-4614-force-munmap-for-index

(cherry picked from commit 5fc530bc483db145e0cba3b63a57d6d6a7c547f2)
Signed-off-by: Jun Rao <junrao@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/770bab39
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/770bab39
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/770bab39

Branch: refs/heads/0.10.2
Commit: 770bab39916e213443aff8f696c6097b551b9408
Parents: ae5591a
Author: Yuto Kawamura <kawamuray.dadada@gmail.com>
Authored: Thu Jan 19 09:47:34 2017 -0800
Committer: Jun Rao <junrao@gmail.com>
Committed: Thu Jan 19 09:48:40 2017 -0800

----------------------------------------------------------------------
 core/src/main/scala/kafka/log/AbstractIndex.scala | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/770bab39/core/src/main/scala/kafka/log/AbstractIndex.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/kafka/log/AbstractIndex.scala b/core/src/main/scala/kafka/log/AbstractIndex.scala
index 77ef0f7..6f850d5 100644
--- a/core/src/main/scala/kafka/log/AbstractIndex.scala
+++ b/core/src/main/scala/kafka/log/AbstractIndex.scala
@@ -17,7 +17,7 @@
 
 package kafka.log
 
-import java.io.{File, RandomAccessFile}
+import java.io.{File, IOException, RandomAccessFile}
 import java.nio.{ByteBuffer, MappedByteBuffer}
 import java.nio.channels.FileChannel
 import java.util.concurrent.locks.{Lock, ReentrantLock}
@@ -141,8 +141,16 @@ abstract class AbstractIndex[K, V](@volatile var file: File, val baseOffset:
Lon
    */
   def delete(): Boolean = {
     info(s"Deleting index ${file.getAbsolutePath}")
-    if(Os.isWindows)
+    inLock(lock) {
+      // On JVM, a memory mapping is typically unmapped by garbage collector.
+      // However, in some cases it can pause application threads(STW) for a long moment reading
metadata from a physical disk.
+      // To prevent this, we forcefully cleanup memory mapping within proper execution which
never affects API responsiveness.
+      // See https://issues.apache.org/jira/browse/KAFKA-4614 for the details.
       CoreUtils.swallow(forceUnmap(mmap))
+      // Accessing unmapped mmap crashes JVM by SEGV.
+      // Accessing it after this method called sounds like a bug but for safety, assign null
and do not allow later access.
+      mmap = null
+    }
     file.delete()
   }
 
@@ -185,7 +193,7 @@ abstract class AbstractIndex[K, V](@volatile var file: File, val baseOffset:
Lon
   def truncateTo(offset: Long): Unit
 
   /**
-   * Forcefully free the buffer's mmap. We do this only on windows.
+   * Forcefully free the buffer's mmap.
    */
   protected def forceUnmap(m: MappedByteBuffer) {
     try {
@@ -279,4 +287,4 @@ abstract class AbstractIndex[K, V](@volatile var file: File, val baseOffset:
Lon
 object IndexSearchType extends Enumeration {
   type IndexSearchEntity = Value
   val KEY, VALUE = Value
-}
\ No newline at end of file
+}


Mime
View raw message