You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/07/17 09:52:04 UTC
[2/3] lucenenet git commit: Lucene.Net.Store.FSDirectory: Removed
Fsync() method and m_staleFiles variable and all references to them
Lucene.Net.Store.FSDirectory: Removed Fsync() method and m_staleFiles variable and all references to them
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/bc295b0e
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/bc295b0e
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/bc295b0e
Branch: refs/heads/master
Commit: bc295b0e79c153d9dfa7e9f99a144db135a014f5
Parents: 4347872
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Mon Jul 17 15:06:35 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Mon Jul 17 15:06:35 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/bc295b0e/src/Lucene.Net/Store/FSDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Store/FSDirectory.cs b/src/Lucene.Net/Store/FSDirectory.cs
index 19f8e14..d023e0d 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()
@@ -540,9 +550,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/bc295b0e/src/Lucene.Net/Util/IOUtils.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Util/IOUtils.cs b/src/Lucene.Net/Util/IOUtils.cs
index 5907b60..27daafa 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 !NETSTANDARD
- try
- {
-#endif
- // Pause 5 msec
- Thread.Sleep(5);
-#if !NETSTANDARD
- }
- catch (ThreadInterruptedException ie)
- {
- var ex = new ThreadInterruptedException(ie.ToString(), ie);
- //ex.AddSuppressed(exc);
- 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 !NETSTANDARD
+ // try
+ // {
+ //#endif
+ // // Pause 5 msec
+ // Thread.Sleep(5);
+ //#if !NETSTANDARD
+ // }
+ // catch (ThreadInterruptedException ie)
+ // {
+ // var ex = new ThreadInterruptedException(ie.ToString(), ie);
+ // //ex.AddSuppressed(exc);
+ // throw ex;
+ // }
+ //#endif
+ // }
+ // finally
+ // {
+ // if (file != null)
+ // {
+ // file.Dispose();
+ // }
+ // }
+
+ // if (success)
+ // {
+ // return;
+ // }
+
+ // retryCount++;
+ // }
+ // }
}
}
\ No newline at end of file