/// <summary> /// This test come from a support case where dropping an index would block forever after index sampling failed. /// <para> /// A fusion index has multiple <seealso cref="IndexSampler index samplers"/> that are called sequentially. If one fails, then the other will never be invoked. /// This was a problem for <seealso cref="LuceneIndexSampler"/>. It owns a <seealso cref="org.neo4j.helpers.TaskControl"/> that it will try to release in try-finally /// in <seealso cref="LuceneIndexSampler.sampleIndex()"/>. But it never gets here because a prior <seealso cref="IndexSampler"/> fails. /// </para> /// <para> /// Because the <seealso cref="org.neo4j.helpers.TaskControl"/> was never released the lucene accessor would block forever, waiting for /// <seealso cref="TaskCoordinator.awaitCompletion()"/>. /// </para> /// <para> /// This situation was solved by making <seealso cref="IndexSampler"/> <seealso cref="System.IDisposable"/> and include it in try-with-resource together with /// <seealso cref="IndexReader"/> that created it. /// </para> /// </summary> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeout = 5_000L) public void failedIndexSamplingMustNotPreventIndexDrop() throws java.io.IOException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void FailedIndexSamplingMustNotPreventIndexDrop() { LuceneIndexProvider luceneProvider = luceneProvider(); MakeSureIndexHasSomeData(luceneProvider); // Otherwise no sampler will be created. IndexProvider failingProvider = failingProvider(); FusionIndexProvider fusionProvider = CreateFusionProvider(luceneProvider, failingProvider); using (IndexAccessor fusionAccessor = fusionProvider.GetOnlineAccessor(_storeIndexDescriptor, _samplingConfig)) { IndexSamplingJob indexSamplingJob = CreateIndexSamplingJob(fusionAccessor); // Call run from other thread try { indexSamplingJob.run(); } catch (Exception e) { assertSame(e, _sampleException); } // then fusionAccessor.Drop(); // should not block forever } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldApplyIndexUpdatesInWorkSyncedBatches() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldApplyIndexUpdatesInWorkSyncedBatches() { // GIVEN //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: long duration = parseTimeMillis.apply(System.getProperty(this.GetType().FullName + ".duration", "2s")); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: int numThreads = Integer.getInteger(this.GetType().FullName + ".numThreads", Runtime.Runtime.availableProcessors()); DefaultFileSystemAbstraction fs = _fileSystemRule.get(); PageCache pageCache = _pageCacheRule.getPageCache(fs); FusionIndexProvider indexProvider = NativeLuceneFusionIndexProviderFactory20.create(pageCache, _directory.databaseDir(), fs, IndexProvider.Monitor_Fields.EMPTY, Config.defaults(), OperationalMode.single, RecoveryCleanupWorkCollector.immediate()); RecordStorageEngine storageEngine = _storageEngineRule.getWith(fs, pageCache, _directory.databaseLayout()).indexProvider(indexProvider).build(); storageEngine.Apply(Tx(singletonList(createIndexRule(DESCRIPTOR, 1, _descriptor))), TransactionApplicationMode.EXTERNAL); Dependencies dependencies = new Dependencies(); storageEngine.SatisfyDependencies(dependencies); IndexProxy index = dependencies.ResolveDependency(typeof(IndexingService)).getIndexProxy(_descriptor); AwaitOnline(index); // WHEN Workers <Worker> workers = new Workers <Worker>(this.GetType().Name); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean(); AtomicBoolean end = new AtomicBoolean(); for (int i = 0; i < numThreads; i++) { workers.Start(new Worker(this, i, end, storageEngine, 10, index)); } // let the threads hammer the storage engine for some time Thread.Sleep(duration); end.set(true); // THEN (assertions as part of the workers applying transactions) workers.AwaitAndThrowOnError(); }
public override Lifecycle NewInstance(KernelContext context, SchemaIndexHaIT.IndexProviderDependencies deps) { PageCache pageCache = deps.PageCache(); File databaseDirectory = context.Directory(); DefaultFileSystemAbstraction fs = FileSystemRule.get(); IndexProvider.Monitor monitor = IndexProvider.Monitor_Fields.EMPTY; Config config = deps.Config(); OperationalMode operationalMode = context.DatabaseInfo().OperationalMode; RecoveryCleanupWorkCollector recoveryCleanupWorkCollector = deps.RecoveryCleanupWorkCollector(); FusionIndexProvider fusionIndexProvider = NativeLuceneFusionIndexProviderFactory20.create(pageCache, databaseDirectory, fs, monitor, config, operationalMode, recoveryCleanupWorkCollector); if (InjectLatchPredicate.test(deps.Db())) { ControlledIndexProvider provider = new ControlledIndexProvider(fusionIndexProvider); PerDbIndexProvider[deps.Db()] = provider; return(provider); } else { return(fusionIndexProvider); } }