//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDropIndexGivenDropSchemaRuleCommand() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldDropIndexGivenDropSchemaRuleCommand() { // Given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.storageengine.api.schema.StoreIndexDescriptor indexRule = indexRule(1, 42, 42, INDEX_DESCRIPTOR); StoreIndexDescriptor indexRule = indexRule(1, 42, 42, _indexDescriptor); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final IndexBatchTransactionApplier applier = newIndexTransactionApplier(); IndexBatchTransactionApplier applier = NewIndexTransactionApplier(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(singleton(createdDynamicRecord(1)), singleton(dynamicRecord(1, false)), indexRule); Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(singleton(CreatedDynamicRecord(1)), singleton(dynamicRecord(1, false)), indexRule); // When bool result; using (TransactionApplier txApplier = applier.StartTx(_transactionToApply)) { result = txApplier.VisitSchemaRuleCommand(command); } // Then assertFalse(result); verify(_indexingService).dropIndex(indexRule); }
public override bool VisitSchemaRuleCommand(Command.SchemaRuleCommand command) { SchemaStore schemaStore = _neoStores.SchemaStore; if (_version == CommandVersion.BEFORE) { // We are doing reverse-recovery. There is no need for updating the cache, since the indexing service be told what it needs to know when we do // forward-recovery later. bool create = command.Mode == Command.Mode.Create; foreach (DynamicRecord record in command.RecordsBefore) { if (create) { // Schema create commands do not properly store their before images, so we need to correct them. // That is, if the schema was created by this command, then obviously the before image of those records were not in use. record.InUse = false; } schemaStore.UpdateRecord(record); } return(false); } // schema rules. Execute these after generating the property updates so. If executed // before and we've got a transaction that sets properties/labels as well as creating an index // we might end up with this corner-case: // 1) index rule created and index population job started // 2) index population job processes some nodes, but doesn't complete // 3) we gather up property updates and send those to the indexes. The newly created population // job might get those as updates // 4) the population job will apply those updates as added properties, and might end up with duplicate // entries for the same property foreach (DynamicRecord record in command.RecordsAfter) { schemaStore.UpdateRecord(record); } if (command.SchemaRule is ConstraintRule) { switch (command.Mode) { case UPDATE: case CREATE: _neoStores.MetaDataStore.LatestConstraintIntroducingTx = _transactionId; break; case DELETE: break; default: throw new System.InvalidOperationException(command.Mode.name()); } } switch (command.Mode) { case DELETE: _cacheAccess.removeSchemaRuleFromCache(command.Key); break; default: _cacheAccess.addSchemaRule(command.SchemaRule); break; } return(false); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public boolean visitSchemaRuleCommand(Command.SchemaRuleCommand command) throws java.io.IOException public override bool VisitSchemaRuleCommand(Command.SchemaRuleCommand command) { SchemaRule schemaRule = command.SchemaRule; if (command.SchemaRule is StoreIndexDescriptor) { StoreIndexDescriptor indexRule = ( StoreIndexDescriptor )schemaRule; // Why apply index updates here? Here's the thing... this is a batch applier, which means that // index updates are gathered throughout the batch and applied in the end of the batch. // Assume there are some transactions creating or modifying nodes that may not be covered // by an existing index, but a later transaction in the same batch creates such an index. // In that scenario the index would be created, populated and then fed the [this time duplicate] // update for the node created before the index. The most straight forward solution is to // apply pending index updates up to this point in this batch before index schema changes occur. outerInstance.applyPendingLabelAndIndexUpdates(); switch (command.Mode) { case UPDATE: // Shouldn't we be more clear about that we are waiting for an index to come online here? // right now we just assume that an update to index records means wait for it to be online. if (indexRule.CanSupportUniqueConstraint()) { // Register activations into the IndexActivator instead of IndexingService to avoid deadlock // that could insue for applying batches of transactions where a previous transaction in the same // batch acquires a low-level commit lock that prevents the very same index population to complete. outerInstance.indexActivator.ActivateIndex(schemaRule.Id); } break; case CREATE: // Add to list so that all these indexes will be created in one call later CreatedIndexes = CreatedIndexes == null ? new List <StoreIndexDescriptor>() : CreatedIndexes; CreatedIndexes.Add(indexRule); break; case DELETE: outerInstance.indexingService.DropIndex(indexRule); outerInstance.indexActivator.IndexDropped(schemaRule.Id); break; default: throw new System.InvalidOperationException(command.Mode.name()); } } // Keep IndexingService updated on constraint changes else if (schemaRule is ConstraintRule) { ConstraintRule constraintRule = ( ConstraintRule )schemaRule; switch (command.Mode) { case CREATE: case UPDATE: outerInstance.indexingService.PutConstraint(constraintRule); break; case DELETE: outerInstance.indexingService.RemoveConstraint(constraintRule.Id); break; default: throw new System.InvalidOperationException(command.Mode.name()); } } return(false); }