lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Currens <currens.ch...@gmail.com>
Subject Re: svn commit: r1353025 - in /incubator/lucene.net/trunk/src/core: Search/FieldCacheImpl.cs Store/NativeFSLockFactory.cs
Date Mon, 25 Jun 2012 16:53:25 GMT
Luc,

Sorry about that.  There were some merge issues with one of the patches (I
had to manually copy the changes), and I think I just overlooked
the Lucenenet-484-NativeFSLockFactory.patch file because of that confusion.
 It's committed now.

In regards to OSX also getting an intermittent "Permission Denied"
exception, I'm going to go out on a limb here, and say that because of the
wording, it's likely an UnauthorizedAccessException.  I've added an
additional catch block for UnauthorizedAccessException, for this reason.
 Tests still pass, and we have less to worry about when we're able to
confirm mono support now.  Thanks for that heads up.


Thanks,
Christopher

On Mon, Jun 25, 2012 at 1:55 AM, Vanlerberghe, Luc <
Luc.Vanlerberghe@bvdinfo.com> wrote:

> Hi Christopher,
>
> Thanks for reviewing and applying my patches, but something must have gone
> wrong with the patch for NativeFSLockFactory: I see only whitespace changes
> in the patch you applied, and not the extra "catch
> (System.UnauthorizedAccessException e) { ... }"
>
> BTW. In the code there's a similar remark about OS X sometimes getting an
> intermittent "Permission Denied" exception.  Perhaps someone with suitable
> hardware should check if this "Permission Denied" exception derives from
> IOException or is also an UnauthorizedAccessException...
>
> Luc
>
>
> -----Original Message-----
> From: ccurrens@apache.org [mailto:ccurrens@apache.org]
> Sent: vrijdag 22 juni 2012 22:59
> To: lucene-net-commits@lucene.apache.org
> Subject: svn commit: r1353025 - in /incubator/lucene.net/trunk/src/core:
> Search/FieldCacheImpl.cs Store/NativeFSLockFactory.cs
>
> Author: ccurrens
> Date: Fri Jun 22 20:58:40 2012
> New Revision: 1353025
>
> URL: http://svn.apache.org/viewvc?rev=1353025&view=rev
> Log:
> [LUCENENET-484] - Added patch from Luc Vanlerberghe fixing interittent
> failures in TestSort.TestParallelMultiSort
>
> Modified:
>    incubator/lucene.net/trunk/src/core/Search/FieldCacheImpl.cs
>    incubator/lucene.net/trunk/src/core/Store/NativeFSLockFactory.cs
>
> Modified: incubator/lucene.net/trunk/src/core/Search/FieldCacheImpl.cs
> URL:
> http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Search/FieldCacheImpl.cs?rev=1353025&r1=1353024&r2=1353025&view=diff
>
> ==============================================================================
> --- incubator/lucene.net/trunk/src/core/Search/FieldCacheImpl.cs(original)
> +++ incubator/lucene.net/trunk/src/core/Search/FieldCacheImpl.cs Fri Jun
> 22 20:58:40 2012
> @@ -31,27 +31,27 @@ using StringHelper = Lucene.Net.Util.Str
>
>  namespace Lucene.Net.Search
>  {
> -
> -       /// <summary> Expert: The default cache implementation, storing
> all values in memory.
> -       /// A WeakDictionary is used for storage.
> -       ///
> -       /// <p/>Created: May 19, 2004 4:40:36 PM
> -       ///
> -       /// </summary>
> -       /// <since>   lucene 1.4
> -       /// </since>
> -       class FieldCacheImpl : FieldCache
> -       {
> -
> -               private IDictionary<Type, Cache> caches;
> -               internal FieldCacheImpl()
> -               {
> -                       Init();
> -               }
> -               private void  Init()
> -               {
> -                       lock (this)
> -                       {
> +
> +    /// <summary> Expert: The default cache implementation, storing all
> values in memory.
> +    /// A WeakDictionary is used for storage.
> +    ///
> +    /// <p/>Created: May 19, 2004 4:40:36 PM
> +    ///
> +    /// </summary>
> +    /// <since>   lucene 1.4
> +    /// </since>
> +    class FieldCacheImpl : FieldCache
> +    {
> +        private IDictionary<Type, Cache> caches;
> +
> +        internal FieldCacheImpl()
> +        {
> +            Init();
> +        }
> +        private void  Init()
> +        {
> +            lock (this)
> +            {
>                 caches = new HashMap<Type, Cache>(7);
>                 caches[typeof(sbyte)] = new ByteCache(this);
>                 caches[typeof(short)] = new ShortCache(this);
> @@ -61,121 +61,138 @@ namespace Lucene.Net.Search
>                 caches[typeof(double)] = new DoubleCache(this);
>                 caches[typeof(string)] = new StringCache(this);
>                 caches[typeof(StringIndex)] = new StringIndexCache(this);
> -                       }
> -               }
> -
> -               public virtual void  PurgeAllCaches()
> -               {
> -                       Init();
> -               }
> +            }
> +        }
> +
> +        // lucene.net: java version 3.0.3 with patch in rev. 912330
> applied:
> +        // uschindler 21/02/2010 12:16:42 LUCENE-2273: Fixed bug in
> FieldCacheImpl.getCacheEntries() that used
> +        //                     WeakHashMap incorrectly and lead to
> ConcurrentModificationException
> +        public virtual void  PurgeAllCaches()
> +        {
> +            lock (this)
> +            {
> +                Init();
> +            }
> +        }
>
> +        // lucene.net: java version 3.0.3 with patch in rev. 912330
> applied:
> +        // uschindler 21/02/2010 12:16:42 LUCENE-2273: Fixed bug in
> FieldCacheImpl.getCacheEntries() that used
> +        //                     WeakHashMap incorrectly and lead to
> ConcurrentModificationException
>         public void Purge(IndexReader r)
>         {
> -            foreach (Cache c in caches.Values)
> +            lock (this)
>             {
> -                c.Purge(r);
> +                foreach (Cache c in caches.Values)
> +                {
> +                    c.Purge(r);
> +                }
>             }
>         }
> -
> -               public virtual CacheEntry[] GetCacheEntries()
> -               {
> -                       IList<CacheEntry> result = new
> List<CacheEntry>(17);
> -                       foreach(var cacheType in caches.Keys)
> -                       {
> -                           var cache = caches[cacheType];
> -                foreach(var readerKey in cache.readerCache.Keys)
> -                               {
> -                                       // we've now materialized a hard
> ref
> -                                       // innerKeys was backed by
> WeakDictionary, sanity check
> -                                       // that it wasn't GCed before we
> made hard ref
> -                    if (null != readerKey &&
> cache.readerCache.ContainsKey(readerKey))
> -                                       {
> -                                               var innerCache =
> cache.readerCache[readerKey];
> -                        foreach (KeyValuePair<Entry, Object> mapEntry in
> innerCache)
> -                                               {
> -                                                       Entry entry =
> mapEntry.Key;
> -                                                       result.Add(new
> CacheEntryImpl(readerKey, entry.field, cacheType, entry.custom,
> mapEntry.Value));
> -                                               }
> -                                       }
> -                               }
> -                       }
> -                       return result.ToArray();
> -               }
> -
> -               private sealed class CacheEntryImpl : CacheEntry
> -               {
> -                       private System.Object readerKey;
> -                       private System.String fieldName;
> -                       private System.Type cacheType;
> -                       private System.Object custom;
> -                       private System.Object value;
> -                       internal CacheEntryImpl(System.Object readerKey,
> System.String fieldName, System.Type cacheType, System.Object custom,
> System.Object value)
> -                       {
> -                               this.readerKey = readerKey;
> -                               this.fieldName = fieldName;
> -                               this.cacheType = cacheType;
> -                               this.custom = custom;
> -                               this.value = value;
> -
> -                               // :HACK: for testing.
> -                               //         if (null != locale ||
> SortField.CUSTOM != sortFieldType) {
> -                               //           throw new
> RuntimeException("Locale/sortFieldType: " + this);
> -                               //         }
> -                       }
> -
> -                   public override object ReaderKey
> -                   {
> -                       get { return readerKey; }
> -                   }
> -
> -                   public override string FieldName
> -                   {
> -                       get { return fieldName; }
> -                   }
> -
> -                   public override Type CacheType
> -                   {
> -                       get { return cacheType; }
> -                   }
> -
> -                   public override object Custom
> -                   {
> -                       get { return custom; }
> -                   }
> -
> -                   public override object Value
> -                   {
> -                       get { return value; }
> -                   }
> -               }
> -
> -               /// <summary> Hack: When thrown from a Parser
> (NUMERIC_UTILS_* ones), this stops
> -               /// processing terms and returns the current FieldCache
> -               /// array.
> -               /// </summary>
> -               [Serializable]
> -               internal sealed class
> StopFillCacheException:System.SystemException
> -               {
> -               }
> -
> -               /// <summary>Expert: Internal cache. </summary>
> -               internal abstract class Cache
> -               {
> -                       internal Cache()
> -                       {
> -                               this.wrapper = null;
> -                       }
> -
> -                       internal Cache(FieldCache wrapper)
> -                       {
> -                               this.wrapper = wrapper;
> -                       }
> -
> -                       internal FieldCache wrapper;
> +
> +        // lucene.net: java version 3.0.3 with patch in rev. 912330
> applied:
> +        // uschindler 21/02/2010 12:16:42 LUCENE-2273: Fixed bug in
> FieldCacheImpl.getCacheEntries() that used
> +        //                     WeakHashMap incorrectly and lead to
> ConcurrentModificationException
> +        public virtual CacheEntry[] GetCacheEntries()
> +        {
> +            lock (this)
> +            {
> +                IList<CacheEntry> result = new List<CacheEntry>(17);
> +                foreach (var cacheEntry in caches)
> +                {
> +                    var cache = cacheEntry.Value;
> +                    var cacheType = cacheEntry.Key;
> +                    lock (cache.readerCache)
> +                    {
> +                        foreach (var readerCacheEntry in
> cache.readerCache)
> +                        {
> +                            var readerKey = readerCacheEntry.Key;
> +                            var innerCache = readerCacheEntry.Value;
> +                            foreach (var mapEntry in innerCache)
> +                            {
> +                                Entry entry = mapEntry.Key;
> +                                result.Add(new CacheEntryImpl(readerKey,
> entry.field, cacheType, entry.custom, mapEntry.Value));
> +                            }
> +                        }
> +                    }
> +                }
> +                return result.ToArray();
> +            }
> +        }
> +
> +        private sealed class CacheEntryImpl : CacheEntry
> +        {
> +            private System.Object readerKey;
> +            private System.String fieldName;
> +            private System.Type cacheType;
> +            private System.Object custom;
> +            private System.Object value;
> +            internal CacheEntryImpl(System.Object readerKey,
> System.String fieldName, System.Type cacheType, System.Object custom,
> System.Object value)
> +            {
> +                this.readerKey = readerKey;
> +                this.fieldName = fieldName;
> +                this.cacheType = cacheType;
> +                this.custom = custom;
> +                this.value = value;
> +
> +                // :HACK: for testing.
> +                //         if (null != locale || SortField.CUSTOM !=
> sortFieldType) {
> +                //           throw new
> RuntimeException("Locale/sortFieldType: " + this);
> +                //         }
> +            }
> +
> +            public override object ReaderKey
> +            {
> +                get { return readerKey; }
> +            }
> +
> +            public override string FieldName
> +            {
> +                get { return fieldName; }
> +            }
> +
> +            public override Type CacheType
> +            {
> +                get { return cacheType; }
> +            }
> +
> +            public override object Custom
> +            {
> +                get { return custom; }
> +            }
> +
> +            public override object Value
> +            {
> +                get { return value; }
> +            }
> +        }
> +
> +        /// <summary> Hack: When thrown from a Parser (NUMERIC_UTILS_*
> ones), this stops
> +        /// processing terms and returns the current FieldCache
> +        /// array.
> +        /// </summary>
> +        [Serializable]
> +        internal sealed class
> StopFillCacheException:System.SystemException
> +        {
> +        }
> +
> +        /// <summary>Expert: Internal cache. </summary>
> +        internal abstract class Cache
> +        {
> +            internal Cache()
> +            {
> +                this.wrapper = null;
> +            }
> +
> +            internal Cache(FieldCache wrapper)
> +            {
> +                this.wrapper = wrapper;
> +            }
> +
> +            internal FieldCache wrapper;
>
>             internal IDictionary<object, IDictionary<Entry, object>>
> readerCache = new WeakDictionary<object, IDictionary<Entry, object>>();
> -
> -                       protected internal abstract System.Object
> CreateValue(IndexReader reader, Entry key);
> +
> +            protected internal abstract System.Object
> CreateValue(IndexReader reader, Entry key);
>
>             /** Remove this reader from the cache, if present. */
>             public void Purge(IndexReader r)
> @@ -186,100 +203,100 @@ namespace Lucene.Net.Search
>                     readerCache.Remove(readerKey);
>                 }
>             }
> -
> -                       public virtual System.Object Get(IndexReader
> reader, Entry key)
> -                       {
> -                               IDictionary<Entry, object> innerCache;
> -                               System.Object value;
> -                               System.Object readerKey =
> reader.FieldCacheKey;
> -                               lock (readerCache)
> -                               {
> -                                       innerCache =
> readerCache[readerKey];
> -                                       if (innerCache == null)
> -                                       {
> -                                               innerCache = new
> HashMap<Entry, object>();
> -                                               readerCache[readerKey] =
> innerCache;
> -                                               value = null;
> -                                       }
> -                                       else
> -                                       {
> -                                               value = innerCache[key];
> -                                       }
> -                                       if (value == null)
> -                                       {
> -                                               value = new
> CreationPlaceholder();
> -                                               innerCache[key] = value;
> -                                       }
> -                               }
> -                               if (value is CreationPlaceholder)
> -                               {
> -                                       lock (value)
> -                                       {
> -                                               CreationPlaceholder
> progress = (CreationPlaceholder) value;
> -                                               if (progress.value_Renamed
> == null)
> -                                               {
> -
> progress.value_Renamed = CreateValue(reader, key);
> -                                                       lock (readerCache)
> -                                                       {
> -
> innerCache[key] = progress.value_Renamed;
> -                                                       }
> -
> -                                                       // Only check if
> key.custom (the parser) is
> -                                                       // non-null; else,
> we check twice for a single
> -                                                       // call to
> FieldCache.getXXX
> -                                                       if (key.custom !=
> null && wrapper != null)
> -                                                       {
> -
> System.IO.StreamWriter infoStream = wrapper.InfoStream;
> -                                                               if
> (infoStream != null)
> -                                                               {
> -
> PrintNewInsanity(infoStream, progress.value_Renamed);
> -                                                               }
> -                                                       }
> -                                               }
> -                                               return
> progress.value_Renamed;
> -                                       }
> -                               }
> -                               return value;
> -                       }
> -
> -                       private void
>  PrintNewInsanity(System.IO.StreamWriter infoStream, System.Object
> value_Renamed)
> -                       {
> -                               FieldCacheSanityChecker.Insanity[]
> insanities = FieldCacheSanityChecker.CheckSanity(wrapper);
> -                               for (int i = 0; i < insanities.Length; i++)
> -                               {
> -                                       FieldCacheSanityChecker.Insanity
> insanity = insanities[i];
> -                                       CacheEntry[] entries =
> insanity.GetCacheEntries();
> -                                       for (int j = 0; j <
> entries.Length; j++)
> -                                       {
> -                                               if (entries[j].Value ==
> value_Renamed)
> -                                               {
> -                                                       // OK this
> insanity involves our entry
> -
> infoStream.WriteLine("WARNING: new FieldCache insanity created\nDetails: "
> + insanity.ToString());
> -
> infoStream.WriteLine("\nStack:\n");
> +
> +            public virtual System.Object Get(IndexReader reader, Entry
> key)
> +            {
> +                IDictionary<Entry, object> innerCache;
> +                System.Object value;
> +                System.Object readerKey = reader.FieldCacheKey;
> +                lock (readerCache)
> +                {
> +                    innerCache = readerCache[readerKey];
> +                    if (innerCache == null)
> +                    {
> +                        innerCache = new HashMap<Entry, object>();
> +                        readerCache[readerKey] = innerCache;
> +                        value = null;
> +                    }
> +                    else
> +                    {
> +                        value = innerCache[key];
> +                    }
> +                    if (value == null)
> +                    {
> +                        value = new CreationPlaceholder();
> +                        innerCache[key] = value;
> +                    }
> +                }
> +                if (value is CreationPlaceholder)
> +                {
> +                    lock (value)
> +                    {
> +                        CreationPlaceholder progress =
> (CreationPlaceholder) value;
> +                        if (progress.value_Renamed == null)
> +                        {
> +                            progress.value_Renamed = CreateValue(reader,
> key);
> +                            lock (readerCache)
> +                            {
> +                                innerCache[key] = progress.value_Renamed;
> +                            }
> +
> +                            // Only check if key.custom (the parser) is
> +                            // non-null; else, we check twice for a single
> +                            // call to FieldCache.getXXX
> +                            if (key.custom != null && wrapper != null)
> +                            {
> +                                System.IO.StreamWriter infoStream =
> wrapper.InfoStream;
> +                                if (infoStream != null)
> +                                {
> +                                    PrintNewInsanity(infoStream,
> progress.value_Renamed);
> +                                }
> +                            }
> +                        }
> +                        return progress.value_Renamed;
> +                    }
> +                }
> +                return value;
> +            }
> +
> +            private void  PrintNewInsanity(System.IO.StreamWriter
> infoStream, System.Object value_Renamed)
> +            {
> +                FieldCacheSanityChecker.Insanity[] insanities =
> FieldCacheSanityChecker.CheckSanity(wrapper);
> +                for (int i = 0; i < insanities.Length; i++)
> +                {
> +                    FieldCacheSanityChecker.Insanity insanity =
> insanities[i];
> +                    CacheEntry[] entries = insanity.GetCacheEntries();
> +                    for (int j = 0; j < entries.Length; j++)
> +                    {
> +                        if (entries[j].Value == value_Renamed)
> +                        {
> +                            // OK this insanity involves our entry
> +                            infoStream.WriteLine("WARNING: new FieldCache
> insanity created\nDetails: " + insanity.ToString());
> +                            infoStream.WriteLine("\nStack:\n");
>                             infoStream.WriteLine(new System.Exception());
> -                                                       break;
> -                                               }
> -                                       }
> -                               }
> -                       }
> -               }
> -
> -               /// <summary>Expert: Every composite-key in the internal
> cache is of this type. </summary>
> -               protected internal class Entry
> -               {
> -                       internal System.String field; // which Fieldable
> -                       internal System.Object custom; // which custom
> comparator or parser
> -
> -                       /// <summary>Creates one of these objects for a
> custom comparator/parser. </summary>
> -                       internal Entry(System.String field, System.Object
> custom)
> -                       {
> -                               this.field = StringHelper.Intern(field);
> -                               this.custom = custom;
> -                       }
> -
> -                       /// <summary>Two of these are equal iff they
> reference the same field and type. </summary>
> -                       public  override bool Equals(System.Object o)
> -                       {
> +                            break;
> +                        }
> +                    }
> +                }
> +            }
> +        }
> +
> +        /// <summary>Expert: Every composite-key in the internal cache is
> of this type. </summary>
> +        protected internal class Entry
> +        {
> +            internal System.String field; // which Fieldable
> +            internal System.Object custom; // which custom comparator or
> parser
> +
> +            /// <summary>Creates one of these objects for a custom
> comparator/parser. </summary>
> +            internal Entry(System.String field, System.Object custom)
> +            {
> +                this.field = StringHelper.Intern(field);
> +                this.custom = custom;
> +            }
> +
> +            /// <summary>Two of these are equal iff they reference the
> same field and type. </summary>
> +            public  override bool Equals(System.Object o)
> +            {
>                 if (o is Entry)
>                 {
>                     Entry other = (Entry) o;
> @@ -296,546 +313,546 @@ namespace Lucene.Net.Search
>                         }
>                     }
>                 }
> -                           return false;
> -                       }
> -
> -                       /// <summary>Composes a hashcode based on the
> field and type. </summary>
> -                       public override int GetHashCode()
> -                       {
> -                               return field.GetHashCode() ^  (custom ==
> null?0:custom.GetHashCode());
> -                       }
> -               }
> -
> -               // inherit javadocs
> -               public virtual sbyte[] GetBytes(IndexReader reader,
> System.String field)
> -               {
> -                       return GetBytes(reader, field, null);
> -               }
> -
> -               // inherit javadocs
> -               public virtual sbyte[] GetBytes(IndexReader reader,
> System.String field, ByteParser parser)
> -               {
> -                       return (sbyte[]) caches[typeof(sbyte)].Get(reader,
> new Entry(field, parser));
> -               }
> -
> -               internal sealed class ByteCache:Cache
> -               {
> -                       internal ByteCache(FieldCache
> wrapper):base(wrapper)
> -                       {
> -                       }
> -                       protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> -                       {
> -                               Entry entry = entryKey;
> -                               System.String field = entry.field;
> -                               ByteParser parser = (ByteParser)
> entry.custom;
> -                               if (parser == null)
> -                               {
> -                                       return wrapper.GetBytes(reader,
> field, Lucene.Net.Search.FieldCache_Fields.DEFAULT_BYTE_PARSER);
> -                               }
> -                               sbyte[] retArray = new
> sbyte[reader.MaxDoc];
> -                               TermDocs termDocs = reader.TermDocs();
> -                               TermEnum termEnum = reader.Terms(new
> Term(field));
> -                               try
> -                               {
> -                                       do
> -                                       {
> -                                               Term term =
> termEnum.Term();
> -                                               if (term == null ||
> (System.Object) term.Field != (System.Object) field)
> -                                                       break;
> -                                               sbyte termval =
> parser.ParseByte(term.Text);
> -                                               termDocs.Seek(termEnum);
> -                                               while (termDocs.Next())
> -                                               {
> -
> retArray[termDocs.Doc] = termval;
> -                                               }
> -                                       }
> -                                       while (termEnum.Next());
> -                               }
> -                               catch (StopFillCacheException stop)
> -                               {
> -                               }
> -                               finally
> -                               {
> -                                       termDocs.Close();
> -                                       termEnum.Close();
> -                               }
> -                               return retArray;
> -                       }
> -               }
> -
> -
> -               // inherit javadocs
> -               public virtual short[] GetShorts(IndexReader reader,
> System.String field)
> -               {
> -                       return GetShorts(reader, field, null);
> -               }
> -
> -               // inherit javadocs
> -               public virtual short[] GetShorts(IndexReader reader,
> System.String field, ShortParser parser)
> -               {
> -                       return (short[]) caches[typeof(short)].Get(reader,
> new Entry(field, parser));
> -               }
> -
> -               internal sealed class ShortCache:Cache
> -               {
> -                       internal ShortCache(FieldCache
> wrapper):base(wrapper)
> -                       {
> -                       }
> -
> -                       protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> -                       {
> -                               Entry entry = entryKey;
> -                               System.String field = entry.field;
> -                               ShortParser parser = (ShortParser)
> entry.custom;
> -                               if (parser == null)
> -                               {
> -                                       return wrapper.GetShorts(reader,
> field, Lucene.Net.Search.FieldCache_Fields.DEFAULT_SHORT_PARSER);
> -                               }
> -                               short[] retArray = new
> short[reader.MaxDoc];
> -                               TermDocs termDocs = reader.TermDocs();
> -                               TermEnum termEnum = reader.Terms(new
> Term(field));
> -                               try
> -                               {
> -                                       do
> -                                       {
> -                                               Term term =
> termEnum.Term();
> -                                               if (term == null ||
> (System.Object) term.Field != (System.Object) field)
> -                                                       break;
> -                                               short termval =
> parser.ParseShort(term.Text);
> -                                               termDocs.Seek(termEnum);
> -                                               while (termDocs.Next())
> -                                               {
> -
> retArray[termDocs.Doc] = termval;
> -                                               }
> -                                       }
> -                                       while (termEnum.Next());
> -                               }
> -                               catch (StopFillCacheException stop)
> -                               {
> -                               }
> -                               finally
> -                               {
> -                                       termDocs.Close();
> -                                       termEnum.Close();
> -                               }
> -                               return retArray;
> -                       }
> -               }
> -
> -
> -               // inherit javadocs
> -               public virtual int[] GetInts(IndexReader reader,
> System.String field)
> -               {
> -                       return GetInts(reader, field, null);
> -               }
> -
> -               // inherit javadocs
> -               public virtual int[] GetInts(IndexReader reader,
> System.String field, IntParser parser)
> -               {
> -                       return (int[]) caches[typeof(int)].Get(reader, new
> Entry(field, parser));
> -               }
> -
> -               internal sealed class IntCache:Cache
> -               {
> -                       internal IntCache(FieldCache wrapper):base(wrapper)
> -                       {
> -                       }
> -
> -                       protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> -                       {
> -                               Entry entry = entryKey;
> -                               System.String field = entry.field;
> -                               IntParser parser = (IntParser)
> entry.custom;
> -                               if (parser == null)
> -                               {
> -                                       try
> -                                       {
> -                                               return
> wrapper.GetInts(reader, field,
> Lucene.Net.Search.FieldCache_Fields.DEFAULT_INT_PARSER);
> -                                       }
> -                                       catch (System.FormatException ne)
> -                                       {
> -                                               return
> wrapper.GetInts(reader, field,
> Lucene.Net.Search.FieldCache_Fields.NUMERIC_UTILS_INT_PARSER);
> -                                       }
> -                               }
> -                               int[] retArray = null;
> -                               TermDocs termDocs = reader.TermDocs();
> -                               TermEnum termEnum = reader.Terms(new
> Term(field));
> -                               try
> -                               {
> -                                       do
> -                                       {
> -                                               Term term =
> termEnum.Term();
> -                                               if (term == null ||
> (System.Object) term.Field != (System.Object) field)
> -                                                       break;
> -                                               int termval =
> parser.ParseInt(term.Text);
> -                                               if (retArray == null)
> -                                               // late init
> -                                                       retArray = new
> int[reader.MaxDoc];
> -                                               termDocs.Seek(termEnum);
> -                                               while (termDocs.Next())
> -                                               {
> -
> retArray[termDocs.Doc] = termval;
> -                                               }
> -                                       }
> -                                       while (termEnum.Next());
> -                               }
> -                               catch (StopFillCacheException stop)
> -                               {
> -                               }
> -                               finally
> -                               {
> -                                       termDocs.Close();
> -                                       termEnum.Close();
> -                               }
> -                               if (retArray == null)
> -                               // no values
> -                                       retArray = new int[reader.MaxDoc];
> -                               return retArray;
> -                       }
> -               }
> -
> -
> -
> -               // inherit javadocs
> -               public virtual float[] GetFloats(IndexReader reader,
> System.String field)
> -               {
> -                       return GetFloats(reader, field, null);
> -               }
> -
> -               // inherit javadocs
> -               public virtual float[] GetFloats(IndexReader reader,
> System.String field, FloatParser parser)
> -               {
> -
> -                       return (float[]) caches[typeof(float)].Get(reader,
> new Entry(field, parser));
> -               }
> -
> -               internal sealed class FloatCache:Cache
> -               {
> -                       internal FloatCache(FieldCache
> wrapper):base(wrapper)
> -                       {
> -                       }
> -
> -                       protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> -                       {
> -                               Entry entry = entryKey;
> -                               System.String field = entry.field;
> -                               FloatParser parser = (FloatParser)
> entry.custom;
> -                               if (parser == null)
> -                               {
> -                                       try
> -                                       {
> -                                               return
> wrapper.GetFloats(reader, field,
> Lucene.Net.Search.FieldCache_Fields.DEFAULT_FLOAT_PARSER);
> -                                       }
> -                                       catch (System.FormatException ne)
> -                                       {
> -                                               return
> wrapper.GetFloats(reader, field,
> Lucene.Net.Search.FieldCache_Fields.NUMERIC_UTILS_FLOAT_PARSER);
> -                                       }
> -                               }
> -                               float[] retArray = null;
> -                               TermDocs termDocs = reader.TermDocs();
> -                               TermEnum termEnum = reader.Terms(new
> Term(field));
> -                               try
> -                               {
> -                                       do
> -                                       {
> -                                               Term term =
> termEnum.Term();
> -                                               if (term == null ||
> (System.Object) term.Field != (System.Object) field)
> -                                                       break;
> -                                               float termval =
> parser.ParseFloat(term.Text);
> -                                               if (retArray == null)
> -                                               // late init
> -                                                       retArray = new
> float[reader.MaxDoc];
> -                                               termDocs.Seek(termEnum);
> -                                               while (termDocs.Next())
> -                                               {
> -
> retArray[termDocs.Doc] = termval;
> -                                               }
> -                                       }
> -                                       while (termEnum.Next());
> -                               }
> -                               catch (StopFillCacheException stop)
> -                               {
> -                               }
> -                               finally
> -                               {
> -                                       termDocs.Close();
> -                                       termEnum.Close();
> -                               }
> -                               if (retArray == null)
> -                               // no values
> -                                       retArray = new
> float[reader.MaxDoc];
> -                               return retArray;
> -                       }
> -               }
> -
> -
> -
> -               public virtual long[] GetLongs(IndexReader reader,
> System.String field)
> -               {
> -                       return GetLongs(reader, field, null);
> -               }
> -
> -               // inherit javadocs
> -               public virtual long[] GetLongs(IndexReader reader,
> System.String field, Lucene.Net.Search.LongParser parser)
> -               {
> -                       return (long[]) caches[typeof(long)].Get(reader,
> new Entry(field, parser));
> -               }
> -
> -               internal sealed class LongCache:Cache
> -               {
> -                       internal LongCache(FieldCache
> wrapper):base(wrapper)
> -                       {
> -                       }
> -
> -                       protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> -                       {
> -                               Entry entry = entryKey;
> -                               System.String field = entry.field;
> -                               Lucene.Net.Search.LongParser parser =
> (Lucene.Net.Search.LongParser) entry.custom;
> -                               if (parser == null)
> -                               {
> -                                       try
> -                                       {
> -                                               return
> wrapper.GetLongs(reader, field,
> Lucene.Net.Search.FieldCache_Fields.DEFAULT_LONG_PARSER);
> -                                       }
> -                                       catch (System.FormatException ne)
> -                                       {
> -                                               return
> wrapper.GetLongs(reader, field,
> Lucene.Net.Search.FieldCache_Fields.NUMERIC_UTILS_LONG_PARSER);
> -                                       }
> -                               }
> -                               long[] retArray = null;
> -                               TermDocs termDocs = reader.TermDocs();
> -                               TermEnum termEnum = reader.Terms(new
> Term(field));
> -                               try
> -                               {
> -                                       do
> -                                       {
> -                                               Term term =
> termEnum.Term();
> -                                               if (term == null ||
> (System.Object) term.Field != (System.Object) field)
> -                                                       break;
> -                                               long termval =
> parser.ParseLong(term.Text);
> -                                               if (retArray == null)
> -                                               // late init
> -                                                       retArray = new
> long[reader.MaxDoc];
> -                                               termDocs.Seek(termEnum);
> -                                               while (termDocs.Next())
> -                                               {
> -
> retArray[termDocs.Doc] = termval;
> -                                               }
> -                                       }
> -                                       while (termEnum.Next());
> -                               }
> -                               catch (StopFillCacheException stop)
> -                               {
> -                               }
> -                               finally
> -                               {
> -                                       termDocs.Close();
> -                                       termEnum.Close();
> -                               }
> -                               if (retArray == null)
> -                               // no values
> -                                       retArray = new long[reader.MaxDoc];
> -                               return retArray;
> -                       }
> -               }
> -
> -
> -               // inherit javadocs
> -               public virtual double[] GetDoubles(IndexReader reader,
> System.String field)
> -               {
> -                       return GetDoubles(reader, field, null);
> -               }
> -
> -               // inherit javadocs
> -               public virtual double[] GetDoubles(IndexReader reader,
> System.String field, Lucene.Net.Search.DoubleParser parser)
> -               {
> -                       return (double[])
> caches[typeof(double)].Get(reader, new Entry(field, parser));
> -               }
> -
> -               internal sealed class DoubleCache:Cache
> -               {
> -                       internal DoubleCache(FieldCache
> wrapper):base(wrapper)
> -                       {
> -                       }
> -
> -                       protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> -                       {
> -                               Entry entry = entryKey;
> -                               System.String field = entry.field;
> -                               Lucene.Net.Search.DoubleParser parser =
> (Lucene.Net.Search.DoubleParser) entry.custom;
> -                               if (parser == null)
> -                               {
> -                                       try
> -                                       {
> -                                               return
> wrapper.GetDoubles(reader, field,
> Lucene.Net.Search.FieldCache_Fields.DEFAULT_DOUBLE_PARSER);
> -                                       }
> -                                       catch (System.FormatException ne)
> -                                       {
> -                                               return
> wrapper.GetDoubles(reader, field,
> Lucene.Net.Search.FieldCache_Fields.NUMERIC_UTILS_DOUBLE_PARSER);
> -                                       }
> -                               }
> -                               double[] retArray = null;
> -                               TermDocs termDocs = reader.TermDocs();
> -                               TermEnum termEnum = reader.Terms(new
> Term(field));
> -                               try
> -                               {
> -                                       do
> -                                       {
> -                                               Term term =
> termEnum.Term();
> -                                               if (term == null ||
> (System.Object) term.Field != (System.Object) field)
> -                                                       break;
> -                                               double termval =
> parser.ParseDouble(term.Text);
> -                                               if (retArray == null)
> -                                               // late init
> -                                                       retArray = new
> double[reader.MaxDoc];
> -                                               termDocs.Seek(termEnum);
> -                                               while (termDocs.Next())
> -                                               {
> -
> retArray[termDocs.Doc] = termval;
> -                                               }
> -                                       }
> -                                       while (termEnum.Next());
> -                               }
> -                               catch (StopFillCacheException stop)
> -                               {
> -                               }
> -                               finally
> -                               {
> -                                       termDocs.Close();
> -                                       termEnum.Close();
> -                               }
> -                               if (retArray == null)
> -                               // no values
> -                                       retArray = new
> double[reader.MaxDoc];
> -                               return retArray;
> -                       }
> -               }
> -
> -
> -               // inherit javadocs
> -               public virtual System.String[] GetStrings(IndexReader
> reader, System.String field)
> -               {
> -                       return (System.String[])
> caches[typeof(string)].Get(reader, new Entry(field, (Parser) null));
> -               }
> -
> -               internal sealed class StringCache:Cache
> -               {
> -                       internal StringCache(FieldCache
> wrapper):base(wrapper)
> -                       {
> -                       }
> -
> -                       protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> -                       {
> -                               System.String field =
> StringHelper.Intern(entryKey.field);
> -                               System.String[] retArray = new
> System.String[reader.MaxDoc];
> -                               TermDocs termDocs = reader.TermDocs();
> -                               TermEnum termEnum = reader.Terms(new
> Term(field));
> -                               try
> -                               {
> -                                       do
> -                                       {
> -                                               Term term =
> termEnum.Term();
> -                                               if (term == null ||
> (System.Object) term.Field != (System.Object) field)
> -                                                       break;
> -                                               System.String termval =
> term.Text;
> -                                               termDocs.Seek(termEnum);
> -                                               while (termDocs.Next())
> -                                               {
> -
> retArray[termDocs.Doc] = termval;
> -                                               }
> -                                       }
> -                                       while (termEnum.Next());
> -                               }
> -                               finally
> -                               {
> -                                       termDocs.Close();
> -                                       termEnum.Close();
> -                               }
> -                               return retArray;
> -                       }
> -               }
> -
> -
> -               // inherit javadocs
> -               public virtual StringIndex GetStringIndex(IndexReader
> reader, System.String field)
> -               {
> -                       return (StringIndex)
> caches[typeof(StringIndex)].Get(reader, new Entry(field, (Parser) null));
> -               }
> -
> -               internal sealed class StringIndexCache:Cache
> -               {
> -                       internal StringIndexCache(FieldCache
> wrapper):base(wrapper)
> -                       {
> -                       }
> -
> -                       protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> -                       {
> -                               System.String field =
> StringHelper.Intern(entryKey.field);
> -                               int[] retArray = new int[reader.MaxDoc];
> -                               System.String[] mterms = new
> System.String[reader.MaxDoc + 1];
> -                               TermDocs termDocs = reader.TermDocs();
> -                               TermEnum termEnum = reader.Terms(new
> Term(field));
> -                               int t = 0; // current term number
> -
> -                               // an entry for documents that have no
> terms in this field
> -                               // should a document with no terms be at
> top or bottom?
> -                               // this puts them at the top - if it is
> changed, FieldDocSortedHitQueue
> -                               // needs to change as well.
> -                               mterms[t++] = null;
> -
> -                               try
> -                               {
> -                                       do
> -                                       {
> -                                               Term term =
> termEnum.Term();
> +                return false;
> +            }
> +
> +            /// <summary>Composes a hashcode based on the field and type.
> </summary>
> +            public override int GetHashCode()
> +            {
> +                return field.GetHashCode() ^  (custom ==
> null?0:custom.GetHashCode());
> +            }
> +        }
> +
> +        // inherit javadocs
> +        public virtual sbyte[] GetBytes(IndexReader reader, System.String
> field)
> +        {
> +            return GetBytes(reader, field, null);
> +        }
> +
> +        // inherit javadocs
> +        public virtual sbyte[] GetBytes(IndexReader reader, System.String
> field, ByteParser parser)
> +        {
> +            return (sbyte[]) caches[typeof(sbyte)].Get(reader, new
> Entry(field, parser));
> +        }
> +
> +        internal sealed class ByteCache:Cache
> +        {
> +            internal ByteCache(FieldCache wrapper):base(wrapper)
> +            {
> +            }
> +            protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> +            {
> +                Entry entry = entryKey;
> +                System.String field = entry.field;
> +                ByteParser parser = (ByteParser) entry.custom;
> +                if (parser == null)
> +                {
> +                    return wrapper.GetBytes(reader, field,
> Lucene.Net.Search.FieldCache_Fields.DEFAULT_BYTE_PARSER);
> +                }
> +                sbyte[] retArray = new sbyte[reader.MaxDoc];
> +                TermDocs termDocs = reader.TermDocs();
> +                TermEnum termEnum = reader.Terms(new Term(field));
> +                try
> +                {
> +                    do
> +                    {
> +                        Term term = termEnum.Term();
> +                        if (term == null || (System.Object) term.Field !=
> (System.Object) field)
> +                            break;
> +                        sbyte termval = parser.ParseByte(term.Text);
> +                        termDocs.Seek(termEnum);
> +                        while (termDocs.Next())
> +                        {
> +                            retArray[termDocs.Doc] = termval;
> +                        }
> +                    }
> +                    while (termEnum.Next());
> +                }
> +                catch (StopFillCacheException stop)
> +                {
> +                }
> +                finally
> +                {
> +                    termDocs.Close();
> +                    termEnum.Close();
> +                }
> +                return retArray;
> +            }
> +        }
> +
> +
> +        // inherit javadocs
> +        public virtual short[] GetShorts(IndexReader reader,
> System.String field)
> +        {
> +            return GetShorts(reader, field, null);
> +        }
> +
> +        // inherit javadocs
> +        public virtual short[] GetShorts(IndexReader reader,
> System.String field, ShortParser parser)
> +        {
> +            return (short[]) caches[typeof(short)].Get(reader, new
> Entry(field, parser));
> +        }
> +
> +        internal sealed class ShortCache:Cache
> +        {
> +            internal ShortCache(FieldCache wrapper):base(wrapper)
> +            {
> +            }
> +
> +            protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> +            {
> +                Entry entry = entryKey;
> +                System.String field = entry.field;
> +                ShortParser parser = (ShortParser) entry.custom;
> +                if (parser == null)
> +                {
> +                    return wrapper.GetShorts(reader, field,
> Lucene.Net.Search.FieldCache_Fields.DEFAULT_SHORT_PARSER);
> +                }
> +                short[] retArray = new short[reader.MaxDoc];
> +                TermDocs termDocs = reader.TermDocs();
> +                TermEnum termEnum = reader.Terms(new Term(field));
> +                try
> +                {
> +                    do
> +                    {
> +                        Term term = termEnum.Term();
> +                        if (term == null || (System.Object) term.Field !=
> (System.Object) field)
> +                            break;
> +                        short termval = parser.ParseShort(term.Text);
> +                        termDocs.Seek(termEnum);
> +                        while (termDocs.Next())
> +                        {
> +                            retArray[termDocs.Doc] = termval;
> +                        }
> +                    }
> +                    while (termEnum.Next());
> +                }
> +                catch (StopFillCacheException stop)
> +                {
> +                }
> +                finally
> +                {
> +                    termDocs.Close();
> +                    termEnum.Close();
> +                }
> +                return retArray;
> +            }
> +        }
> +
> +
> +        // inherit javadocs
> +        public virtual int[] GetInts(IndexReader reader, System.String
> field)
> +        {
> +            return GetInts(reader, field, null);
> +        }
> +
> +        // inherit javadocs
> +        public virtual int[] GetInts(IndexReader reader, System.String
> field, IntParser parser)
> +        {
> +            return (int[]) caches[typeof(int)].Get(reader, new
> Entry(field, parser));
> +        }
> +
> +        internal sealed class IntCache:Cache
> +        {
> +            internal IntCache(FieldCache wrapper):base(wrapper)
> +            {
> +            }
> +
> +            protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> +            {
> +                Entry entry = entryKey;
> +                System.String field = entry.field;
> +                IntParser parser = (IntParser) entry.custom;
> +                if (parser == null)
> +                {
> +                    try
> +                    {
> +                        return wrapper.GetInts(reader, field,
> Lucene.Net.Search.FieldCache_Fields.DEFAULT_INT_PARSER);
> +                    }
> +                    catch (System.FormatException ne)
> +                    {
> +                        return wrapper.GetInts(reader, field,
> Lucene.Net.Search.FieldCache_Fields.NUMERIC_UTILS_INT_PARSER);
> +                    }
> +                }
> +                int[] retArray = null;
> +                TermDocs termDocs = reader.TermDocs();
> +                TermEnum termEnum = reader.Terms(new Term(field));
> +                try
> +                {
> +                    do
> +                    {
> +                        Term term = termEnum.Term();
> +                        if (term == null || (System.Object) term.Field !=
> (System.Object) field)
> +                            break;
> +                        int termval = parser.ParseInt(term.Text);
> +                        if (retArray == null)
> +                        // late init
> +                            retArray = new int[reader.MaxDoc];
> +                        termDocs.Seek(termEnum);
> +                        while (termDocs.Next())
> +                        {
> +                            retArray[termDocs.Doc] = termval;
> +                        }
> +                    }
> +                    while (termEnum.Next());
> +                }
> +                catch (StopFillCacheException stop)
> +                {
> +                }
> +                finally
> +                {
> +                    termDocs.Close();
> +                    termEnum.Close();
> +                }
> +                if (retArray == null)
> +                // no values
> +                    retArray = new int[reader.MaxDoc];
> +                return retArray;
> +            }
> +        }
> +
> +
> +
> +        // inherit javadocs
> +        public virtual float[] GetFloats(IndexReader reader,
> System.String field)
> +        {
> +            return GetFloats(reader, field, null);
> +        }
> +
> +        // inherit javadocs
> +        public virtual float[] GetFloats(IndexReader reader,
> System.String field, FloatParser parser)
> +        {
> +
> +            return (float[]) caches[typeof(float)].Get(reader, new
> Entry(field, parser));
> +        }
> +
> +        internal sealed class FloatCache:Cache
> +        {
> +            internal FloatCache(FieldCache wrapper):base(wrapper)
> +            {
> +            }
> +
> +            protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> +            {
> +                Entry entry = entryKey;
> +                System.String field = entry.field;
> +                FloatParser parser = (FloatParser) entry.custom;
> +                if (parser == null)
> +                {
> +                    try
> +                    {
> +                        return wrapper.GetFloats(reader, field,
> Lucene.Net.Search.FieldCache_Fields.DEFAULT_FLOAT_PARSER);
> +                    }
> +                    catch (System.FormatException ne)
> +                    {
> +                        return wrapper.GetFloats(reader, field,
> Lucene.Net.Search.FieldCache_Fields.NUMERIC_UTILS_FLOAT_PARSER);
> +                    }
> +                }
> +                float[] retArray = null;
> +                TermDocs termDocs = reader.TermDocs();
> +                TermEnum termEnum = reader.Terms(new Term(field));
> +                try
> +                {
> +                    do
> +                    {
> +                        Term term = termEnum.Term();
> +                        if (term == null || (System.Object) term.Field !=
> (System.Object) field)
> +                            break;
> +                        float termval = parser.ParseFloat(term.Text);
> +                        if (retArray == null)
> +                        // late init
> +                            retArray = new float[reader.MaxDoc];
> +                        termDocs.Seek(termEnum);
> +                        while (termDocs.Next())
> +                        {
> +                            retArray[termDocs.Doc] = termval;
> +                        }
> +                    }
> +                    while (termEnum.Next());
> +                }
> +                catch (StopFillCacheException stop)
> +                {
> +                }
> +                finally
> +                {
> +                    termDocs.Close();
> +                    termEnum.Close();
> +                }
> +                if (retArray == null)
> +                // no values
> +                    retArray = new float[reader.MaxDoc];
> +                return retArray;
> +            }
> +        }
> +
> +
> +
> +        public virtual long[] GetLongs(IndexReader reader, System.String
> field)
> +        {
> +            return GetLongs(reader, field, null);
> +        }
> +
> +        // inherit javadocs
> +        public virtual long[] GetLongs(IndexReader reader, System.String
> field, Lucene.Net.Search.LongParser parser)
> +        {
> +            return (long[]) caches[typeof(long)].Get(reader, new
> Entry(field, parser));
> +        }
> +
> +        internal sealed class LongCache:Cache
> +        {
> +            internal LongCache(FieldCache wrapper):base(wrapper)
> +            {
> +            }
> +
> +            protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> +            {
> +                Entry entry = entryKey;
> +                System.String field = entry.field;
> +                Lucene.Net.Search.LongParser parser =
> (Lucene.Net.Search.LongParser) entry.custom;
> +                if (parser == null)
> +                {
> +                    try
> +                    {
> +                        return wrapper.GetLongs(reader, field,
> Lucene.Net.Search.FieldCache_Fields.DEFAULT_LONG_PARSER);
> +                    }
> +                    catch (System.FormatException ne)
> +                    {
> +                        return wrapper.GetLongs(reader, field,
> Lucene.Net.Search.FieldCache_Fields.NUMERIC_UTILS_LONG_PARSER);
> +                    }
> +                }
> +                long[] retArray = null;
> +                TermDocs termDocs = reader.TermDocs();
> +                TermEnum termEnum = reader.Terms(new Term(field));
> +                try
> +                {
> +                    do
> +                    {
> +                        Term term = termEnum.Term();
> +                        if (term == null || (System.Object) term.Field !=
> (System.Object) field)
> +                            break;
> +                        long termval = parser.ParseLong(term.Text);
> +                        if (retArray == null)
> +                        // late init
> +                            retArray = new long[reader.MaxDoc];
> +                        termDocs.Seek(termEnum);
> +                        while (termDocs.Next())
> +                        {
> +                            retArray[termDocs.Doc] = termval;
> +                        }
> +                    }
> +                    while (termEnum.Next());
> +                }
> +                catch (StopFillCacheException stop)
> +                {
> +                }
> +                finally
> +                {
> +                    termDocs.Close();
> +                    termEnum.Close();
> +                }
> +                if (retArray == null)
> +                // no values
> +                    retArray = new long[reader.MaxDoc];
> +                return retArray;
> +            }
> +        }
> +
> +
> +        // inherit javadocs
> +        public virtual double[] GetDoubles(IndexReader reader,
> System.String field)
> +        {
> +            return GetDoubles(reader, field, null);
> +        }
> +
> +        // inherit javadocs
> +        public virtual double[] GetDoubles(IndexReader reader,
> System.String field, Lucene.Net.Search.DoubleParser parser)
> +        {
> +            return (double[]) caches[typeof(double)].Get(reader, new
> Entry(field, parser));
> +        }
> +
> +        internal sealed class DoubleCache:Cache
> +        {
> +            internal DoubleCache(FieldCache wrapper):base(wrapper)
> +            {
> +            }
> +
> +            protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> +            {
> +                Entry entry = entryKey;
> +                System.String field = entry.field;
> +                Lucene.Net.Search.DoubleParser parser =
> (Lucene.Net.Search.DoubleParser) entry.custom;
> +                if (parser == null)
> +                {
> +                    try
> +                    {
> +                        return wrapper.GetDoubles(reader, field,
> Lucene.Net.Search.FieldCache_Fields.DEFAULT_DOUBLE_PARSER);
> +                    }
> +                    catch (System.FormatException ne)
> +                    {
> +                        return wrapper.GetDoubles(reader, field,
> Lucene.Net.Search.FieldCache_Fields.NUMERIC_UTILS_DOUBLE_PARSER);
> +                    }
> +                }
> +                double[] retArray = null;
> +                TermDocs termDocs = reader.TermDocs();
> +                TermEnum termEnum = reader.Terms(new Term(field));
> +                try
> +                {
> +                    do
> +                    {
> +                        Term term = termEnum.Term();
> +                        if (term == null || (System.Object) term.Field !=
> (System.Object) field)
> +                            break;
> +                        double termval = parser.ParseDouble(term.Text);
> +                        if (retArray == null)
> +                        // late init
> +                            retArray = new double[reader.MaxDoc];
> +                        termDocs.Seek(termEnum);
> +                        while (termDocs.Next())
> +                        {
> +                            retArray[termDocs.Doc] = termval;
> +                        }
> +                    }
> +                    while (termEnum.Next());
> +                }
> +                catch (StopFillCacheException stop)
> +                {
> +                }
> +                finally
> +                {
> +                    termDocs.Close();
> +                    termEnum.Close();
> +                }
> +                if (retArray == null)
> +                // no values
> +                    retArray = new double[reader.MaxDoc];
> +                return retArray;
> +            }
> +        }
> +
> +
> +        // inherit javadocs
> +        public virtual System.String[] GetStrings(IndexReader reader,
> System.String field)
> +        {
> +            return (System.String[]) caches[typeof(string)].Get(reader,
> new Entry(field, (Parser) null));
> +        }
> +
> +        internal sealed class StringCache:Cache
> +        {
> +            internal StringCache(FieldCache wrapper):base(wrapper)
> +            {
> +            }
> +
> +            protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> +            {
> +                System.String field = StringHelper.Intern(entryKey.field);
> +                System.String[] retArray = new
> System.String[reader.MaxDoc];
> +                TermDocs termDocs = reader.TermDocs();
> +                TermEnum termEnum = reader.Terms(new Term(field));
> +                try
> +                {
> +                    do
> +                    {
> +                        Term term = termEnum.Term();
> +                        if (term == null || (System.Object) term.Field !=
> (System.Object) field)
> +                            break;
> +                        System.String termval = term.Text;
> +                        termDocs.Seek(termEnum);
> +                        while (termDocs.Next())
> +                        {
> +                            retArray[termDocs.Doc] = termval;
> +                        }
> +                    }
> +                    while (termEnum.Next());
> +                }
> +                finally
> +                {
> +                    termDocs.Close();
> +                    termEnum.Close();
> +                }
> +                return retArray;
> +            }
> +        }
> +
> +
> +        // inherit javadocs
> +        public virtual StringIndex GetStringIndex(IndexReader reader,
> System.String field)
> +        {
> +            return (StringIndex) caches[typeof(StringIndex)].Get(reader,
> new Entry(field, (Parser) null));
> +        }
> +
> +        internal sealed class StringIndexCache:Cache
> +        {
> +            internal StringIndexCache(FieldCache wrapper):base(wrapper)
> +            {
> +            }
> +
> +            protected internal override System.Object
> CreateValue(IndexReader reader, Entry entryKey)
> +            {
> +                System.String field = StringHelper.Intern(entryKey.field);
> +                int[] retArray = new int[reader.MaxDoc];
> +                System.String[] mterms = new System.String[reader.MaxDoc
> + 1];
> +                TermDocs termDocs = reader.TermDocs();
> +                TermEnum termEnum = reader.Terms(new Term(field));
> +                int t = 0; // current term number
> +
> +                // an entry for documents that have no terms in this field
> +                // should a document with no terms be at top or bottom?
> +                // this puts them at the top - if it is changed,
> FieldDocSortedHitQueue
> +                // needs to change as well.
> +                mterms[t++] = null;
> +
> +                try
> +                {
> +                    do
> +                    {
> +                        Term term = termEnum.Term();
>                         if (term == null || term.Field != field || t >=
> mterms.Length) break;
> -
> -                                               // store term text
> -                                               mterms[t] = term.Text;
> -
> -                                               termDocs.Seek(termEnum);
> -                                               while (termDocs.Next())
> -                                               {
> -
> retArray[termDocs.Doc] = t;
> -                                               }
> -
> -                                               t++;
> -                                       }
> -                                       while (termEnum.Next());
> -                               }
> -                               finally
> -                               {
> -                                       termDocs.Close();
> -                                       termEnum.Close();
> -                               }
> -
> -                               if (t == 0)
> -                               {
> -                                       // if there are no terms, make the
> term array
> -                                       // have a single null entry
> -                                       mterms = new System.String[1];
> -                               }
> -                               else if (t < mterms.Length)
> -                               {
> -                                       // if there are less terms than
> documents,
> -                                       // trim off the dead array space
> -                                       System.String[] terms = new
> System.String[t];
> -                                       Array.Copy(mterms, 0, terms, 0, t);
> -                                       mterms = terms;
> -                               }
> -
> -                               StringIndex value_Renamed = new
> StringIndex(retArray, mterms);
> -                               return value_Renamed;
> -                       }
> -               }
> -
> -               private volatile System.IO.StreamWriter infoStream;
> -
> -           public virtual StreamWriter InfoStream
> -           {
> -               get { return infoStream; }
> -               set { infoStream = value; }
> -           }
> -       }
> +
> +                        // store term text
> +                        mterms[t] = term.Text;
> +
> +                        termDocs.Seek(termEnum);
> +                        while (termDocs.Next())
> +                        {
> +                            retArray[termDocs.Doc] = t;
> +                        }
> +
> +                        t++;
> +                    }
> +                    while (termEnum.Next());
> +                }
> +                finally
> +                {
> +                    termDocs.Close();
> +                    termEnum.Close();
> +                }
> +
> +                if (t == 0)
> +                {
> +                    // if there are no terms, make the term array
> +                    // have a single null entry
> +                    mterms = new System.String[1];
> +                }
> +                else if (t < mterms.Length)
> +                {
> +                    // if there are less terms than documents,
> +                    // trim off the dead array space
> +                    System.String[] terms = new System.String[t];
> +                    Array.Copy(mterms, 0, terms, 0, t);
> +                    mterms = terms;
> +                }
> +
> +                StringIndex value_Renamed = new StringIndex(retArray,
> mterms);
> +                return value_Renamed;
> +            }
> +        }
> +
> +        private volatile System.IO.StreamWriter infoStream;
> +
> +        public virtual StreamWriter InfoStream
> +        {
> +            get { return infoStream; }
> +            set { infoStream = value; }
> +        }
> +    }
>  }
> \ No newline at end of file
>
> Modified: incubator/lucene.net/trunk/src/core/Store/NativeFSLockFactory.cs
> URL:
> http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Store/NativeFSLockFactory.cs?rev=1353025&r1=1353024&r2=1353025&view=diff
>
> ==============================================================================
> --- incubator/lucene.net/trunk/src/core/Store/NativeFSLockFactory.cs(original)
> +++ incubator/lucene.net/trunk/src/core/Store/NativeFSLockFactory.cs Fri
> Jun 22 20:58:40 2012
> @@ -20,59 +20,59 @@ using System.Collections.Generic;
>
>  namespace Lucene.Net.Store
>  {
> -
> -       /// <summary> <p/>Implements <see cref="LockFactory" /> using
> native OS file
> -       /// locks.  Note that because this LockFactory relies on
> -       /// java.nio.* APIs for locking, any problems with those APIs
> -       /// will cause locking to fail.  Specifically, on certain NFS
> -       /// environments the java.nio.* locks will fail (the lock can
> -       /// incorrectly be double acquired) whereas <see
> cref="SimpleFSLockFactory" />
> -       /// worked perfectly in those same
> -       /// environments.  For NFS based access to an index, it's
> -       /// recommended that you try <see cref="SimpleFSLockFactory" />
> -       /// first and work around the one limitation that a lock file
> -       /// could be left when the JVM exits abnormally.<p/>
> -       ///
> -       /// <p/>The primary benefit of <see cref="NativeFSLockFactory" />
> is
> -       /// that lock files will be properly removed (by the OS) if
> -       /// the JVM has an abnormal exit.<p/>
> -       ///
> -       /// <p/>Note that, unlike <see cref="SimpleFSLockFactory" />, the
> existence of
> -       /// leftover lock files in the filesystem on exiting the JVM
> -       /// is fine because the OS will free the locks held against
> -       /// these files even though the files still remain.<p/>
> -       ///
> -       /// <p/>If you suspect that this or any other LockFactory is
> -       /// not working properly in your environment, you can easily
> -       /// test it by using <see cref="VerifyingLockFactory" />, <see
> cref="LockVerifyServer" />
> -       /// and <see cref="LockStressTest" />.<p/>
> -       ///
> -       /// </summary>
> -       /// <seealso cref="LockFactory">
> -       /// </seealso>
> -
> -       public class NativeFSLockFactory : FSLockFactory
> -       {
> -               /// <summary> Create a NativeFSLockFactory instance, with
> null (unset)
> -               /// lock directory. When you pass this factory to a <see
> cref="FSDirectory" />
> -               /// subclass, the lock directory is automatically set to
> the
> -               /// directory itsself. Be sure to create one instance for
> each directory
> -               /// your create!
> -               /// </summary>
> -               public
> NativeFSLockFactory():this((System.IO.DirectoryInfo) null)
> -               {
> -               }
> -
> -               /// <summary> Create a NativeFSLockFactory instance,
> storing lock
> -               /// files into the specified lockDirName:
> -               ///
> -               /// </summary>
> -               /// <param name="lockDirName">where lock files are created.
> -               /// </param>
> -               public NativeFSLockFactory(System.String
> lockDirName):this(new System.IO.DirectoryInfo(lockDirName))
> -               {
> -               }
> -
> +
> +    /// <summary> <p/>Implements <see cref="LockFactory" /> using native
> OS file
> +    /// locks.  Note that because this LockFactory relies on
> +    /// java.nio.* APIs for locking, any problems with those APIs
> +    /// will cause locking to fail.  Specifically, on certain NFS
> +    /// environments the java.nio.* locks will fail (the lock can
> +    /// incorrectly be double acquired) whereas <see
> cref="SimpleFSLockFactory" />
> +    /// worked perfectly in those same
> +    /// environments.  For NFS based access to an index, it's
> +    /// recommended that you try <see cref="SimpleFSLockFactory" />
> +    /// first and work around the one limitation that a lock file
> +    /// could be left when the JVM exits abnormally.<p/>
> +    ///
> +    /// <p/>The primary benefit of <see cref="NativeFSLockFactory" /> is
> +    /// that lock files will be properly removed (by the OS) if
> +    /// the JVM has an abnormal exit.<p/>
> +    ///
> +    /// <p/>Note that, unlike <see cref="SimpleFSLockFactory" />, the
> existence of
> +    /// leftover lock files in the filesystem on exiting the JVM
> +    /// is fine because the OS will free the locks held against
> +    /// these files even though the files still remain.<p/>
> +    ///
> +    /// <p/>If you suspect that this or any other LockFactory is
> +    /// not working properly in your environment, you can easily
> +    /// test it by using <see cref="VerifyingLockFactory" />, <see
> cref="LockVerifyServer" />
> +    /// and <see cref="LockStressTest" />.<p/>
> +    ///
> +    /// </summary>
> +    /// <seealso cref="LockFactory">
> +    /// </seealso>
> +
> +    public class NativeFSLockFactory : FSLockFactory
> +    {
> +        /// <summary> Create a NativeFSLockFactory instance, with null
> (unset)
> +        /// lock directory. When you pass this factory to a <see
> cref="FSDirectory" />
> +        /// subclass, the lock directory is automatically set to the
> +        /// directory itsself. Be sure to create one instance for each
> directory
> +        /// your create!
> +        /// </summary>
> +        public NativeFSLockFactory():this((System.IO.DirectoryInfo) null)
> +        {
> +        }
> +
> +        /// <summary> Create a NativeFSLockFactory instance, storing lock
> +        /// files into the specified lockDirName:
> +        ///
> +        /// </summary>
> +        /// <param name="lockDirName">where lock files are created.
> +        /// </param>
> +        public NativeFSLockFactory(System.String lockDirName):this(new
> System.IO.DirectoryInfo(lockDirName))
> +        {
> +        }
> +
>         /// <summary> Create a NativeFSLockFactory instance, storing lock
>         /// files into the specified lockDir:
>         ///
> @@ -83,334 +83,334 @@ namespace Lucene.Net.Store
>         {
>             LockDir = lockDir;
>         }
> -
> -               public override Lock MakeLock(System.String lockName)
> -               {
> -                       lock (this)
> -                       {
> -                               if (_lockPrefix != null)
> -                                       lockName = _lockPrefix + "-" +
> lockName;
> -                               return new NativeFSLock(_lockDir,
> lockName);
> -                       }
> -               }
> -
> -               public override void  ClearLock(System.String lockName)
> -               {
> -                       // Note that this isn't strictly required anymore
> -                       // because the existence of these files does not
> mean
> -                       // they are locked, but, still do this in case
> people
> -                       // really want to see the files go away:
> -                       bool tmpBool;
> -                       if (System.IO.File.Exists(_lockDir.FullName))
> -                               tmpBool = true;
> -                       else
> -                               tmpBool =
> System.IO.Directory.Exists(_lockDir.FullName);
> -                       if (tmpBool)
> -                       {
> -                               if (_lockPrefix != null)
> -                               {
> -                                       lockName = _lockPrefix + "-" +
> lockName;
> -                               }
> -                               System.IO.FileInfo lockFile = new
> System.IO.FileInfo(System.IO.Path.Combine(_lockDir.FullName, lockName));
> -                               bool tmpBool2;
> -                               if
> (System.IO.File.Exists(lockFile.FullName))
> -                                       tmpBool2 = true;
> -                               else
> -                                       tmpBool2 =
> System.IO.Directory.Exists(lockFile.FullName);
> -                               bool tmpBool3;
> -                               if
> (System.IO.File.Exists(lockFile.FullName))
> -                               {
> -
> System.IO.File.Delete(lockFile.FullName);
> -                                       tmpBool3 = true;
> -                               }
> -                               else if
> (System.IO.Directory.Exists(lockFile.FullName))
> -                               {
> -
> System.IO.Directory.Delete(lockFile.FullName);
> -                                       tmpBool3 = true;
> -                               }
> -                               else
> -                                       tmpBool3 = false;
> -                               if (tmpBool2 && !tmpBool3)
> -                               {
> -                                       throw new
> System.IO.IOException("Cannot delete " + lockFile);
> -                               }
> -                       }
> -               }
> -       }
> -
> -
> -       class NativeFSLock:Lock
> -       {
> -
> -               private System.IO.FileStream f;
> -               private System.IO.FileStream channel;
> -               private bool lock_Renamed;
> -               private System.IO.FileInfo path;
> -               private System.IO.DirectoryInfo lockDir;
> -
> -               /*
> -               * The javadocs for FileChannel state that you should have
> -               * a single instance of a FileChannel (per JVM) for all
> -               * locking against a given file.  To ensure this, we have
> -               * a single (static) HashSet that contains the file paths
> -               * of all currently locked locks.  This protects against
> -               * possible cases where different Directory instances in
> -               * one JVM (each with their own NativeFSLockFactory
> -               * instance) have set the same lock dir and lock prefix.
> -               */
> +
> +        public override Lock MakeLock(System.String lockName)
> +        {
> +            lock (this)
> +            {
> +                if (_lockPrefix != null)
> +                    lockName = _lockPrefix + "-" + lockName;
> +                return new NativeFSLock(_lockDir, lockName);
> +            }
> +        }
> +
> +        public override void  ClearLock(System.String lockName)
> +        {
> +            // Note that this isn't strictly required anymore
> +            // because the existence of these files does not mean
> +            // they are locked, but, still do this in case people
> +            // really want to see the files go away:
> +            bool tmpBool;
> +            if (System.IO.File.Exists(_lockDir.FullName))
> +                tmpBool = true;
> +            else
> +                tmpBool = System.IO.Directory.Exists(_lockDir.FullName);
> +            if (tmpBool)
> +            {
> +                if (_lockPrefix != null)
> +                {
> +                    lockName = _lockPrefix + "-" + lockName;
> +                }
> +                System.IO.FileInfo lockFile = new
> System.IO.FileInfo(System.IO.Path.Combine(_lockDir.FullName, lockName));
> +                bool tmpBool2;
> +                if (System.IO.File.Exists(lockFile.FullName))
> +                    tmpBool2 = true;
> +                else
> +                    tmpBool2 =
> System.IO.Directory.Exists(lockFile.FullName);
> +                bool tmpBool3;
> +                if (System.IO.File.Exists(lockFile.FullName))
> +                {
> +                    System.IO.File.Delete(lockFile.FullName);
> +                    tmpBool3 = true;
> +                }
> +                else if (System.IO.Directory.Exists(lockFile.FullName))
> +                {
> +                    System.IO.Directory.Delete(lockFile.FullName);
> +                    tmpBool3 = true;
> +                }
> +                else
> +                    tmpBool3 = false;
> +                if (tmpBool2 && !tmpBool3)
> +                {
> +                    throw new System.IO.IOException("Cannot delete " +
> lockFile);
> +                }
> +            }
> +        }
> +    }
> +
> +
> +    class NativeFSLock:Lock
> +    {
> +
> +        private System.IO.FileStream f;
> +        private System.IO.FileStream channel;
> +        private bool lock_Renamed;
> +        private System.IO.FileInfo path;
> +        private System.IO.DirectoryInfo lockDir;
> +
> +        /*
> +        * The javadocs for FileChannel state that you should have
> +        * a single instance of a FileChannel (per JVM) for all
> +        * locking against a given file.  To ensure this, we have
> +        * a single (static) HashSet that contains the file paths
> +        * of all currently locked locks.  This protects against
> +        * possible cases where different Directory instances in
> +        * one JVM (each with their own NativeFSLockFactory
> +        * instance) have set the same lock dir and lock prefix.
> +        */
>         private static HashSet<string> LOCK_HELD = new HashSet<string>();
> -
> +
>         public NativeFSLock(System.IO.DirectoryInfo lockDir, System.String
> lockFileName)
>         {
>             this.lockDir = lockDir;
>             path = new
> System.IO.FileInfo(System.IO.Path.Combine(lockDir.FullName, lockFileName));
>         }
> -
> -               private bool LockExists()
> -               {
> -                       lock (this)
> -                       {
> -                               return lock_Renamed != false;
> -                       }
> -               }
> -
> -               public override bool Obtain()
> -               {
> -                       lock (this)
> -                       {
> -
> -                               if (LockExists())
> -                               {
> -                                       // Our instance is already locked:
> -                                       return false;
> -                               }
> -
> -                               // Ensure that lockDir exists and is a
> directory.
> -                               bool tmpBool;
> -                               if
> (System.IO.File.Exists(lockDir.FullName))
> -                                       tmpBool = true;
> -                               else
> -                                       tmpBool =
> System.IO.Directory.Exists(lockDir.FullName);
> -                               if (!tmpBool)
> -                               {
> -                                       try
> +
> +        private bool LockExists()
> +        {
> +            lock (this)
> +            {
> +                return lock_Renamed != false;
> +            }
> +        }
> +
> +        public override bool Obtain()
> +        {
> +            lock (this)
> +            {
> +
> +                if (LockExists())
> +                {
> +                    // Our instance is already locked:
> +                    return false;
> +                }
> +
> +                // Ensure that lockDir exists and is a directory.
> +                bool tmpBool;
> +                if (System.IO.File.Exists(lockDir.FullName))
> +                    tmpBool = true;
> +                else
> +                    tmpBool =
> System.IO.Directory.Exists(lockDir.FullName);
> +                if (!tmpBool)
> +                {
> +                    try
>                     {
>
> System.IO.Directory.CreateDirectory(lockDir.FullName);
>                     }
>                     catch
>                     {
> -                                               throw new
> System.IO.IOException("Cannot create directory: " + lockDir.FullName);
> +                        throw new System.IO.IOException("Cannot create
> directory: " + lockDir.FullName);
>                     }
> -                               }
> -                               else if
> (!System.IO.Directory.Exists(lockDir.FullName))
> -                               {
> -                                       throw new
> System.IO.IOException("Found regular file where directory expected: " +
> lockDir.FullName);
> -                               }
> -
> -                               System.String canonicalPath =
> path.FullName;
> -
> -                               bool markedHeld = false;
> -
> -                               try
> -                               {
> -
> -                                       // Make sure nobody else
> in-process has this lock held
> -                                       // already, and, mark it held if
> not:
> -
> -                                       lock (LOCK_HELD)
> -                                       {
> -                                               if
> (LOCK_HELD.Contains(canonicalPath))
> -                                               {
> -                                                       // Someone else in
> this JVM already has the lock:
> -                                                       return false;
> -                                               }
> -                                               else
> -                                               {
> -                                                       // This "reserves"
> the fact that we are the one
> -                                                       // thread trying
> to obtain this lock, so we own
> -                                                       // the only
> instance of a channel against this
> -                                                       // file:
> +                }
> +                else if (!System.IO.Directory.Exists(lockDir.FullName))
> +                {
> +                    throw new System.IO.IOException("Found regular file
> where directory expected: " + lockDir.FullName);
> +                }
> +
> +                System.String canonicalPath = path.FullName;
> +
> +                bool markedHeld = false;
> +
> +                try
> +                {
> +
> +                    // Make sure nobody else in-process has this lock held
> +                    // already, and, mark it held if not:
> +
> +                    lock (LOCK_HELD)
> +                    {
> +                        if (LOCK_HELD.Contains(canonicalPath))
> +                        {
> +                            // Someone else in this JVM already has the
> lock:
> +                            return false;
> +                        }
> +                        else
> +                        {
> +                            // This "reserves" the fact that we are the
> one
> +                            // thread trying to obtain this lock, so we
> own
> +                            // the only instance of a channel against this
> +                            // file:
>                             LOCK_HELD.Add(canonicalPath);
> -                                                       markedHeld = true;
> -                                               }
> -                                       }
> -
> -                                       try
> -                                       {
> -                                               f = new
> System.IO.FileStream(path.FullName, System.IO.FileMode.OpenOrCreate,
> System.IO.FileAccess.ReadWrite);
> -                                       }
> -                                       catch (System.IO.IOException e)
> -                                       {
> -                                               // On Windows, we can get
> intermittent "Access
> -                                               // Denied" here.  So, we
> treat this as failure to
> -                                               // acquire the lock, but,
> store the reason in case
> -                                               // there is in fact a real
> error case.
> -                                               failureReason = e;
> -                                               f = null;
> -                                       }
> -
> -                                       if (f != null)
> -                                       {
> -                                               try
> -                                               {
> -                                                       channel = f;
> +                            markedHeld = true;
> +                        }
> +                    }
> +
> +                    try
> +                    {
> +                        f = new System.IO.FileStream(path.FullName,
> System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite);
> +                    }
> +                    catch (System.IO.IOException e)
> +                    {
> +                        // On Windows, we can get intermittent "Access
> +                        // Denied" here.  So, we treat this as failure to
> +                        // acquire the lock, but, store the reason in case
> +                        // there is in fact a real error case.
> +                        failureReason = e;
> +                        f = null;
> +                    }
> +
> +                    if (f != null)
> +                    {
> +                        try
> +                        {
> +                            channel = f;
>                             lock_Renamed = false;
> -                                                       try
> -                                                       {
> -
> channel.Lock(0, channel.Length);
> +                            try
> +                            {
> +                                channel.Lock(0, channel.Length);
>                                 lock_Renamed = true;
> -                                                       }
> -                                                       catch
> (System.IO.IOException e)
> -                                                       {
> -                                                               // At
> least on OS X, we will sometimes get an
> -                                                               //
> intermittent "Permission Denied" IOException,
> -                                                               // which
> seems to simply mean "you failed to get
> -                                                               // the
> lock".  But other IOExceptions could be
> -                                                               //
> "permanent" (eg, locking is not supported via
> -                                                               // the
> filesystem).  So, we record the failure
> -                                                               // reason
> here; the timeout obtain (usually the
> -                                                               // one
> calling us) will use this as "root cause"
> -                                                               // if it
> fails to get the lock.
> -
> failureReason = e;
> -                                                       }
> -                                                       finally
> -                                                       {
> -                                                               if
> (lock_Renamed == false)
> -                                                               {
> -                                                                       try
> -                                                                       {
> -
>       channel.Close();
> -                                                                       }
> -
> finally
> -                                                                       {
> -
>       channel = null;
> -                                                                       }
> -                                                               }
> -                                                       }
> -                                               }
> -                                               finally
> -                                               {
> -                                                       if (channel ==
> null)
> -                                                       {
> -                                                               try
> -                                                               {
> -
> f.Close();
> -                                                               }
> -                                                               finally
> -                                                               {
> -                                                                       f
> = null;
> -                                                               }
> -                                                       }
> -                                               }
> -                                       }
> -                               }
> -                               finally
> -                               {
> -                                       if (markedHeld && !LockExists())
> -                                       {
> -                                               lock (LOCK_HELD)
> -                                               {
> -                                                       if
> (LOCK_HELD.Contains(canonicalPath))
> -                                                       {
> -
> LOCK_HELD.Remove(canonicalPath);
> -                                                       }
> -                                               }
> -                                       }
> -                               }
> -                               return LockExists();
> -                       }
> -               }
> -
> -               public override void  Release()
> -               {
> -                       lock (this)
> -                       {
> -                               if (LockExists())
> -                               {
> -                                       try
> -                                       {
> +                            }
> +                            catch (System.IO.IOException e)
> +                            {
> +                                // At least on OS X, we will sometimes
> get an
> +                                // intermittent "Permission Denied"
> IOException,
> +                                // which seems to simply mean "you failed
> to get
> +                                // the lock".  But other IOExceptions
> could be
> +                                // "permanent" (eg, locking is not
> supported via
> +                                // the filesystem).  So, we record the
> failure
> +                                // reason here; the timeout obtain
> (usually the
> +                                // one calling us) will use this as "root
> cause"
> +                                // if it fails to get the lock.
> +                                failureReason = e;
> +                            }
> +                            finally
> +                            {
> +                                if (lock_Renamed == false)
> +                                {
> +                                    try
> +                                    {
> +                                        channel.Close();
> +                                    }
> +                                    finally
> +                                    {
> +                                        channel = null;
> +                                    }
> +                                }
> +                            }
> +                        }
> +                        finally
> +                        {
> +                            if (channel == null)
> +                            {
> +                                try
> +                                {
> +                                    f.Close();
> +                                }
> +                                finally
> +                                {
> +                                    f = null;
> +                                }
> +                            }
> +                        }
> +                    }
> +                }
> +                finally
> +                {
> +                    if (markedHeld && !LockExists())
> +                    {
> +                        lock (LOCK_HELD)
> +                        {
> +                            if (LOCK_HELD.Contains(canonicalPath))
> +                            {
> +                                LOCK_HELD.Remove(canonicalPath);
> +                            }
> +                        }
> +                    }
> +                }
> +                return LockExists();
> +            }
> +        }
> +
> +        public override void  Release()
> +        {
> +            lock (this)
> +            {
> +                if (LockExists())
> +                {
> +                    try
> +                    {
>                         channel.Unlock(0, channel.Length);
> -                                       }
> -                                       finally
> -                                       {
> -                                               lock_Renamed = false;
> -                                               try
> -                                               {
> -                                                       channel.Close();
> -                                               }
> -                                               finally
> -                                               {
> -                                                       channel = null;
> -                                                       try
> -                                                       {
> -                                                               f.Close();
> -                                                       }
> -                                                       finally
> -                                                       {
> -                                                               f = null;
> -                                                               lock
> (LOCK_HELD)
> -                                                               {
> -
> LOCK_HELD.Remove(path.FullName);
> -                                                               }
> -                                                       }
> -                                               }
> -                                       }
> -                                       bool tmpBool;
> -                                       if
> (System.IO.File.Exists(path.FullName))
> -                                       {
> -
> System.IO.File.Delete(path.FullName);
> -                                               tmpBool = true;
> -                                       }
> -                                       else if
> (System.IO.Directory.Exists(path.FullName))
> -                                       {
> -
> System.IO.Directory.Delete(path.FullName);
> -                                               tmpBool = true;
> -                                       }
> -                                       else
> -                                               tmpBool = false;
> -                                       if (!tmpBool)
> -                                               throw new
> LockReleaseFailedException("failed to delete " + path);
> -                               }
> +                    }
> +                    finally
> +                    {
> +                        lock_Renamed = false;
> +                        try
> +                        {
> +                            channel.Close();
> +                        }
> +                        finally
> +                        {
> +                            channel = null;
> +                            try
> +                            {
> +                                f.Close();
> +                            }
> +                            finally
> +                            {
> +                                f = null;
> +                                lock (LOCK_HELD)
> +                                {
> +                                    LOCK_HELD.Remove(path.FullName);
> +                                }
> +                            }
> +                        }
> +                    }
> +                    bool tmpBool;
> +                    if (System.IO.File.Exists(path.FullName))
> +                    {
> +                        System.IO.File.Delete(path.FullName);
> +                        tmpBool = true;
> +                    }
> +                    else if (System.IO.Directory.Exists(path.FullName))
> +                    {
> +                        System.IO.Directory.Delete(path.FullName);
> +                        tmpBool = true;
> +                    }
> +                    else
> +                        tmpBool = false;
> +                    if (!tmpBool)
> +                        throw new LockReleaseFailedException("failed to
> delete " + path);
> +                }
>             }
> -               }
> -
> -               public override bool IsLocked()
> -               {
> -                       lock (this)
> -                       {
> -                               // The test for is isLocked is not
> directly possible with native file locks:
> -
> -                               // First a shortcut, if a lock reference
> in this instance is available
> -                               if (LockExists())
> -                                       return true;
> -
> -                               // Look if lock file is present; if not,
> there can definitely be no lock!
> -                               bool tmpBool;
> -                               if (System.IO.File.Exists(path.FullName))
> -                                       tmpBool = true;
> -                               else
> -                                       tmpBool =
> System.IO.Directory.Exists(path.FullName);
> -                               if (!tmpBool)
> -                                       return false;
> -
> -                               // Try to obtain and release (if was
> locked) the lock
> -                               try
> -                               {
> -                                       bool obtained = Obtain();
> -                                       if (obtained)
> -                                               Release();
> -                                       return !obtained;
> -                               }
> -                               catch (System.IO.IOException ioe)
> -                               {
> -                                       return false;
> -                               }
> -                       }
> -               }
> -
> -               public override System.String ToString()
> -               {
> -                       return "NativeFSLock@" + path;
> -               }
> -       }
> +        }
> +
> +        public override bool IsLocked()
> +        {
> +            lock (this)
> +            {
> +                // The test for is isLocked is not directly possible with
> native file locks:
> +
> +                // First a shortcut, if a lock reference in this instance
> is available
> +                if (LockExists())
> +                    return true;
> +
> +                // Look if lock file is present; if not, there can
> definitely be no lock!
> +                bool tmpBool;
> +                if (System.IO.File.Exists(path.FullName))
> +                    tmpBool = true;
> +                else
> +                    tmpBool = System.IO.Directory.Exists(path.FullName);
> +                if (!tmpBool)
> +                    return false;
> +
> +                // Try to obtain and release (if was locked) the lock
> +                try
> +                {
> +                    bool obtained = Obtain();
> +                    if (obtained)
> +                        Release();
> +                    return !obtained;
> +                }
> +                catch (System.IO.IOException ioe)
> +                {
> +                    return false;
> +                }
> +            }
> +        }
> +
> +        public override System.String ToString()
> +        {
> +            return "NativeFSLock@" + path;
> +        }
> +    }
>  }
> \ No newline at end of file
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message