Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Lucene.Net/Store/FSDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,6 @@ public override void DeleteFile(string name)
EnsureOpen();
string file = Path.Combine(m_directory.FullName, name);

// LUCENENET Specific: See remarks for m_staleFiles field.
UninterruptableMonitor.Enter(m_syncLock);
try
{
// LUCENENET specific: We need to explicitly throw when the file has already been deleted,
Comment thread
marionoack marked this conversation as resolved.
Outdated
// since FileInfo doesn't do that for us.
// (An enhancement carried over from Lucene 8.2.0)
Expand All @@ -329,6 +325,13 @@ public override void DeleteFile(string name)
throw new FileNotFoundException("Cannot delete " + file + " because it doesn't exist.");
}

// LUCENENET specific: Do NOT hold m_syncLock while deleting. On a network share (SMB),
Comment thread
marionoack marked this conversation as resolved.
Outdated
// File.Delete can block for a long time (e.g. waiting for the server to break an
// oplock/lease on a file this client still has open). Holding m_syncLock here would
// block every concurrent Sync() and IndexOutput.Dispose() on this directory behind
// a single stalled delete, freezing the whole writer. Only the m_staleFiles
// bookkeeping below needs the lock (see remarks for the m_staleFiles field);
// upstream Java likewise performs the delete without any directory-wide lock.
try
{
File.Delete(file);
Expand All @@ -342,6 +345,9 @@ public override void DeleteFile(string name)
throw new IOException("Cannot delete " + file, e);
}

UninterruptableMonitor.Enter(m_syncLock);
try
{
m_staleFiles.Remove(name);
}
finally
Expand Down
8 changes: 7 additions & 1 deletion src/Lucene.Net/Store/MMapDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,13 @@ public override IndexInput OpenInput(string name, IOContext context)
EnsureOpen();
EnsureCanRead(name); // LUCENENET-specific: backported call site from Lucene 6.0.0
var file = Path.Combine(Directory.FullName, name); // LUCENENET specific: changed to use string file name instead of allocating a FileInfo (#832)
var fc = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
// LUCENENET specific: Add FileShare.Delete (a deliberate divergence from upstream Java's RandomAccessFile,
Comment thread
marionoack marked this conversation as resolved.
Outdated
// which omits it) to match SimpleFSDirectory, NIOFSDirectory and our other handles, giving Windows the same
// delete-while-open semantics POSIX already provides so index files can be deleted while a read handle is
// open (#1283). Without it, a pending delete of a still-mapped file on an SMB share can block inside
// File.Delete while the server waits for this client's lease break, which cannot complete while mapped
// views are active.
var fc = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
return new MMapIndexInput(this, "MMapIndexInput(path=\"" + file + "\")", fc);
}

Expand Down