Beispiel #1
0
        /// <summary> Tries to acquire the WriteLock on this directory.
        /// this method is only valid if this IndexReader is directory owner.
        ///
        /// </summary>
        /// <throws>  IOException If WriteLock cannot be acquired. </throws>
        private void  AquireWriteLock()
        {
            if (stale)
            {
                throw new System.IO.IOException("IndexReader out of date and no longer valid for delete, undelete, or setNorm operations");
            }

            if (this.writeLock == null)
            {
                Lock writeLock = directory.MakeLock(IndexWriter.WRITE_LOCK_NAME);
                if (!writeLock.Obtain(IndexWriter.WRITE_LOCK_TIMEOUT))
                // obtain write lock
                {
                    throw new System.IO.IOException("Index locked for write: " + writeLock);
                }
                this.writeLock = writeLock;

                // we have to check whether index has changed since this reader was opened.
                // if so, this reader is no longer valid for deletion
                if (SegmentInfos.ReadCurrentVersion(directory) > segmentInfos.GetVersion())
                {
                    stale = true;
                    this.writeLock.Release();
                    this.writeLock = null;
                    throw new System.IO.IOException("IndexReader out of date and no longer valid for delete, undelete, or setNorm operations");
                }
            }
        }
Beispiel #2
0
 /// <summary> Check whether this IndexReader still works on a current version of the index.
 /// If this is not the case you will need to re-open the IndexReader to
 /// make sure you see the latest changes made to the index.
 ///
 /// </summary>
 /// <throws>  IOException </throws>
 public virtual bool IsCurrent()
 {
     if (SegmentInfos.ReadCurrentVersion(directory) != segmentInfos.GetVersion())
     {
         return(false);
     }
     return(true);
 }
Beispiel #3
0
        /// <summary> Check whether this IndexReader still works on a current version of the index.
        /// If this is not the case you will need to re-open the IndexReader to
        /// make sure you see the latest changes made to the index.
        ///
        /// </summary>
        /// <throws>  IOException </throws>
        public virtual bool IsCurrent()
        {
            lock (directory)
            {
                // in- & inter-process sync
                Lock commitLock = directory.MakeLock(IndexWriter.COMMIT_LOCK_NAME);

                bool locked = false;

                try
                {
                    locked = commitLock.Obtain(IndexWriter.COMMIT_LOCK_TIMEOUT);

                    return(SegmentInfos.ReadCurrentVersion(directory) == segmentInfos.GetVersion());
                }
                finally
                {
                    if (locked)
                    {
                        commitLock.Release();
                    }
                }
            }
        }
Beispiel #4
0
 /// <summary> Reads version number from segments files. The version number is
 /// initialized with a timestamp and then increased by one for each change of
 /// the index.
 ///
 /// </summary>
 /// <param name="directory">where the index resides.
 /// </param>
 /// <returns> version number.
 /// </returns>
 /// <throws>  IOException if segments file cannot be read. </throws>
 public static long GetCurrentVersion(Directory directory)
 {
     return(SegmentInfos.ReadCurrentVersion(directory));
 }
Beispiel #5
0
 /// <summary> Check whether this IndexReader still works on a current version of the index.
 /// If this is not the case you will need to re-open the IndexReader to
 /// make sure you see the latest changes made to the index.
 ///
 /// </summary>
 /// <throws>  IOException </throws>
 public virtual bool IsCurrent()
 {
     return(SegmentInfos.ReadCurrentVersion(directory) == segmentInfos.GetVersion());
 }
		/// <summary> Check whether this IndexReader is still using the
		/// current (i.e., most recently committed) version of the
		/// index.  If a writer has committed any changes to the
		/// index since this reader was opened, this will return
		/// <code>false</code>, in which case you must open a new
		/// IndexReader in order to see the changes.  See the
		/// description of the <a href="IndexWriter.html#autoCommit"><code>autoCommit</code></a>
		/// flag which controls when the {@link IndexWriter}
		/// actually commits changes to the index.
		/// 
		/// </summary>
		/// <throws>  CorruptIndexException if the index is corrupt </throws>
		/// <throws>  IOException if there is a low-level IO error </throws>
		public override bool IsCurrent()
		{
			EnsureOpen();
			return SegmentInfos.ReadCurrentVersion(directory) == segmentInfos.GetVersion();
		}