/// <summary> /// Expert: decreases the refCount of this TaxonomyReader instance. If the /// refCount drops to 0 this taxonomy reader is closed. /// </summary> public void DecRef() { EnsureOpen(); int rc = refCount.DecrementAndGet(); if (rc == 0) { bool success = false; try { DoClose(); closed = true; success = true; } finally { if (!success) { // Put reference back on failure refCount.IncrementAndGet(); } } } else if (rc < 0) { throw new ThreadStateException("too many decRef calls: refCount is " + rc + " after decrement"); } }
/// <summary> /// Decrements the reference counting of this object. When reference counting /// hits 0, calls <see cref="Release()"/>. /// </summary> public void DecRef() { int rc = refCount.DecrementAndGet(); if (rc == 0) { bool success = false; try { Release(); success = true; } finally { if (!success) { // Put reference back on failure refCount.IncrementAndGet(); } } } else if (rc < 0) { throw IllegalStateException.Create("too many DecRef() calls: refCount is " + rc + " after decrement"); } }
public override void Run() { Random random = Random; while (numDocs.DecrementAndGet() > 0) { try { Document doc = new Document(); int numCats = random.Next(3) + 1; // 1-3 while (numCats-- > 0) { FacetField ff = NewCategory(); doc.Add(ff); FacetLabel label = new FacetLabel(ff.Dim, ff.Path); // add all prefixes to values int level = label.Length; while (level > 0) { string s = FacetsConfig.PathToString(label.Components, level); values[s] = s; --level; } } iw.AddDocument(config.Build(tw, doc)); } catch (IOException e) { throw new Exception(e.ToString(), e); } } }
protected override void HandleUpdateException(Exception exception) { if (exception.IsIOException()) { try { if (Verbose) { Console.WriteLine("hit exception during update: " + exception); } // test that the index can be read and also some basic statistics DirectoryReader reader = DirectoryReader.Open(test.handlerIndexDir.Delegate); try { int numDocs = reader.NumDocs; int version = int.Parse(reader.IndexCommit.UserData[VERSION_ID], NumberStyles.HexNumber); assertEquals(numDocs, version); } finally { reader.Dispose(); } // verify index consistency TestUtil.CheckIndex(test.handlerIndexDir.Delegate); // verify taxonomy index is fully consistent (since we only add one // category to all documents, there's nothing much more to validate TestUtil.CheckIndex(test.handlerTaxoDir.Delegate); } catch (Exception e) when(e.IsIOException()) { throw RuntimeException.Create(e); } finally { // count-down number of failures failures.DecrementAndGet(); if (Debugging.AssertsEnabled) { Debugging.Assert(failures >= 0, "handler failed too many times: {0}", failures); } if (Verbose) { if (failures == 0) { Console.WriteLine("no more failures expected"); } else { Console.WriteLine("num failures left: " + failures); } } } } else { ExceptionDispatchInfo.Capture(exception).Throw(); // LUCENENET: Rethrow to preserve stack details from the original throw } }
public override void Run() { Random random = Random; while (numCats.DecrementAndGet() > 0) { try { int value = random.Next(range); FacetLabel cp = new FacetLabel(Convert.ToString(value / 1000), Convert.ToString(value / 10000), Convert.ToString(value / 100000), Convert.ToString(value)); int ord = tw.AddCategory(cp); Assert.True(tw.GetParent(ord) != -1, "invalid parent for ordinal " + ord + ", category " + cp); string l1 = FacetsConfig.PathToString(cp.Components, 1); string l2 = FacetsConfig.PathToString(cp.Components, 2); string l3 = FacetsConfig.PathToString(cp.Components, 3); string l4 = FacetsConfig.PathToString(cp.Components, 4); values[l1] = l1; values[l2] = l2; values[l3] = l3; values[l4] = l4; } catch (IOException e) { throw new Exception(e.ToString(), e); } } }
public override void Run() { try { long ramSize = 0; while (PendingDocs.DecrementAndGet() > -1) { Document doc = Docs.NextDoc(); Writer.AddDocument(doc); long newRamSize = Writer.RamSizeInBytes(); if (newRamSize != ramSize) { ramSize = newRamSize; } if (DoRandomCommit) { if (Rarely()) { Writer.Commit(); } } } Writer.Commit(); } catch (Exception ex) { Console.WriteLine("FAILED exc:"); Console.WriteLine(ex.StackTrace); throw new Exception(ex.Message, ex); } }
public override void Run() { try { long ramSize = 0; while (pendingDocs.DecrementAndGet() > -1) { Document doc = docs.NextDoc(); writer.AddDocument(doc); long newRamSize = writer.RamSizeInBytes(); if (newRamSize != ramSize) { ramSize = newRamSize; } if (doRandomCommit) { if (Rarely()) { writer.Commit(); } } } writer.Commit(); } catch (Exception ex) when(ex.IsThrowable()) { Console.WriteLine("FAILED exc:"); ex.printStackTrace(Console.Out); throw RuntimeException.Create(ex); } }
/// <summary/> /// <exception cref="InvalidOperationException"></exception> public virtual void DecRef() { if (refCount <= 0) { throw IllegalStateException.Create("this revision is already released"); } var rc = refCount.DecrementAndGet(); if (rc == 0) { bool success = false; try { Revision.Release(); success = true; } finally { if (!success) { // Put reference back on failure refCount.IncrementAndGet(); } } } else if (rc < 0) { throw IllegalStateException.Create(string.Format("too many decRef calls: refCount is {0} after decrement", rc)); } }
protected abstract void Dispose(bool disposing); // LUCENENET: Refactored from DoClose() /// <summary> /// Expert: decreases the refCount of this TaxonomyReader instance. If the /// refCount drops to 0 this taxonomy reader is closed. /// </summary> public void DecRef() { EnsureOpen(); int rc = refCount.DecrementAndGet(); if (rc == 0) { bool success = false; try { Dispose(true); // LUCENENET specific - changed from DoClose() to Dispose(bool) closed = true; success = true; } finally { if (!success) { // Put reference back on failure refCount.IncrementAndGet(); } } } else if (rc < 0) { throw IllegalStateException.Create("too many decRef calls: refCount is " + rc + " after decrement"); } }
public void OneTimeTearDownWrapper() { if (stackCount.DecrementAndGet() == 0) { // Tear down for assembly initializer.DoTestFrameworkTearDown(); } }
public virtual void DecRef() { int rc = refCount.DecrementAndGet(); if (Debugging.AssertsEnabled) { Debugging.Assert(rc >= 0); } }
protected override void HandleUpdateException(Exception exception) { if (exception is IOException) { try { if (VERBOSE) { Console.WriteLine("hit exception during update: " + exception); } // test that the index can be read and also some basic statistics DirectoryReader reader = DirectoryReader.Open(test.handlerIndexDir.Delegate); try { int numDocs = reader.NumDocs; int version = int.Parse(reader.IndexCommit.UserData[VERSION_ID], NumberStyles.HexNumber); assertEquals(numDocs, version); } finally { reader.Dispose(); } // verify index consistency TestUtil.CheckIndex(test.handlerIndexDir.Delegate); // verify taxonomy index is fully consistent (since we only add one // category to all documents, there's nothing much more to validate TestUtil.CheckIndex(test.handlerTaxoDir.Delegate); } finally { // count-down number of failures failures.DecrementAndGet(); Debug.Assert(failures >= 0, "handler failed too many times: " + failures); if (VERBOSE) { if (failures == 0) { Console.WriteLine("no more failures expected"); } else { Console.WriteLine("num failures left: " + failures); } } } } else { throw exception; } }
protected override void HandleUpdateException(Exception exception) { if (exception is IOException) { if (Verbose) { Console.WriteLine("hit exception during update: " + exception); } try { // test that the index can be read and also some basic statistics DirectoryReader reader = DirectoryReader.Open(test.handlerDir.Delegate); try { int numDocs = reader.NumDocs; int version = int.Parse(reader.IndexCommit.UserData[VERSION_ID], NumberStyles.HexNumber); assertEquals(numDocs, version); } finally { reader.Dispose(); } // verify index consistency TestUtil.CheckIndex(test.handlerDir.Delegate); } finally { // count-down number of failures failures.DecrementAndGet(); if (Debugging.AssertsEnabled) { Debugging.Assert(failures >= 0, "handler failed too many times: {0}", failures); } if (Verbose) { if (failures == 0) { Console.WriteLine("no more failures expected"); } else { Console.WriteLine("num failures left: " + failures); } } } } else { throw exception; } }
public override void Run() { Random random = Random; while (numCats.DecrementAndGet() > 0) { string cat = Convert.ToString(random.Next(range), CultureInfo.InvariantCulture); try { tw.AddCategory(new FacetLabel("a", cat)); } catch (Exception e) when(e.IsIOException()) { throw RuntimeException.Create(e); } } }
public override void Run() { Random random = Random; while (numCats.DecrementAndGet() > 0) { string cat = Convert.ToString(random.Next(range)); try { tw.AddCategory(new FacetLabel("a", cat)); } catch (IOException e) { throw new Exception(e.ToString(), e); } } }
internal void DecRef() { if (@ref.DecrementAndGet() == 0) { Exception th = null; try { IOUtils.Dispose(termVectorsLocal, fieldsReaderLocal, normsLocal, fields, termVectorsReaderOrig, fieldsReaderOrig, cfsReader, normsProducer); } catch (Exception throwable) { th = throwable; } finally { NotifyCoreClosedListeners(th); } } }
protected override void DoMerge(MergePolicy.OneMerge merge) { try { // Stall all incoming merges until we see // maxMergeCount: int count = runningMergeCount.IncrementAndGet(); try { Assert.IsTrue(count <= maxMergeCount, "count=" + count + " vs maxMergeCount=" + maxMergeCount); enoughMergesWaiting.Signal(); // Stall this merge until we see exactly // maxMergeCount merges waiting while (true) { // wait for 10 milliseconds if (enoughMergesWaiting.Wait(new TimeSpan(0, 0, 0, 0, 10)) || failed) { break; } } // Then sleep a bit to give a chance for the bug // (too many pending merges) to appear: Thread.Sleep(20); base.DoMerge(merge); } finally { runningMergeCount.DecrementAndGet(); } } catch (Exception /*t*/) { failed.Value = (true); m_writer.MergeFinish(merge); // LUCENENET specific - throwing an exception on a background thread causes the test // runner to crash on .NET Core 2.0. //throw new Exception(t.ToString(), t); } }
protected override void DoMerge(MergePolicy.OneMerge merge) { try { // Stall all incoming merges until we see // maxMergeCount: int count = runningMergeCount.IncrementAndGet(); try { Assert.IsTrue(count <= maxMergeCount, "count=" + count + " vs maxMergeCount=" + maxMergeCount); enoughMergesWaiting.Signal(); // Stall this merge until we see exactly // maxMergeCount merges waiting while (true) { // wait for 10 milliseconds if (enoughMergesWaiting.Wait(new TimeSpan(0, 0, 0, 0, 10)) || failed) { break; } } // Then sleep a bit to give a chance for the bug // (too many pending merges) to appear: Thread.Sleep(20); base.DoMerge(merge); } finally { runningMergeCount.DecrementAndGet(); } } catch (Exception t) { failed.Value = (true); m_writer.MergeFinish(merge); // LUCENENET NOTE: ThreadJob takes care of propagating the exception to the calling thread throw new Exception(t.ToString(), t); } }
/// <summary> /// Expert: decreases the <see cref="RefCount"/> of this <see cref="IndexReader"/> /// instance. If the <see cref="RefCount"/> drops to 0, then this /// reader is disposed. If an exception is hit, the <see cref="RefCount"/> /// is unchanged. /// </summary> /// <exception cref="System.IO.IOException"> in case an <see cref="System.IO.IOException"/> occurs in <see cref="DoClose()"/> /// </exception> /// <seealso cref="IncRef"/> public void DecRef() { // only check refcount here (don't call ensureOpen()), so we can // still close the reader if it was made invalid by a child: if (refCount.Get() <= 0) { throw new ObjectDisposedException(this.GetType().GetTypeInfo().FullName, "this IndexReader is closed"); } int rc = refCount.DecrementAndGet(); if (rc == 0) { closed = true; Exception throwable = null; try { DoClose(); } catch (Exception th) { throwable = th; } finally { try { ReportCloseToParentReaders(); } finally { NotifyReaderClosedListeners(throwable); } } } else if (rc < 0) { throw new InvalidOperationException("too many decRef calls: refCount is " + rc + " after decrement"); } }
/// <summary> /// Expert: decreases the <see cref="RefCount"/> of this <see cref="IndexReader"/> /// instance. If the <see cref="RefCount"/> drops to 0, then this /// reader is disposed. If an exception is hit, the <see cref="RefCount"/> /// is unchanged. /// </summary> /// <exception cref="IOException"> in case an <see cref="IOException"/> occurs in <see cref="DoClose()"/> /// </exception> /// <seealso cref="IncRef"/> public void DecRef() { // only check refcount here (don't call ensureOpen()), so we can // still close the reader if it was made invalid by a child: if (refCount <= 0) { throw AlreadyClosedException.Create(this.GetType().FullName, "this IndexReader is disposed."); } int rc = refCount.DecrementAndGet(); if (rc == 0) { closed = true; Exception throwable = null; try { DoClose(); } catch (Exception th) when(th.IsThrowable()) { throwable = th; } finally { try { ReportCloseToParentReaders(); } finally { NotifyReaderClosedListeners(throwable); } } } else if (rc < 0) { throw IllegalStateException.Create("too many decRef calls: refCount is " + rc + " after decrement"); } }
public void Put(TKey key, TValue value) { IDictionary <TKey, TValue> primary; IDictionary <TKey, TValue> secondary; if (swapped) { primary = cache2; secondary = cache1; } else { primary = cache1; secondary = cache2; } primary[key] = value; if (countdown.DecrementAndGet() == 0) { // Time to swap // NOTE: there is saturation risk here, that the // thread that's doing the clear() takes too long to // do so, while other threads continue to add to // primary, but in practice this seems not to be an // issue (see LUCENE-2075 for benchmark & details) // First, clear secondary secondary.Clear(); // Second, swap swapped = !swapped; // Third, reset countdown countdown.Set(maxSize); } }
public void OnClose(IndexReader reader) { Count.DecrementAndGet(); }
public virtual void DecRef() { int rc = refCount.DecrementAndGet(); Debug.Assert(rc >= 0); }
public override void Run() { try { while (Operations.Get() > 0) { int oper = rand.Next(100); if (oper < CommitPercent) { if (NumCommitting.IncrementAndGet() <= MaxConcurrentCommits) { IDictionary <int, long> newCommittedModel; long version; DirectoryReader oldReader; lock (OuterInstance) { newCommittedModel = new Dictionary <int, long>(OuterInstance.Model); // take a snapshot version = OuterInstance.SnapshotCount++; oldReader = OuterInstance.Reader; oldReader.IncRef(); // increment the reference since we will use this for reopening } DirectoryReader newReader; if (rand.Next(100) < SoftCommitPercent) { // assertU(h.Commit("softCommit","true")); if (Random().NextBoolean()) { if (VERBOSE) { Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": call writer.getReader"); } newReader = Writer.GetReader(true); } else { if (VERBOSE) { Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": reopen reader=" + oldReader + " version=" + version); } newReader = DirectoryReader.OpenIfChanged(oldReader, Writer.w, true); } } else { // assertU(commit()); if (VERBOSE) { Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": commit+reopen reader=" + oldReader + " version=" + version); } Writer.Commit(); if (VERBOSE) { Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": now reopen after commit"); } newReader = DirectoryReader.OpenIfChanged(oldReader); } // Code below assumes newReader comes w/ // extra ref: if (newReader == null) { oldReader.IncRef(); newReader = oldReader; } oldReader.DecRef(); lock (OuterInstance) { // install the new reader if it's newest (and check the current version since another reader may have already been installed) //System.out.println(Thread.currentThread().getName() + ": newVersion=" + newReader.getVersion()); Debug.Assert(newReader.RefCount > 0); Debug.Assert(OuterInstance.Reader.RefCount > 0); if (newReader.Version > OuterInstance.Reader.Version) { if (VERBOSE) { Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": install new reader=" + newReader); } OuterInstance.Reader.DecRef(); OuterInstance.Reader = newReader; // Silly: forces fieldInfos to be // loaded so we don't hit IOE on later // reader.toString newReader.ToString(); // install this snapshot only if it's newer than the current one if (version >= OuterInstance.CommittedModelClock) { if (VERBOSE) { Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": install new model version=" + version); } OuterInstance.CommittedModel = newCommittedModel; OuterInstance.CommittedModelClock = version; } else { if (VERBOSE) { Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": skip install new model version=" + version); } } } else { // if the same reader, don't decRef. if (VERBOSE) { Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": skip install new reader=" + newReader); } newReader.DecRef(); } } } NumCommitting.DecrementAndGet(); } else { int id = rand.Next(Ndocs); object sync = OuterInstance.SyncArr[id]; // set the lastId before we actually change it sometimes to try and // uncover more race conditions between writing and reading bool before = Random().NextBoolean(); if (before) { OuterInstance.LastId = id; } // We can't concurrently update the same document and retain our invariants of increasing values // since we can't guarantee what order the updates will be executed. lock (sync) { long val = OuterInstance.Model[id]; long nextVal = Math.Abs(val) + 1; if (oper < CommitPercent + DeletePercent) { // assertU("<delete><id>" + id + "</id></delete>"); // add tombstone first if (Tombstones) { Document d = new Document(); d.Add(OuterInstance.NewStringField("id", "-" + Convert.ToString(id), Documents.Field.Store.YES)); d.Add(OuterInstance.NewField(OuterInstance.Field, Convert.ToString(nextVal), StoredOnlyType)); Writer.UpdateDocument(new Term("id", "-" + Convert.ToString(id)), d); } if (VERBOSE) { Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": term delDocs id:" + id + " nextVal=" + nextVal); } Writer.DeleteDocuments(new Term("id", Convert.ToString(id))); OuterInstance.Model[id] = -nextVal; } else if (oper < CommitPercent + DeletePercent + DeleteByQueryPercent) { //assertU("<delete><query>id:" + id + "</query></delete>"); // add tombstone first if (Tombstones) { Document d = new Document(); d.Add(OuterInstance.NewStringField("id", "-" + Convert.ToString(id), Documents.Field.Store.YES)); d.Add(OuterInstance.NewField(OuterInstance.Field, Convert.ToString(nextVal), StoredOnlyType)); Writer.UpdateDocument(new Term("id", "-" + Convert.ToString(id)), d); } if (VERBOSE) { Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": query delDocs id:" + id + " nextVal=" + nextVal); } Writer.DeleteDocuments(new TermQuery(new Term("id", Convert.ToString(id)))); OuterInstance.Model[id] = -nextVal; } else { // assertU(adoc("id",Integer.toString(id), field, Long.toString(nextVal))); Document d = new Document(); d.Add(OuterInstance.NewStringField("id", Convert.ToString(id), Documents.Field.Store.YES)); d.Add(OuterInstance.NewField(OuterInstance.Field, Convert.ToString(nextVal), StoredOnlyType)); if (VERBOSE) { Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": u id:" + id + " val=" + nextVal); } Writer.UpdateDocument(new Term("id", Convert.ToString(id)), d); if (Tombstones) { // remove tombstone after new addition (this should be optional?) Writer.DeleteDocuments(new Term("id", "-" + Convert.ToString(id))); } OuterInstance.Model[id] = nextVal; } } if (!before) { OuterInstance.LastId = id; } } } } catch (Exception e) { Console.WriteLine(Thread.CurrentThread.Name + ": FAILED: unexpected exception"); Console.WriteLine(e.StackTrace); throw new Exception(e.Message, e); } }