lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [3/5] lucenenet git commit: Revert Revert "Lucene.Net.Store.FSDirectory: Removed Fsync() method and m_staleFiles variable and all references to them"
Date Fri, 15 Sep 2017 04:02:52 GMT
Revert Revert "Lucene.Net.Store.FSDirectory: Removed Fsync() method and m_staleFiles variable
and all references to them"

This reverts commit 681430e44ce316e18b788598ed002f6f14dd3822


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

Branch: refs/heads/master
Commit: b7c5f0b081e31aa873bf375c1e75cbda434bef9f
Parents: 2bfa241
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Fri Sep 15 09:35:27 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Fri Sep 15 09:36:36 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net/Store/FSDirectory.cs |  55 ++++++-----
 src/Lucene.Net/Util/IOUtils.cs      | 153 ++++++++++++++++---------------
 2 files changed, 112 insertions(+), 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b7c5f0b0/src/Lucene.Net/Store/FSDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Store/FSDirectory.cs b/src/Lucene.Net/Store/FSDirectory.cs
index 5487b96..8c65d9c 100644
--- a/src/Lucene.Net/Store/FSDirectory.cs
+++ b/src/Lucene.Net/Store/FSDirectory.cs
@@ -92,7 +92,10 @@ namespace Lucene.Net.Store
         public const int DEFAULT_READ_CHUNK_SIZE = 8192;
 
         protected readonly DirectoryInfo m_directory; // The underlying filesystem directory
-        protected readonly ISet<string> m_staleFiles = new ConcurrentHashSet<string>();
// Files written, but not yet sync'ed
+
+        // LUCENENET specific: No such thing as "stale files" in .NET, since Flush(true)
writes everything to disk before
+        // our FileStream is disposed.
+        //protected readonly ISet<string> m_staleFiles = new ConcurrentHashSet<string>();
// Files written, but not yet sync'ed
 #pragma warning disable 612, 618
         private int chunkSize = DEFAULT_READ_CHUNK_SIZE;
 #pragma warning restore 612, 618
@@ -310,7 +313,9 @@ namespace Lucene.Net.Store
             {
                 throw new IOException("Cannot delete " + file, e);
             }
-            m_staleFiles.Remove(name);
+            // LUCENENET specific: No such thing as "stale files" in .NET, since Flush(true)
writes everything to disk before
+            // our FileStream is disposed.
+            //m_staleFiles.Remove(name);
         }
 
         /// <summary>
@@ -353,30 +358,35 @@ namespace Lucene.Net.Store
 
         protected virtual void OnIndexOutputClosed(FSIndexOutput io)
         {
-            m_staleFiles.Add(io.name);
+            // LUCENENET specific: No such thing as "stale files" in .NET, since Flush(true)
writes everything to disk before
+            // our FileStream is disposed.
+            //m_staleFiles.Add(io.name);
         }
 
         public override void Sync(ICollection<string> names)
         {
             EnsureOpen();
-            ISet<string> toSync = new HashSet<string>(names);
-            toSync.IntersectWith(m_staleFiles);
 
-            // LUCENENET specific: Fsync breaks concurrency here.
-            // Part of a solution suggested by Vincent Van Den Berghe: http://apache.markmail.org/message/hafnuhq2ydhfjmi2
-            //foreach (var name in toSync)
+            // LUCENENET specific: No such thing as "stale files" in .NET, since Flush(true)
writes everything to disk before
+            // our FileStream is disposed. Therefore, there is nothing else to do in this
method.
+            //ISet<string> toSync = new HashSet<string>(names);
+            //toSync.IntersectWith(m_staleFiles);
+
+            //// LUCENENET specific: Fsync breaks concurrency here.
+            //// Part of a solution suggested by Vincent Van Den Berghe: http://apache.markmail.org/message/hafnuhq2ydhfjmi2
+            ////foreach (var name in toSync)
+            ////{
+            ////    Fsync(name);
+            ////}
+
+            //// fsync the directory itsself, but only if there was any file fsynced before
+            //// (otherwise it can happen that the directory does not yet exist)!
+            //if (toSync.Count > 0)
             //{
-            //    Fsync(name);
+            //    IOUtils.Fsync(m_directory.FullName, true);
             //}
 
-            // fsync the directory itsself, but only if there was any file fsynced before
-            // (otherwise it can happen that the directory does not yet exist)!
-            if (toSync.Count > 0)
-            {
-                IOUtils.Fsync(m_directory.FullName, true);
-            }
-
-            m_staleFiles.ExceptWith(toSync);
+            //m_staleFiles.ExceptWith(toSync);
         }
 
         public override string GetLockID()
@@ -535,9 +545,12 @@ namespace Lucene.Net.Store
             // LUCENENET NOTE: FileStream doesn't have a way to set length
         }
 
-        protected virtual void Fsync(string name)
-        {
-            IOUtils.Fsync(Path.Combine(m_directory.FullName, name), false);            
-        }
+        // LUCENENET specific: Fsync is pointless in .NET, since we are 
+        // calling FileStream.Flush(true) before the stream is disposed
+        // which means we never need it at the point in Java where it is called.
+        //protected virtual void Fsync(string name)
+        //{
+        //    IOUtils.Fsync(Path.Combine(m_directory.FullName, name), false);           

+        //}
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b7c5f0b0/src/Lucene.Net/Util/IOUtils.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Util/IOUtils.cs b/src/Lucene.Net/Util/IOUtils.cs
index 9243104..125084f 100644
--- a/src/Lucene.Net/Util/IOUtils.cs
+++ b/src/Lucene.Net/Util/IOUtils.cs
@@ -522,80 +522,83 @@ namespace Lucene.Net.Util
             }
         }
 
