/// <summary> Commit changes resulting from delete, undeleteAll, or setNorm operations /// /// </summary> /// <throws> IOException </throws> protected internal void Commit() { lock (this) { if (hasChanges) { if (directoryOwner) { lock (directory) { // in- & inter-process sync new AnonymousClassWith1(this, directory.MakeLock(IndexWriter.COMMIT_LOCK_NAME), IndexWriter.COMMIT_LOCK_TIMEOUT).Run(); } if (writeLock != null) { writeLock.Release(); // release write lock writeLock = null; } } else { DoCommit(); } } hasChanges = false; } }
/// <summary> Trys 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"); } } }
/// <summary>Flushes all changes to an index and closes all associated files. </summary> public virtual void Close() { lock (this) { FlushRamSegments(); ramDirectory.Close(); writeLock.Release(); // release write lock writeLock = null; if (closeDir) { directory.Close(); } System.GC.SuppressFinalize(this); } }
private IndexWriter(Directory d, Analyzer a, bool create, bool closeDir) { InitBlock(); this.closeDir = closeDir; directory = d; analyzer = a; Lock writeLock = directory.MakeLock(IndexWriter.WRITE_LOCK_NAME); if (!writeLock.Obtain(WRITE_LOCK_TIMEOUT)) // obtain write lock { throw new System.IO.IOException("Index locked for write: " + writeLock); } this.writeLock = writeLock; // save it lock (directory) { // in- & inter-process sync new AnonymousClassWith(create, this, directory.MakeLock(IndexWriter.COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT).Run(); } }
/// <summary> Commit changes resulting from delete, undeleteAll, or setNorm operations /// /// </summary> /// <throws> IOException </throws> protected internal void Commit() { lock (this) { if (hasChanges) { if (directoryOwner) { lock (directory) { // in- & inter-process sync new AnonymousClassWith1(this, directory.MakeLock(IndexWriter.COMMIT_LOCK_NAME), IndexWriter.COMMIT_LOCK_TIMEOUT).Run(); } if (writeLock != null) { writeLock.Release(); // release write lock writeLock = null; } } else DoCommit(); } hasChanges = false; } }
/// <summary> Trys 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"); } } }
/// <summary>Flushes all changes to an index and closes all associated files. </summary> public virtual void Close() { lock (this) { FlushRamSegments(); ramDirectory.Close(); writeLock.Release(); // release write lock writeLock = null; if (closeDir) directory.Close(); System.GC.SuppressFinalize(this); } }