From 89a35a108e5c7f56095c87090d38fb0e5b1df2a0 Mon Sep 17 00:00:00 2001 From: Liu Xiao Date: Fri, 29 Jun 2018 09:10:47 +0800 Subject: [PATCH 1/3] try to preallocate space after RandomAccessFile#setLength() --- .../hash/impl/VanillaChronicleHash.java | 53 +++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java index 2d7daa05a..39111e31f 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java @@ -17,6 +17,8 @@ package net.openhft.chronicle.hash.impl; +import com.sun.jna.Native; +import com.sun.jna.Platform; import net.openhft.chronicle.algo.locks.*; import net.openhft.chronicle.bytes.BytesStore; import net.openhft.chronicle.bytes.MappedBytesStoreFactory; @@ -40,12 +42,12 @@ import net.openhft.chronicle.wire.Marshallable; import net.openhft.chronicle.wire.WireIn; import net.openhft.chronicle.wire.WireOut; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import java.io.Closeable; -import java.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; +import java.io.*; import java.lang.ref.WeakReference; +import java.lang.reflect.Field; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.ArrayList; @@ -68,6 +70,9 @@ public abstract class VanillaChronicleHash> implements ChronicleHash, Marshallable { + private static final Logger LOG = + LoggerFactory.getLogger(VanillaChronicleHash.class.getName()); + public static final long TIER_COUNTERS_AREA_SIZE = 64; public static final long RESERVED_GLOBAL_MUTABLE_STATE_BYTES = 1024; @@ -944,6 +949,36 @@ public abstract class VanillaChronicleHash Date: Mon, 2 Jul 2018 09:00:34 +0800 Subject: [PATCH 2/3] code refactoring --- .../hash/impl/VanillaChronicleHash.java | 40 +--------------- .../hash/impl/util/jna/PosixFallocate.java | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 38 deletions(-) create mode 100644 src/main/java/net/openhft/chronicle/hash/impl/util/jna/PosixFallocate.java diff --git a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java index 39111e31f..2c47fc690 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java @@ -17,7 +17,6 @@ package net.openhft.chronicle.hash.impl; -import com.sun.jna.Native; import com.sun.jna.Platform; import net.openhft.chronicle.algo.locks.*; import net.openhft.chronicle.bytes.BytesStore; @@ -29,6 +28,7 @@ import net.openhft.chronicle.hash.*; import net.openhft.chronicle.hash.impl.util.BuildVersion; import net.openhft.chronicle.hash.impl.util.Cleaner; import net.openhft.chronicle.hash.impl.util.CleanerUtils; +import net.openhft.chronicle.hash.impl.util.jna.PosixFallocate; import net.openhft.chronicle.hash.impl.util.jna.PosixMsync; import net.openhft.chronicle.hash.impl.util.jna.WindowsMsync; import net.openhft.chronicle.hash.serialization.DataAccess; @@ -42,12 +42,9 @@ import net.openhft.chronicle.wire.Marshallable; import net.openhft.chronicle.wire.WireIn; import net.openhft.chronicle.wire.WireOut; import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.*; import java.lang.ref.WeakReference; -import java.lang.reflect.Field; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.ArrayList; @@ -70,9 +67,6 @@ public abstract class VanillaChronicleHash> implements ChronicleHash, Marshallable { - private static final Logger LOG = - LoggerFactory.getLogger(VanillaChronicleHash.class.getName()); - public static final long TIER_COUNTERS_AREA_SIZE = 64; public static final long RESERVED_GLOBAL_MUTABLE_STATE_BYTES = 1024; @@ -949,36 +943,6 @@ public abstract class VanillaChronicleHash Date: Mon, 2 Jul 2018 09:12:01 +0800 Subject: [PATCH 3/3] use OS.isLinux() instead of Platform.isLinux() for consistency --- .../net/openhft/chronicle/hash/impl/VanillaChronicleHash.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java index 2c47fc690..beea4ceef 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java @@ -17,7 +17,6 @@ package net.openhft.chronicle.hash.impl; -import com.sun.jna.Platform; import net.openhft.chronicle.algo.locks.*; import net.openhft.chronicle.bytes.BytesStore; import net.openhft.chronicle.bytes.MappedBytesStoreFactory; @@ -964,7 +963,7 @@ public abstract class VanillaChronicleHash