-        /// <summary>
-        /// Ensure that any writes to the given file is written to the storage device that
contains it. </summary>
-        /// <param name="fileToSync"> The file to fsync </param>
-        /// <param name="isDir"> If <c>true</c>, the given file is a directory
(we open for read and ignore <see cref="IOException"/>s,
-        ///  because not all file systems and operating systems allow to fsync on a directory)
</param>
-        public static void Fsync(string fileToSync, bool isDir)
-        {
-            // Fsync does not appear to function properly for Windows and Linux platforms.
In Lucene version
-            // they catch this in IOException branch and return if the call is for the directory.

-            // In Lucene.Net the exception is UnauthorizedAccessException and is not handled
by
-            // IOException block. No need to even attempt to fsync, just return if the call
is for directory
-            if (isDir)
-            {
-                return;
-            }
-
-            var retryCount = 1;
-            while (true)
-            {
-                FileStream file = null;
-                bool success = false;
-                try
-                {
-                    // If the file is a directory we have to open read-only, for regular
files we must open r/w for the fsync to have an effect.
-                    // See http://blog.httrack.com/blog/2013/11/15/everything-you-always-wanted-to-know-about-fsync/
-                    file = new FileStream(fileToSync,
-                        FileMode.Open, // We shouldn't create a file when syncing.
-                        // Java version uses FileChannel which doesn't create the file if
it doesn't already exist, 
-                        // so there should be no reason for attempting to create it in Lucene.Net.
-                        FileAccess.Write,
-                        FileShare.ReadWrite);
-                    //FileSupport.Sync(file);
-                    file.Flush(true);
-                    success = true;
-                }
-#pragma warning disable 168
-                catch (IOException e)
-#pragma warning restore 168
-                {
-                    if (retryCount == 5)
-                    {
-                        throw;
-                    }
-#if !NETSTANDARD1_5
-                    try
-                    {
-#endif
-                        // Pause 5 msec
-                        Thread.Sleep(5);
-#if !NETSTANDARD1_5
-                    }
-                    catch (ThreadInterruptedException ie)
-                    {
-                        var ex = new ThreadInterruptedException(ie.ToString(), ie);
-                        ex.AddSuppressed(e);
-                        throw ex;
-                    }
-#endif
-                }
-                finally
-                {
-                    if (file != null)
-                    {
-                        file.Dispose();
-                    }
-                }
-
-                if (success)
-                {
-                    return;
-                }
-
-                retryCount++;
-            }
-        }
+        // LUCENENET specific: Fsync is pointless in .NET, since we are 
+        // calling FileStream.Flush(true) before the stream is disposed
+        // which means we never need it at the point in Java where it is called.
+        //        /// <summary>
+        //        /// Ensure that any writes to the given file is written to the storage
device that contains it. </summary>
+        //        /// <param name="fileToSync"> The file to fsync </param>
+        //        /// <param name="isDir"> If <c>true</c>, the given file
is a directory (we open for read and ignore <see cref="IOException"/>s,
+        //        ///  because not all file systems and operating systems allow to fsync
on a directory) </param>
+        //        public static void Fsync(string fileToSync, bool isDir)
+        //        {
+        //            // Fsync does not appear to function properly for Windows and Linux
platforms. In Lucene version
+        //            // they catch this in IOException branch and return if the call is
for the directory. 
+        //            // In Lucene.Net the exception is UnauthorizedAccessException and is
not handled by
+        //            // IOException block. No need to even attempt to fsync, just return
if the call is for directory
+        //            if (isDir)
+        //            {
+        //                return;
+        //            }
+
+        //            var retryCount = 1;
+        //            while (true)
+        //            {
+        //                FileStream file = null;
+        //                bool success = false;
+        //                try
+        //                {
+        //                    // If the file is a directory we have to open read-only, for
regular files we must open r/w for the fsync to have an effect.
+        //                    // See http://blog.httrack.com/blog/2013/11/15/everything-you-always-wanted-to-know-about-fsync/
+        //                    file = new FileStream(fileToSync,
+        //                        FileMode.Open, // We shouldn't create a file when syncing.
+        //                        // Java version uses FileChannel which doesn't create the
file if it doesn't already exist, 
+        //                        // so there should be no reason for attempting to create
it in Lucene.Net.
+        //                        FileAccess.Write,
+        //                        FileShare.ReadWrite);
+        //                    //FileSupport.Sync(file);
+        //                    file.Flush(true);
+        //                    success = true;
+        //                }
+        //#pragma warning disable 168
+        //                catch (IOException e)
+        //#pragma warning restore 168
+        //                {
+        //                    if (retryCount == 5)
+        //                    {
+        //                        throw;
+        //                    }
+        //#if !NETSTANDARD1_5
+        //                    try
+        //                    {
+        //#endif
+        //                        // Pause 5 msec
+        //                        Thread.Sleep(5);
+        //#if !NETSTANDARD1_5
+        //                    }
+        //                    catch (ThreadInterruptedException ie)
+        //                    {
+        //                        var ex = new ThreadInterruptedException(ie.ToString(),
ie);
+        //                        ex.AddSuppressed(e);
+        //                        throw ex;
+        //                    }
+        //#endif
+        //                }
+        //                finally
+        //                {
+        //                    if (file != null)
+        //                    {
+        //                        file.Dispose();
+        //                    }
+        //                }
+
+        //                if (success)
+        //                {
+        //                    return;
+        //                }
+
+        //                retryCount++;
+        //            }
+        //        }
     }
 }
\ No newline at end of file


Mime
View raw message