Repository: lucenenet Updated Branches: refs/heads/master 012ffaab3 -> e67244aa2
BUG: Lucene.Net.Store.NativeFSLockFactory: Fixed concurrency issue with locks across multiple instances (solution provided by Vincent Van Den Burghe). Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/95a7505d Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/95a7505d Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/95a7505d Branch: refs/heads/master Commit: 95a7505d04e21d22e307cac5d0a1f6a957a0cf92 Parents: 012ffaa Author: Shad Storhaug <[email protected]> Authored: Thu Jul 20 16:46:51 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Thu Jul 20 16:46:51 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net/Store/NativeFSLockFactory.cs | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/95a7505d/src/Lucene.Net/Store/NativeFSLockFactory.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Store/NativeFSLockFactory.cs b/src/Lucene.Net/Store/NativeFSLockFactory.cs index 3459747..47b5233 100644 --- a/src/Lucene.Net/Store/NativeFSLockFactory.cs +++ b/src/Lucene.Net/Store/NativeFSLockFactory.cs @@ -89,16 +89,12 @@ namespace Lucene.Net.Store // LUCENENET: NativeFSLocks in Java are infact singletons; this is how we mimick that to track instances and make sure // IW.Unlock and IW.IsLocked works correctly - internal readonly ConcurrentDictionary<string, NativeFSLock> _locks = new ConcurrentDictionary<string, NativeFSLock>(); + internal static readonly ConcurrentDictionary<string, Lazy<NativeFSLock>> _locks = new ConcurrentDictionary<string, Lazy<NativeFSLock>>(); public override Lock MakeLock(string lockName) { - if (m_lockPrefix != null) - { - lockName = m_lockPrefix + "-" + lockName; - } - - return _locks.GetOrAdd(lockName, (s) => new NativeFSLock(this, m_lockDir, s)); + var path = new DirectoryInfo(System.IO.Path.Combine(m_lockDir.FullName, lockName)); + return _locks.GetOrAdd(path.FullName, s => new Lazy<NativeFSLock>(() => new NativeFSLock(this, m_lockDir, s))).Value; } public override void ClearLock(string lockName) @@ -191,16 +187,8 @@ namespace Lucene.Net.Store { if (channel != null) { - try - { - NativeFSLock _; - outerInstance._locks.TryRemove(path.FullName, out _); - } - finally - { - IOUtils.DisposeWhileHandlingException(channel); - channel = null; - } + IOUtils.DisposeWhileHandlingException(channel); + channel = null; bool tmpBool; if (File.Exists(path.FullName))
