lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [42/50] [abbrv] lucenenet git commit: BUG: IndexWriter.ReaderPool.DropAll() was failing to remove elements from the dictionary as was specified in the comments. As a result, the dictionary was not in the right state if an exception is thrown. Fixed this
Date Wed, 15 Mar 2017 23:50:24 GMT
BUG: IndexWriter.ReaderPool.DropAll() was failing to remove elements from the dictionary as
was specified in the comments. As a result, the dictionary was not in the right state if an
exception is thrown. Fixed this by keeping track of what has been iterated over and removing
them after iteration is complete (whether that is due to an exception or not).


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

Branch: refs/heads/api-work
Commit: a4ee2550421f060b571142f64d972721119797a4
Parents: 7dc5180
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Thu Mar 16 01:38:11 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Thu Mar 16 01:38:11 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Index/IndexWriter.cs | 130 ++++++++++++++------------
 1 file changed, 70 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a4ee2550/src/Lucene.Net.Core/Index/IndexWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/IndexWriter.cs b/src/Lucene.Net.Core/Index/IndexWriter.cs
index fa9cb72..9593de8 100644
--- a/src/Lucene.Net.Core/Index/IndexWriter.cs
+++ b/src/Lucene.Net.Core/Index/IndexWriter.cs
@@ -277,7 +277,7 @@ namespace Lucene.Net.Index
         // to allow users to query an IndexWriter settings.
         private readonly LiveIndexWriterConfig config;
 
-        internal virtual DirectoryReader Reader
+        internal virtual DirectoryReader Reader // LUCENENET TODO API: Change to GetReader()
         {
             get
             {
@@ -560,78 +560,88 @@ namespace Lucene.Net.Index
                     Exception priorE = null;
                     IEnumerator<KeyValuePair<SegmentCommitInfo, ReadersAndUpdates>>
it = readerMap.GetEnumerator();
 
-                    //Using outer try-catch to avoid deleting as iterating to avoid item
corruption. Whether or not
-                    //an exception is encountered in the outer while-loop, the ReaderMap
will always be Clear()ed out
-                    try
+                    // LUCENENET specific - Since an enumerator doesn't allow you to delete

+                    // immediately, keep track of which elements we have iterated over so
+                    // we can delete them immediately before throwing exceptions or at the
+                    // end of the block.
+                    IList<KeyValuePair<SegmentCommitInfo, ReadersAndUpdates>>
toDelete = new List<KeyValuePair<SegmentCommitInfo, ReadersAndUpdates>>();
+
+                    while (it.MoveNext())
                     {
-                        while (it.MoveNext())
-                        {
-                            ReadersAndUpdates rld = it.Current.Value;
+                        ReadersAndUpdates rld = it.Current.Value;
 
-                            try
+                        try
+                        {
+                            if (doSave && rld.WriteLiveDocs(outerInstance.directory))
// Throws IOException
                             {
-                                if (doSave && rld.WriteLiveDocs(outerInstance.directory))
-                                {
-                                    // Make sure we only write del docs and field updates
for a live segment:
-                                    Debug.Assert(InfoIsLive(rld.Info));
-                                    // Must checkpoint because we just
-                                    // created new _X_N.del and field updates files;
-                                    // don't call IW.checkpoint because that also
-                                    // increments SIS.version, which we do not want to
-                                    // do here: it was done previously (after we
-                                    // invoked BDS.applyDeletes), whereas here all we
-                                    // did was move the state to disk:
-                                    outerInstance.CheckpointNoSIS();
-                                }
+                                // Make sure we only write del docs and field updates for
a live segment:
+                                Debug.Assert(InfoIsLive(rld.Info));
+                                // Must checkpoint because we just
+                                // created new _X_N.del and field updates files;
+                                // don't call IW.checkpoint because that also
+                                // increments SIS.version, which we do not want to
+                                // do here: it was done previously (after we
+                                // invoked BDS.applyDeletes), whereas here all we
+                                // did was move the state to disk:
+                                outerInstance.CheckpointNoSIS(); // Throws IOException
                             }
-                            catch (Exception t)
+                        }
+                        catch (Exception t)
+                        {
+                            if (doSave)
                             {
-                                if (doSave)
-                                {
-                                    IOUtils.ReThrow(t);
-                                }
-                                else if (priorE == null)
-                                {
-                                    priorE = t;
-                                }
+                                // LUCENENET specific: remove all of the
+                                // elements we have iterated over so far
+                                // before throwing an exception.
+                                readerMap.RemoveAll(toDelete);
+                                IOUtils.ReThrow(t);
                             }
+                            else if (priorE == null)
+                            {
+                                priorE = t;
+                            }
+                        }
 
-                            // Important to remove as-we-go, not with .clear()
-                            // in the end, in case we hit an exception;
-                            // otherwise we could over-decref if close() is
-                            // called again:
-                            //ReaderMap.Remove(it.Current);
-
-                            // NOTE: it is allowed that these decRefs do not
-                            // actually close the SRs; this happens when a
-                            // near real-time reader is kept open after the
-                            // IndexWriter instance is closed:
-                            try
+                        // Important to remove as-we-go, not with .clear()
+                        // in the end, in case we hit an exception;
+                        // otherwise we could over-decref if close() is
+                        // called again:
+
+                        // LUCENENET specific - we cannot delete immediately,
+                        // so we store the elements that are iterated over and
+                        // delete as soon as we are done iterating (whether
+                        // that is because of an exception or not).
+                        toDelete.Add(it.Current);
+
+                        // NOTE: it is allowed that these decRefs do not
+                        // actually close the SRs; this happens when a
+                        // near real-time reader is kept open after the
+                        // IndexWriter instance is closed:
+                        try
+                        {
+                            rld.DropReaders(); // Throws IOException
+                        }
+                        catch (Exception t)
+                        {
+                            if (doSave)
                             {
-                                rld.DropReaders();
+                                // LUCENENET specific: remove all of the
+                                // elements we have iterated over so far
+                                // before throwing an exception.
+                                readerMap.RemoveAll(toDelete);
+                                IOUtils.ReThrow(t);
                             }
-                            catch (Exception t)
+                            else if (priorE == null)
                             {
-                                if (doSave)
-                                {
-                                    IOUtils.ReThrow(t);
-                                }
-                                else if (priorE == null)
-                                {
-                                    priorE = t;
-                                }
+                                priorE = t;
                             }
                         }
                     }
-#pragma warning disable 168
-                    catch (Exception disruption)
-#pragma warning restore 168
-                    {
-                    }
-                    finally
-                    {
-                        readerMap.Clear();
-                    }
+                    // LUCENENET specific: remove all of the
+                    // elements we have iterated over so far
+                    // before possibly throwing an exception.
+                    readerMap.RemoveAll(toDelete);
+
                     Debug.Assert(readerMap.Count == 0);
                     IOUtils.ReThrow(priorE);
                 }


Mime
View raw message