Return-Path: X-Original-To: apmail-lucenenet-commits-archive@www.apache.org Delivered-To: apmail-lucenenet-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B1571178A9 for ; Mon, 18 May 2015 06:28:00 +0000 (UTC) Received: (qmail 52169 invoked by uid 500); 18 May 2015 06:28:00 -0000 Delivered-To: apmail-lucenenet-commits-archive@lucenenet.apache.org Received: (qmail 52134 invoked by uid 500); 18 May 2015 06:28:00 -0000 Mailing-List: contact commits-help@lucenenet.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@lucenenet.apache.org Delivered-To: mailing list commits@lucenenet.apache.org Received: (qmail 52125 invoked by uid 99); 18 May 2015 06:28:00 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 May 2015 06:28:00 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 59200DFD9E; Mon, 18 May 2015 06:28:00 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: synhershko@apache.org To: commits@lucenenet.apache.org Date: Mon, 18 May 2015 06:28:00 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] lucenenet git commit: synchronize access to underlying file stream for NIOFSDirectory Repository: lucenenet Updated Branches: refs/heads/master cd0a14aea -> 40684b823 synchronize access to underlying file stream for NIOFSDirectory Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/ae1fc2a3 Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/ae1fc2a3 Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/ae1fc2a3 Branch: refs/heads/master Commit: ae1fc2a32b4eb3a347b301c8cb62dfad85acd6db Parents: e3833d6 Author: Laimonas Simutis Authored: Sun May 17 12:10:26 2015 -0400 Committer: Laimonas Simutis Committed: Sun May 17 12:10:26 2015 -0400 ---------------------------------------------------------------------- src/Lucene.Net.Core/Store/NIOFSDirectory.cs | 22 ++++-------- .../Support/FileStreamExtensions.cs | 37 +++++++++++--------- 2 files changed, 28 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ae1fc2a3/src/Lucene.Net.Core/Store/NIOFSDirectory.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Store/NIOFSDirectory.cs b/src/Lucene.Net.Core/Store/NIOFSDirectory.cs index 42fa5e6..e2a0a95 100644 --- a/src/Lucene.Net.Core/Store/NIOFSDirectory.cs +++ b/src/Lucene.Net.Core/Store/NIOFSDirectory.cs @@ -77,36 +77,28 @@ namespace Lucene.Net.Store public override IndexInput OpenInput(string name, IOContext context) { EnsureOpen(); - //File path = new File(Directory, name); - FileInfo path = new FileInfo(Path.Combine(Directory.FullName, name)); - //path.Create(); - FileStream fc = new FileStream(path.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);//FileChannel.open(path.toPath(), StandardOpenOption.READ); + var path = new FileInfo(Path.Combine(Directory.FullName, name)); + var fc = new FileStream(path.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete); return new NIOFSIndexInput("NIOFSIndexInput(path=\"" + path + "\")", fc, context); - //return new NIOFSIndexInput(new FileInfo(Path.Combine(Directory.FullName, name)), context, ReadChunkSize); } public override IndexInputSlicer CreateSlicer(string name, IOContext context) { EnsureOpen(); - //File path = new File(Directory, name); - //FileStream descriptor = FileChannel.open(path.toPath(), StandardOpenOption.READ); - FileInfo path = new FileInfo(Path.Combine(Directory.FullName, name)); - FileStream fc = new FileStream(path.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete); + var path = new FileInfo(Path.Combine(Directory.FullName, name)); + var fc = new FileStream(path.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete); return new IndexInputSlicerAnonymousInnerClassHelper(this, context, path, fc); } - private class IndexInputSlicerAnonymousInnerClassHelper : Directory.IndexInputSlicer + private class IndexInputSlicerAnonymousInnerClassHelper : IndexInputSlicer { - private readonly NIOFSDirectory OuterInstance; - private readonly IOContext Context; private readonly FileInfo Path; private readonly FileStream Descriptor; - public IndexInputSlicerAnonymousInnerClassHelper(NIOFSDirectory outerInstance, Lucene.Net.Store.IOContext context, FileInfo path, FileStream descriptor) + public IndexInputSlicerAnonymousInnerClassHelper(NIOFSDirectory outerInstance, IOContext context, FileInfo path, FileStream descriptor) : base(outerInstance) { - this.OuterInstance = outerInstance; this.Context = context; this.Path = path; this.Descriptor = descriptor; @@ -131,7 +123,7 @@ namespace Lucene.Net.Store { return OpenSlice("full-slice", 0, Descriptor.Length); } - catch (System.IO.IOException ex) + catch (IOException ex) { throw new Exception(ex.Message, ex); } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ae1fc2a3/src/Lucene.Net.Core/Support/FileStreamExtensions.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Support/FileStreamExtensions.cs b/src/Lucene.Net.Core/Support/FileStreamExtensions.cs index c305d85..1e9fc14 100644 --- a/src/Lucene.Net.Core/Support/FileStreamExtensions.cs +++ b/src/Lucene.Net.Core/Support/FileStreamExtensions.cs @@ -4,31 +4,36 @@ namespace Lucene.Net.Support { public static class FileStreamExtensions { + private static object _fsReadLock = new object(); + //Reads bytes from the Filestream into the bytebuffer public static int Read(this FileStream file, ByteBuffer dst, long position) { - // TODO: check this logic, could probably optimize - if (position >= file.Length) - return 0; + lock (_fsReadLock) + { + // TODO: check this logic, could probably optimize + if (position >= file.Length) + return 0; - var original = file.Position; + var original = file.Position; - file.Seek(position, SeekOrigin.Begin); + file.Seek(position, SeekOrigin.Begin); - int count = 0; + int count = 0; - for (int i = dst.Position; i < dst.Limit; i++) - { - int v = file.ReadByte(); - if (v == -1) - break; - dst.Put((byte)v); - count++; - } + for (int i = dst.Position; i < dst.Limit; i++) + { + int v = file.ReadByte(); + if (v == -1) + break; + dst.Put((byte) v); + count++; + } - file.Seek(original, SeekOrigin.Begin); + file.Seek(original, SeekOrigin.Begin); - return count; + return count; + } } } } \ No newline at end of file