use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.
the class IndexDirectoryStructureTest method shouldSeeCorrectDirectoriesForSubProvider.
@Test
void shouldSeeCorrectDirectoriesForSubProvider() {
IndexDirectoryStructure parentStructure = directoriesByProvider(databaseStoreDir).forProvider(provider);
IndexProviderDescriptor subProvider = new IndexProviderDescriptor("sub", "0.3");
assertCorrectDirectories(directoriesBySubProvider(parentStructure).forProvider(subProvider), baseIndexDirectory.resolve(provider.getKey() + "-" + provider.getVersion()), baseIndexDirectory.resolve(provider.getKey() + "-" + provider.getVersion()).resolve(String.valueOf(indexId)).resolve(subProvider.getKey() + "-" + subProvider.getVersion()));
}
use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.
the class SchemaIndexMigratorTest method schemaAndLabelIndexesRemovedAfterSuccessfulMigration.
@Test
void schemaAndLabelIndexesRemovedAfterSuccessfulMigration() throws IOException {
StorageEngineFactory storageEngineFactory = mock(StorageEngineFactory.class);
StoreVersion version = mock(StoreVersion.class);
when(version.hasCompatibleCapabilities(any(), eq(CapabilityType.INDEX))).thenReturn(false);
when(storageEngineFactory.versionInformation(anyString())).thenReturn(version);
IndexImporterFactory indexImporterFactory = mock(IndexImporterFactory.class);
IndexDirectoryStructure directoryStructure = mock(IndexDirectoryStructure.class);
Path indexProviderRootDirectory = databaseLayout.file("just-some-directory");
when(directoryStructure.rootDirectory()).thenReturn(indexProviderRootDirectory);
SchemaIndexMigrator migrator = new SchemaIndexMigrator("Test migrator", fs, pageCache, directoryStructure, storageEngineFactory, true);
when(indexProvider.getProviderDescriptor()).thenReturn(new IndexProviderDescriptor("key", "version"));
migrator.migrate(databaseLayout, migrationLayout, progressReporter, "from", "to", indexImporterFactory);
migrator.moveMigratedFiles(migrationLayout, databaseLayout, "from", "to");
verify(fs).deleteRecursively(indexProviderRootDirectory);
}
use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.
the class SchemaIndexMigratorTest method shouldDeleteRelationshipIndexesAfterCrossFormatFamilyMigration.
@Test
void shouldDeleteRelationshipIndexesAfterCrossFormatFamilyMigration() throws IOException {
// given
IndexProviderDescriptor provider = new IndexProviderDescriptor("k", "v");
IndexDirectoryStructure directoryStructure = directoriesByProvider(databaseLayout.databaseDirectory()).forProvider(provider);
StorageEngineFactory storageEngineFactory = mock(StorageEngineFactory.class);
StoreVersion fromVersion = mock(StoreVersion.class);
StoreVersion toVersion = mock(StoreVersion.class);
when(fromVersion.hasCompatibleCapabilities(toVersion, CapabilityType.FORMAT)).thenReturn(false);
when(storageEngineFactory.versionInformation("from")).thenReturn(fromVersion);
when(storageEngineFactory.versionInformation("to")).thenReturn(toVersion);
List<SchemaRule> schemaRules = new ArrayList<>();
schemaRules.add(forSchema(SchemaDescriptor.forLabel(1, 2, 3)).withName("n1").materialise(1L));
schemaRules.add(forSchema(SchemaDescriptor.forRelType(5, 3)).withName("r1").materialise(2L));
schemaRules.add(forSchema(SchemaDescriptor.fulltext(RELATIONSHIP, new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 })).withName("r2").materialise(3L));
schemaRules.add(forSchema(SchemaDescriptor.fulltext(NODE, new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 })).withName("n2").materialise(4L));
when(storageEngineFactory.loadSchemaRules(any(), any(), any(), any(), any())).thenReturn(schemaRules);
SchemaIndexMigrator migrator = new SchemaIndexMigrator("Test migrator", fs, pageCache, directoryStructure, storageEngineFactory, false);
// when
migrator.migrate(databaseLayout, migrationLayout, progressReporter, "from", "to", IndexImporterFactory.EMPTY);
migrator.moveMigratedFiles(databaseLayout, migrationLayout, "from", "to");
// then
verify(fs, never()).deleteRecursively(directoryStructure.directoryForIndex(1L));
verify(fs).deleteRecursively(directoryStructure.directoryForIndex(2L));
verify(fs).deleteRecursively(directoryStructure.directoryForIndex(3L));
verify(fs, never()).deleteRecursively(directoryStructure.directoryForIndex(4L));
}
use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.
the class OperationsTest method setUp.
@BeforeEach
void setUp() throws Exception {
TxState realTxState = new TxState();
txState = Mockito.spy(realTxState);
when(transaction.getReasonIfTerminated()).thenReturn(Optional.empty());
when(transaction.lockClient()).thenReturn(locks);
when(transaction.dataWrite()).thenReturn(write);
when(transaction.isOpen()).thenReturn(true);
when(transaction.lockTracer()).thenReturn(LockTracer.NONE);
when(transaction.txState()).thenReturn(txState);
when(transaction.securityContext()).thenReturn(SecurityContext.authDisabled(AccessMode.Static.FULL, EMBEDDED_CONNECTION, DB_NAME));
logHelper = new SecurityLogHelper(getFormat());
securityLog = new CommunitySecurityLog((LogExtended) logHelper.getLogProvider().getLog(this.getClass()));
when(transaction.securityAuthorizationHandler()).thenReturn(new SecurityAuthorizationHandler(securityLog));
DefaultPooledCursors cursors = mock(DefaultPooledCursors.class);
nodeCursor = mock(FullAccessNodeCursor.class);
propertyCursor = mock(FullAccessPropertyCursor.class);
relationshipCursor = mock(DefaultRelationshipScanCursor.class);
when(cursors.allocateFullAccessNodeCursor(NULL)).thenReturn(nodeCursor);
when(cursors.allocateFullAccessPropertyCursor(NULL, INSTANCE)).thenReturn(propertyCursor);
when(cursors.allocateRelationshipScanCursor(NULL)).thenReturn(relationshipCursor);
StorageEngine engine = mock(StorageEngine.class);
storageReader = mock(StorageReader.class);
storageReaderSnapshot = mock(StorageSchemaReader.class);
when(storageReader.nodeExists(anyLong(), any())).thenReturn(true);
when(storageReader.constraintsGetForLabel(anyInt())).thenReturn(Collections.emptyIterator());
when(storageReader.constraintsGetAll()).thenReturn(Collections.emptyIterator());
when(storageReader.schemaSnapshot()).thenReturn(storageReaderSnapshot);
when(engine.newReader()).thenReturn(storageReader);
indexingService = mock(IndexingService.class);
Dependencies dependencies = new Dependencies();
var facade = mock(GraphDatabaseFacade.class);
dependencies.satisfyDependency(facade);
allStoreHolder = new AllStoreHolder(storageReader, transaction, cursors, mock(GlobalProcedures.class), mock(SchemaState.class), indexingService, mock(IndexStatisticsStore.class), dependencies, Config.defaults(), INSTANCE);
constraintIndexCreator = mock(ConstraintIndexCreator.class);
tokenHolders = mockedTokenHolders();
creationContext = mock(CommandCreationContext.class);
IndexingProvidersService indexingProvidersService = mock(IndexingProvidersService.class);
when(indexingProvidersService.indexProviderByName("native-btree-1.0")).thenReturn(GenericNativeIndexProvider.DESCRIPTOR);
when(indexingProvidersService.getDefaultProvider()).thenReturn(GenericNativeIndexProvider.DESCRIPTOR);
when(indexingProvidersService.indexProviderByName("fulltext-1.0")).thenReturn(FulltextIndexProviderFactory.DESCRIPTOR);
when(indexingProvidersService.getFulltextProvider()).thenReturn(FulltextIndexProviderFactory.DESCRIPTOR);
when(indexingProvidersService.indexProviderByName("provider-1.0")).thenReturn(new IndexProviderDescriptor("provider", "1.0"));
when(indexingProvidersService.completeConfiguration(any())).thenAnswer(inv -> inv.getArgument(0));
operations = new Operations(allStoreHolder, storageReader, mock(IndexTxStateUpdater.class), creationContext, transaction, new KernelToken(storageReader, creationContext, transaction, tokenHolders), cursors, constraintIndexCreator, mock(ConstraintSemantics.class), indexingProvidersService, Config.defaults(), INSTANCE, () -> KernelVersion.LATEST, mock(DbmsRuntimeRepository.class));
operations.initialize(NULL);
this.order = inOrder(locks, txState, storageReader, storageReaderSnapshot, creationContext);
}
use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.
the class IndexCleanupIT method mustClearIndexDirectoryOnDropWhileFailed.
@ParameterizedTest
@EnumSource(SchemaIndex.class)
void mustClearIndexDirectoryOnDropWhileFailed(SchemaIndex schemaIndex) throws IOException {
configureDb(schemaIndex);
createIndex(db, true);
IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor(schemaIndex.providerKey(), schemaIndex.providerVersion());
SetInitialStateInNativeIndex setInitialStateInNativeIndex = new SetInitialStateInNativeIndex(BYTE_FAILED, providerDescriptor);
restartDatabase(schemaIndex, setInitialStateInNativeIndex);
try (Transaction tx = db.beginTx()) {
for (IndexDefinition index : tx.schema().getIndexes()) {
// ignore the lookup indexes which are there by default and have nothing to do with this test
if (index.getIndexType() == IndexType.LOOKUP) {
continue;
}
IndexState indexState = tx.schema().getIndexState(index);
assertEquals(IndexState.FAILED, indexState, "expected index state to be " + IndexState.FAILED);
}
tx.commit();
}
// when
dropAllIndexes();
// then
assertNoIndexFilesExisting(providerDirectories(fs, db));
}
Aggregations