From aee0cc8f6477ae026927746a9b6f54a38d5e68c3 Mon Sep 17 00:00:00 2001 From: shuozhang Date: Wed, 4 Mar 2020 17:46:38 -0500 Subject: [PATCH 1/3] A minor change for zOS --- .../apache/kafka/common/utils/OperatingSystem.java | 5 ++++- core/src/main/scala/kafka/log/AbstractIndex.scala | 12 ++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java b/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java index 9d80295b1237f..cd057d2750c95 100644 --- a/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java +++ b/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java @@ -27,8 +27,11 @@ private OperatingSystem() { public static final boolean IS_WINDOWS; + public static boolean IS_ZOS; + static { NAME = System.getProperty("os.name").toLowerCase(Locale.ROOT); IS_WINDOWS = NAME.startsWith("windows"); - } + IS_ZOS = NAME.startsWith("z/os"); + } } diff --git a/core/src/main/scala/kafka/log/AbstractIndex.scala b/core/src/main/scala/kafka/log/AbstractIndex.scala index e8e713692a7ae..2104b8b660d79 100644 --- a/core/src/main/scala/kafka/log/AbstractIndex.scala +++ b/core/src/main/scala/kafka/log/AbstractIndex.scala @@ -180,8 +180,8 @@ abstract class AbstractIndex(@volatile var file: File, val baseOffset: Long, val try { val position = mmap.position() - /* Windows won't let us modify the file length while the file is mmapped :-( */ - if (OperatingSystem.IS_WINDOWS) + /* Windows or z/OS won't let us modify the file length while the file is mmapped :-( */ + if (OperatingSystem.IS_WINDOWS || OperatingSystem.IS_ZOS) safeForceUnmap() raf.setLength(roundedNewSize) _length = roundedNewSize @@ -322,16 +322,16 @@ abstract class AbstractIndex(@volatile var file: File, val baseOffset: Long, val } /** - * Execute the given function in a lock only if we are running on windows. We do this - * because Windows won't let us resize a file while it is mmapped. As a result we have to force unmap it + * Execute the given function in a lock only if we are running on windows or z/OS. We do this + * because Windows or z/OS won't let us resize a file while it is mmapped. As a result we have to force unmap it * and this requires synchronizing reads. */ protected def maybeLock[T](lock: Lock)(fun: => T): T = { - if (OperatingSystem.IS_WINDOWS) + if (OperatingSystem.IS_WINDOWS || OperatingSystem.IS_ZOS) lock.lock() try fun finally { - if (OperatingSystem.IS_WINDOWS) + if (OperatingSystem.IS_WINDOWS || OperatingSystem.IS_ZOS) lock.unlock() } } From bd84ce3d54587c2c8f2ff3ec81c1183ed2ba791d Mon Sep 17 00:00:00 2001 From: shuozhang Date: Wed, 4 Mar 2020 21:23:20 -0500 Subject: [PATCH 2/3] Add a static keyword --- .../java/org/apache/kafka/common/utils/OperatingSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java b/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java index cd057d2750c95..012c9994dbe9a 100644 --- a/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java +++ b/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java @@ -27,7 +27,7 @@ private OperatingSystem() { public static final boolean IS_WINDOWS; - public static boolean IS_ZOS; + public static final boolean IS_ZOS; static { NAME = System.getProperty("os.name").toLowerCase(Locale.ROOT); From a5847ccee2a12c486b94a37e5ae0140ffde3028a Mon Sep 17 00:00:00 2001 From: shuozhang Date: Thu, 23 Apr 2020 06:02:20 -0400 Subject: [PATCH 3/3] Fix the identation of the curly bracket --- .../java/org/apache/kafka/common/utils/OperatingSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java b/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java index 012c9994dbe9a..8dc8b86233f2e 100644 --- a/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java +++ b/clients/src/main/java/org/apache/kafka/common/utils/OperatingSystem.java @@ -33,5 +33,5 @@ private OperatingSystem() { NAME = System.getProperty("os.name").toLowerCase(Locale.ROOT); IS_WINDOWS = NAME.startsWith("windows"); IS_ZOS = NAME.startsWith("z/os"); - } + } }