BREAKING: Lucene.Net.MMapDirectory: Removed UnmapHack/UNMAP_SUPPORTED features since these are not needed in .NET.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/7ae81efe Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/7ae81efe Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/7ae81efe Branch: refs/heads/master Commit: 7ae81efe2ab898932cabda9820011b76b4259760 Parents: 8ab834f Author: Shad Storhaug <[email protected]> Authored: Fri Sep 22 12:02:51 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Fri Sep 22 12:45:18 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net.Tests/Store/TestDirectory.cs | 11 +++--- src/Lucene.Net.Tests/Store/TestMultiMMap.cs | 11 +++--- src/Lucene.Net/Store/FSDirectory.cs | 4 +-- src/Lucene.Net/Store/MMapDirectory.cs | 44 +++--------------------- 4 files changed, 18 insertions(+), 52 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7ae81efe/src/Lucene.Net.Tests/Store/TestDirectory.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests/Store/TestDirectory.cs b/src/Lucene.Net.Tests/Store/TestDirectory.cs index 407e38c..9d514c1 100644 --- a/src/Lucene.Net.Tests/Store/TestDirectory.cs +++ b/src/Lucene.Net.Tests/Store/TestDirectory.cs @@ -213,11 +213,12 @@ namespace Lucene.Net.Store Assert.IsTrue(SlowFileExists(d2, fname)); Assert.AreEqual(1 + largeBuffer.Length, d2.FileLength(fname)); - // don't do read tests if unmapping is not supported! - if (d2 is MMapDirectory && !((MMapDirectory)d2).UseUnmap) - { - continue; - } + // LUCENENET specific - unmap hack not needed + //// don't do read tests if unmapping is not supported! + //if (d2 is MMapDirectory && !((MMapDirectory)d2).UseUnmap) + //{ + // continue; + //} IndexInput input = d2.OpenInput(fname, NewIOContext(Random())); Assert.AreEqual((byte)i, input.ReadByte()); http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7ae81efe/src/Lucene.Net.Tests/Store/TestMultiMMap.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests/Store/TestMultiMMap.cs b/src/Lucene.Net.Tests/Store/TestMultiMMap.cs index 00c18d0..3dcb59d 100644 --- a/src/Lucene.Net.Tests/Store/TestMultiMMap.cs +++ b/src/Lucene.Net.Tests/Store/TestMultiMMap.cs @@ -404,11 +404,12 @@ namespace Lucene.Net.Store { DirectoryInfo path = CreateTempDir("mmap" + chunkSize); MMapDirectory mmapDir = new MMapDirectory(path, null, chunkSize); - // we will map a lot, try to turn on the unmap hack - if (MMapDirectory.UNMAP_SUPPORTED) - { - mmapDir.UseUnmap = true; - } + // LUCENENET specific - unmap hack not needed + //// we will map a lot, try to turn on the unmap hack + //if (MMapDirectory.UNMAP_SUPPORTED) + //{ + // mmapDir.UseUnmap = true; + //} MockDirectoryWrapper dir = new MockDirectoryWrapper(random, mmapDir); RandomIndexWriter writer = new RandomIndexWriter(random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).SetMergePolicy(NewLogMergePolicy())); Document doc = new Document(); http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7ae81efe/src/Lucene.Net/Store/FSDirectory.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Store/FSDirectory.cs b/src/Lucene.Net/Store/FSDirectory.cs index 8c65d9c..4c408ae 100644 --- a/src/Lucene.Net/Store/FSDirectory.cs +++ b/src/Lucene.Net/Store/FSDirectory.cs @@ -172,8 +172,8 @@ namespace Lucene.Net.Store /// </summary> public static FSDirectory Open(DirectoryInfo path, LockFactory lockFactory) { - if ((Constants.WINDOWS || Constants.SUN_OS || Constants.LINUX) && Constants.RUNTIME_IS_64BIT && - MMapDirectory.UNMAP_SUPPORTED) + if ((Constants.WINDOWS || Constants.SUN_OS || Constants.LINUX) && Constants.RUNTIME_IS_64BIT /*&& + MMapDirectory.UNMAP_SUPPORTED*/) // LUCENENET specific - unmap hack not needed { return new MMapDirectory(path, lockFactory); } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7ae81efe/src/Lucene.Net/Store/MMapDirectory.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Store/MMapDirectory.cs b/src/Lucene.Net/Store/MMapDirectory.cs index cb2dc0b..68cbaee 100644 --- a/src/Lucene.Net/Store/MMapDirectory.cs +++ b/src/Lucene.Net/Store/MMapDirectory.cs @@ -51,7 +51,7 @@ namespace Lucene.Net.Store /// </summary> public class MMapDirectory : FSDirectory { - private bool useUnmapHack = UNMAP_SUPPORTED; + // LUCENENET specific - unmap hack not needed /// <summary> /// Default max chunk size. </summary> @@ -166,42 +166,9 @@ namespace Lucene.Net.Store { } - /// <summary> - /// <c>true</c>, if this platform supports unmapping mmapped files. - /// </summary> - // LUCENENET NOTE: Some JREs had a bug that didn't allow them to unmap. + // LUCENENET specific - Some JREs had a bug that didn't allow them to unmap. // But according to MSDN, the MemoryMappedFile.Dispose() method will - // indeed "release all resources". - public static readonly bool UNMAP_SUPPORTED = true; - - // LUCENENET specific: No need for static constructor, since unmap is always supported - - /// <summary> - /// This property enables the workaround for unmapping the buffers - /// from address space after closing <see cref="IndexInput"/>, that is - /// mentioned in the bug report. This hack may fail on non-Sun JVMs. - /// It forcefully unmaps the buffer on close by using - /// an undocumented internal cleanup functionality. - /// <para/><b>NOTE:</b> Enabling this is completely unsupported - /// by Java and may lead to JVM crashes if <see cref="IndexInput"/> - /// is closed while another thread is still accessing it (SIGSEGV). </summary> - /// <exception cref="ArgumentException"> if <see cref="UNMAP_SUPPORTED"/> - /// is <c>false</c> and the workaround cannot be enabled. </exception> - public virtual bool UseUnmap - { - set - { - if (value && !UNMAP_SUPPORTED) - { - throw new System.ArgumentException("Unmap hack not supported on this platform!"); - } - this.useUnmapHack = value; - } - get - { - return useUnmapHack; - } - } + // indeed "release all resources". Therefore unmap hack is not needed in .NET. /// <summary> /// Returns the current mmap chunk size. </summary> @@ -266,18 +233,15 @@ namespace Lucene.Net.Store public sealed class MMapIndexInput : ByteBufferIndexInput { - //private readonly bool useUnmapHack; - //private string mapName; // LUCENENET NOTE: Not used internal MemoryMappedFile memoryMappedFile; // .NET port: this is equivalent to FileChannel.map private readonly FileStream fc; private readonly MMapDirectory outerInstance; internal MMapIndexInput(MMapDirectory outerInstance, string resourceDescription, FileStream fc) - : base(resourceDescription, null, fc.Length, outerInstance.chunkSizePower, outerInstance.UseUnmap) + : base(resourceDescription, null, fc.Length, outerInstance.chunkSizePower, true) { this.outerInstance = outerInstance; this.fc = fc ?? throw new ArgumentNullException("fc"); - //this.useUnmapHack = outerInstance.UseUnmap; this.SetBuffers(outerInstance.Map(this, fc, 0, fc.Length)); }
