Search in sources :

Example 6 with IndexRule

use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.

the class IndexingServiceTest method shouldFailToStartIfMissingIndexProvider.

@Test
public void shouldFailToStartIfMissingIndexProvider() throws Exception {
    // GIVEN an indexing service that has a schema index provider X
    String otherProviderKey = "something-completely-different";
    SchemaIndexProvider.Descriptor otherDescriptor = new SchemaIndexProvider.Descriptor(otherProviderKey, "no-version");
    IndexRule rule = indexRule(1, 2, 3, otherDescriptor);
    IndexingService indexing = newIndexingServiceWithMockedDependencies(mock(IndexPopulator.class), mock(IndexAccessor.class), new DataUpdates(), rule);
    // WHEN trying to start up and initialize it with an index from provider Y
    try {
        life.init();
        fail("initIndexes with mismatching index provider should fail");
    } catch (LifecycleException e) {
        // THEN starting up should fail
        assertThat(e.getCause().getMessage(), containsString("existing index"));
        assertThat(e.getCause().getMessage(), containsString(otherProviderKey));
    }
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 7 with IndexRule

use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.

the class IndexingServiceTest method shouldSnapshotOnlineIndexes.

@Test
public void shouldSnapshotOnlineIndexes() throws Exception {
    // GIVEN
    int indexId = 1;
    int indexId2 = 2;
    IndexRule rule1 = indexRule(indexId, 2, 3, PROVIDER_DESCRIPTOR);
    IndexRule rule2 = indexRule(indexId2, 4, 5, PROVIDER_DESCRIPTOR);
    IndexAccessor indexAccessor = mock(IndexAccessor.class);
    IndexingService indexing = newIndexingServiceWithMockedDependencies(mock(IndexPopulator.class), indexAccessor, new DataUpdates(), rule1, rule2);
    File theFile = new File("Blah");
    when(indexAccessor.snapshotFiles()).thenAnswer(newResourceIterator(theFile));
    when(indexProvider.getInitialState(indexId, rule1.getIndexDescriptor())).thenReturn(ONLINE);
    when(indexProvider.getInitialState(indexId2, rule2.getIndexDescriptor())).thenReturn(ONLINE);
    when(storeView.indexSample(anyLong(), any(DoubleLongRegister.class))).thenReturn(newDoubleLongRegister(32L, 32L));
    life.start();
    // WHEN
    ResourceIterator<File> files = indexing.snapshotStoreFiles();
    // THEN
    // We get a snapshot per online index
    assertThat(asCollection(files), equalTo(asCollection(iterator(theFile, theFile))));
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) Registers.newDoubleLongRegister(org.neo4j.register.Registers.newDoubleLongRegister) DoubleLongRegister(org.neo4j.register.Register.DoubleLongRegister) File(java.io.File) Test(org.junit.Test)

Example 8 with IndexRule

use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.

the class IndexingServiceTest method shouldLogIndexStateOnInit.

@Test
public void shouldLogIndexStateOnInit() throws Exception {
    // given
    SchemaIndexProvider provider = mock(SchemaIndexProvider.class);
    when(provider.getProviderDescriptor()).thenReturn(PROVIDER_DESCRIPTOR);
    when(provider.getOnlineAccessor(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(mock(IndexAccessor.class));
    SchemaIndexProviderMap providerMap = new DefaultSchemaIndexProviderMap(provider);
    TokenNameLookup mockLookup = mock(TokenNameLookup.class);
    IndexRule onlineIndex = indexRule(1, 1, 1, PROVIDER_DESCRIPTOR);
    IndexRule populatingIndex = indexRule(2, 1, 2, PROVIDER_DESCRIPTOR);
    IndexRule failedIndex = indexRule(3, 2, 2, PROVIDER_DESCRIPTOR);
    life.add(IndexingServiceFactory.createIndexingService(Config.empty(), mock(JobScheduler.class), providerMap, mock(IndexStoreView.class), mockLookup, asList(onlineIndex, populatingIndex, failedIndex), logProvider, IndexingService.NO_MONITOR, DO_NOTHING_CALLBACK));
    when(provider.getInitialState(onlineIndex.getId(), onlineIndex.getIndexDescriptor())).thenReturn(ONLINE);
    when(provider.getInitialState(populatingIndex.getId(), populatingIndex.getIndexDescriptor())).thenReturn(InternalIndexState.POPULATING);
    when(provider.getInitialState(failedIndex.getId(), failedIndex.getIndexDescriptor())).thenReturn(InternalIndexState.FAILED);
    when(mockLookup.labelGetName(1)).thenReturn("LabelOne");
    when(mockLookup.labelGetName(2)).thenReturn("LabelTwo");
    when(mockLookup.propertyKeyGetName(1)).thenReturn("propertyOne");
    when(mockLookup.propertyKeyGetName(2)).thenReturn("propertyTwo");
    // when
    life.init();
    // then
    logProvider.assertExactly(logMatch.info("IndexingService.init: index 1 on :LabelOne(propertyOne) is ONLINE"), logMatch.info("IndexingService.init: index 2 on :LabelOne(propertyTwo) is POPULATING"), logMatch.info("IndexingService.init: index 3 on :LabelTwo(propertyTwo) is FAILED"));
}
Also used : IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) DefaultSchemaIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultSchemaIndexProviderMap) TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) DefaultSchemaIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultSchemaIndexProviderMap) Test(org.junit.Test)

Example 9 with IndexRule

use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyUpdateIndexRuleSchemaRuleCommandToTheStoreInRecovery.

@Test
public void shouldApplyUpdateIndexRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplierFacade(newIndexApplier(), newApplier(true));
    final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
    final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
    final IndexRule rule = constraintIndexRule(0, 1, 2, new SchemaIndexProvider.Descriptor("K", "X.Y"), 42L);
    final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(schemaStore, times(1)).setHighestPossibleIdInUse(record.getId());
    verify(schemaStore, times(1)).updateRecord(record);
    verify(indexingService, times(1)).activateIndex(rule.getId());
    verify(cacheAccess, times(1)).addSchemaRule(rule);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Example 10 with IndexRule

use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyDeleteIndexRuleSchemaRuleCommandToTheStoreInRecovery.

@Test
public void shouldApplyDeleteIndexRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplierFacade(newIndexApplier(), newApplier(true));
    final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
    record.setInUse(false);
    final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
    final IndexRule rule = indexRule(0, 1, 2, new SchemaIndexProvider.Descriptor("K", "X.Y"));
    final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(schemaStore, times(1)).setHighestPossibleIdInUse(record.getId());
    verify(schemaStore, times(1)).updateRecord(record);
    verify(indexingService, times(1)).dropIndex(rule);
    verify(cacheAccess, times(1)).removeSchemaRuleFromCache(command.getKey());
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Aggregations

IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)60 Test (org.junit.Test)42 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)24 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)22 SchemaRuleUtil.constraintIndexRule (org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule)14 NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)9 ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)9 LabelTokenRecord (org.neo4j.kernel.impl.store.record.LabelTokenRecord)9 PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)9 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)8 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)8 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)8 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)7 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)7 SchemaStorage (org.neo4j.kernel.impl.store.SchemaStorage)7 LabelTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand)7 PropertyKeyTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand)7 RelationshipTypeTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand)7 ArrayList (java.util.ArrayList)6 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)6