lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [28/50] [abbrv] lucenenet git commit: Fixed bugs in Core.Store.MMapDirectory that were causing false access denied exceptions when reaching the end of the file.
Date Sun, 23 Oct 2016 13:02:14 GMT
Fixed bugs in Core.Store.MMapDirectory that were causing false access denied exceptions when
reaching the end of the file.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/3318a4d2
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/3318a4d2
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/3318a4d2

Branch: refs/heads/master
Commit: 3318a4d2601cb0f655786ee34bccba7371a1dc71
Parents: 302c7ad
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Wed Oct 19 10:08:13 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Thu Oct 20 18:20:59 2016 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Store/MMapDirectory.cs | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/3318a4d2/src/Lucene.Net.Core/Store/MMapDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/MMapDirectory.cs b/src/Lucene.Net.Core/Store/MMapDirectory.cs
index 4b8ec4b..1276e5e 100644
--- a/src/Lucene.Net.Core/Store/MMapDirectory.cs
+++ b/src/Lucene.Net.Core/Store/MMapDirectory.cs
@@ -348,18 +348,27 @@ namespace Lucene.Net.Store
                                                         HandleInheritability inheritability,
bool leaveOpen)
              */
 
+            long fileCapacity = length == 0 ? ushort.MaxValue : length;
+
             if (input.memoryMappedFile == null)
             {
-                input.memoryMappedFile = MemoryMappedFile.CreateFromFile(fc, null, length
== 0 ? 1024 : length, MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.Inheritable,
false);
+                input.memoryMappedFile = MemoryMappedFile.CreateFromFile(fc, null, fileCapacity,
MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.Inheritable, false);
             }
 
             long bufferStart = 0L;
             for (int bufNr = 0; bufNr < nrBuffers; bufNr++)
             {
                 int bufSize = (int)((length > (bufferStart + chunkSize)) ? chunkSize :
(length - bufferStart));
-                //LUCENE TO-DO
-                buffers[bufNr] = new MemoryMappedFileByteBuffer(input.memoryMappedFile.CreateViewAccessor(offset
+ bufferStart, bufSize, MemoryMappedFileAccess.Read), -1, 0, bufSize, bufSize);
-                //buffers[bufNr] = fc.Map(FileStream.MapMode.READ_ONLY, offset + bufferStart,
bufSize);
+
+                // LUCENENET: We get a file access exception if we create a 0 byte file at
the end of the range.
+                // We can fix this by moving back 1 byte if the bufSize is 0.
+                int adjust = 0;
+                if (bufSize == 0 && bufNr == (nrBuffers - 1) && (offset +
bufferStart) > 0)
+                {
+                    adjust = 1;
+                }
+
+                buffers[bufNr] = new MemoryMappedFileByteBuffer(input.memoryMappedFile.CreateViewAccessor((offset
+ bufferStart) - adjust, bufSize, MemoryMappedFileAccess.Read), -1, 0, bufSize, bufSize);
                 bufferStart += bufSize;
             }
 


Mime
View raw message