Search in sources :

Example 21 with RecordDatabaseLayout

use of org.neo4j.io.layout.recordstorage.RecordDatabaseLayout in project neo4j by neo4j.

the class MultipleIndexPopulationStressIT method createRandomData.

private void createRandomData(long nodeCount, long relCount) throws Exception {
    Config config = Config.defaults(neo4j_home, directory.homePath());
    RecordFormats recordFormats = RecordFormatSelector.selectForConfig(config, NullLogProvider.getInstance());
    try (RandomDataInput input = new RandomDataInput(nodeCount, relCount);
        JobScheduler jobScheduler = new ThreadPoolJobScheduler()) {
        RecordDatabaseLayout layout = RecordDatabaseLayout.of(config);
        IndexImporterFactory indexImporterFactory = new IndexImporterFactoryImpl(config);
        BatchImporter importer = new ParallelBatchImporter(layout, fileSystemAbstraction, PageCacheTracer.NULL, DEFAULT, NullLogService.getInstance(), ExecutionMonitor.INVISIBLE, EMPTY, config, recordFormats, NO_MONITOR, jobScheduler, Collector.EMPTY, TransactionLogInitializer.getLogFilesInitializer(), indexImporterFactory, INSTANCE);
        importer.doImport(input);
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) ParallelBatchImporter(org.neo4j.internal.batchimport.ParallelBatchImporter) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) BatchImporter(org.neo4j.internal.batchimport.BatchImporter) ParallelBatchImporter(org.neo4j.internal.batchimport.ParallelBatchImporter) Config(org.neo4j.configuration.Config) IndexImporterFactory(org.neo4j.internal.batchimport.IndexImporterFactory) IndexImporterFactoryImpl(org.neo4j.kernel.impl.index.schema.IndexImporterFactoryImpl) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) RecordDatabaseLayout(org.neo4j.io.layout.recordstorage.RecordDatabaseLayout)

Example 22 with RecordDatabaseLayout

use of org.neo4j.io.layout.recordstorage.RecordDatabaseLayout in project neo4j by neo4j.

the class FulltextIndexProviderTest method indexWithUnknownAnalyzerWillBeMarkedAsFailedOnStartup.

@Test
void indexWithUnknownAnalyzerWillBeMarkedAsFailedOnStartup() throws Exception {
    // Create a full-text index.
    long indexId;
    try (KernelTransactionImplementation transaction = getKernelTransaction()) {
        int[] propertyIds = { propIdHa };
        SchemaDescriptor schema = SchemaDescriptors.fulltext(EntityType.NODE, new int[] { labelIdHa }, propertyIds);
        IndexPrototype prototype = IndexPrototype.forSchema(schema).withIndexType(FULLTEXT).withName(NAME);
        SchemaWrite schemaWrite = transaction.schemaWrite();
        IndexDescriptor index = schemaWrite.indexCreate(prototype);
        indexId = index.getId();
        transaction.success();
    }
    // Modify the full-text index such that it has an analyzer configured that does not exist.
    controller.restartDbms(builder -> {
        var cacheTracer = NULL;
        FileSystemAbstraction fs = builder.getFileSystem();
        RecordDatabaseLayout databaseLayout = RecordDatabaseLayout.of(Config.defaults(GraphDatabaseSettings.neo4j_home, builder.getHomeDirectory()));
        DefaultIdGeneratorFactory idGenFactory = new DefaultIdGeneratorFactory(fs, RecoveryCleanupWorkCollector.ignore(), databaseLayout.getDatabaseName());
        try (JobScheduler scheduler = JobSchedulerFactory.createInitialisedScheduler();
            PageCache pageCache = StandalonePageCacheFactory.createPageCache(fs, scheduler, cacheTracer)) {
            StoreFactory factory = new StoreFactory(databaseLayout, Config.defaults(), idGenFactory, pageCache, fs, NullLogProvider.getInstance(), cacheTracer, writable());
            var cursorContext = CursorContext.NULL;
            try (NeoStores neoStores = factory.openAllNeoStores(false);
                var storeCursors = new CachedStoreCursors(neoStores, cursorContext)) {
                TokenHolders tokens = StoreTokens.readOnlyTokenHolders(neoStores, storeCursors);
                SchemaStore schemaStore = neoStores.getSchemaStore();
                SchemaStorage storage = new SchemaStorage(schemaStore, tokens, () -> KernelVersion.LATEST);
                IndexDescriptor index = (IndexDescriptor) storage.loadSingleSchemaRule(indexId, storeCursors);
                Map<String, Value> indexConfigMap = new HashMap<>(index.getIndexConfig().asMap());
                for (Map.Entry<String, Value> entry : indexConfigMap.entrySet()) {
                    if (entry.getKey().contains("analyzer")) {
                        // This analyzer does not exist!
                        entry.setValue(Values.stringValue("bla-bla-lyzer"));
                    }
                }
                index = index.withIndexConfig(IndexConfig.with(indexConfigMap));
                storage.writeSchemaRule(index, cursorContext, INSTANCE, storeCursors);
                schemaStore.flush(cursorContext);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return builder;
    });
    // Verify that the index comes up in a failed state.
    try (Transaction tx = db.beginTx()) {
        IndexDefinition index = tx.schema().getIndexByName(NAME);
        Schema.IndexState indexState = tx.schema().getIndexState(index);
        assertThat(indexState).isEqualTo(Schema.IndexState.FAILED);
        String indexFailure = tx.schema().getIndexFailure(index);
        assertThat(indexFailure).contains("bla-bla-lyzer");
    }
    // Verify that the failed index can be dropped.
    try (Transaction tx = db.beginTx()) {
        tx.schema().getIndexByName(NAME).drop();
        assertThrows(IllegalArgumentException.class, () -> tx.schema().getIndexByName(NAME));
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        assertThrows(IllegalArgumentException.class, () -> tx.schema().getIndexByName(NAME));
    }
    controller.restartDbms();
    try (Transaction tx = db.beginTx()) {
        assertThrows(IllegalArgumentException.class, () -> tx.schema().getIndexByName(NAME));
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) HashMap(java.util.HashMap) Schema(org.neo4j.graphdb.schema.Schema) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) CachedStoreCursors(org.neo4j.kernel.impl.store.cursor.CachedStoreCursors) SchemaStorage(org.neo4j.internal.recordstorage.SchemaStorage) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) TokenHolders(org.neo4j.token.TokenHolders) RecordDatabaseLayout(org.neo4j.io.layout.recordstorage.RecordDatabaseLayout) PageCache(org.neo4j.io.pagecache.PageCache) JobScheduler(org.neo4j.scheduler.JobScheduler) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) KernelException(org.neo4j.exceptions.KernelException) TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) IndexNotApplicableKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Transaction(org.neo4j.graphdb.Transaction) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Value(org.neo4j.values.storable.Value) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 23 with RecordDatabaseLayout

use of org.neo4j.io.layout.recordstorage.RecordDatabaseLayout in project neo4j by neo4j.

the class CheckConsistencyCommandIT method runsConsistencyChecker.

@Test
void runsConsistencyChecker() throws Exception {
    ConsistencyCheckService consistencyCheckService = mock(ConsistencyCheckService.class);
    CheckConsistencyCommand checkConsistencyCommand = new CheckConsistencyCommand(new ExecutionContext(homeDir, confPath), consistencyCheckService);
    RecordDatabaseLayout databaseLayout = RecordDatabaseLayout.of(neo4jLayout, "mydb");
    when(consistencyCheckService.runFullConsistencyCheck(eq(databaseLayout), any(Config.class), any(ProgressMonitorFactory.class), any(LogProvider.class), any(FileSystemAbstraction.class), eq(false), any(), any(ConsistencyFlags.class))).thenReturn(ConsistencyCheckService.Result.success(null, null));
    CommandLine.populateCommand(checkConsistencyCommand, "--database=mydb");
    checkConsistencyCommand.execute();
    verify(consistencyCheckService).runFullConsistencyCheck(eq(databaseLayout), any(Config.class), any(ProgressMonitorFactory.class), any(LogProvider.class), any(FileSystemAbstraction.class), eq(false), any(), any(ConsistencyFlags.class));
}
Also used : LogProvider(org.neo4j.logging.LogProvider) ExecutionContext(org.neo4j.cli.ExecutionContext) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ProgressMonitorFactory(org.neo4j.internal.helpers.progress.ProgressMonitorFactory) ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) Config(org.neo4j.configuration.Config) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) CheckConsistencyCommand(org.neo4j.consistency.CheckConsistencyCommand) RecordDatabaseLayout(org.neo4j.io.layout.recordstorage.RecordDatabaseLayout) Test(org.junit.jupiter.api.Test)

Example 24 with RecordDatabaseLayout

use of org.neo4j.io.layout.recordstorage.RecordDatabaseLayout in project neo4j by neo4j.

the class CheckConsistencyCommandIT method canRunOnBackup.

@Test
void canRunOnBackup() throws Exception {
    ConsistencyCheckService consistencyCheckService = mock(ConsistencyCheckService.class);
    RecordDatabaseLayout backupLayout = RecordDatabaseLayout.ofFlat(testDirectory.directory("backup"));
    prepareBackupDatabase(backupLayout);
    CheckConsistencyCommand checkConsistencyCommand = new CheckConsistencyCommand(new ExecutionContext(homeDir, confPath), consistencyCheckService);
    when(consistencyCheckService.runFullConsistencyCheck(eq(backupLayout), any(Config.class), any(ProgressMonitorFactory.class), any(LogProvider.class), any(FileSystemAbstraction.class), eq(false), any(), any(ConsistencyFlags.class))).thenReturn(ConsistencyCheckService.Result.success(null, null));
    CommandLine.populateCommand(checkConsistencyCommand, "--backup=" + backupLayout.databaseDirectory());
    checkConsistencyCommand.execute();
    verify(consistencyCheckService).runFullConsistencyCheck(eq(backupLayout), any(Config.class), any(ProgressMonitorFactory.class), any(LogProvider.class), any(FileSystemAbstraction.class), eq(false), any(), any(ConsistencyFlags.class));
}
Also used : LogProvider(org.neo4j.logging.LogProvider) ExecutionContext(org.neo4j.cli.ExecutionContext) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ProgressMonitorFactory(org.neo4j.internal.helpers.progress.ProgressMonitorFactory) ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) Config(org.neo4j.configuration.Config) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) CheckConsistencyCommand(org.neo4j.consistency.CheckConsistencyCommand) RecordDatabaseLayout(org.neo4j.io.layout.recordstorage.RecordDatabaseLayout) Test(org.junit.jupiter.api.Test)

Example 25 with RecordDatabaseLayout

use of org.neo4j.io.layout.recordstorage.RecordDatabaseLayout in project neo4j by neo4j.

the class CheckConsistencyCommandIT method consistencyCheckerRespectDatabaseLock.

@Test
void consistencyCheckerRespectDatabaseLock() throws CannotWriteException, IOException {
    ConsistencyCheckService consistencyCheckService = mock(ConsistencyCheckService.class);
    CheckConsistencyCommand checkConsistencyCommand = new CheckConsistencyCommand(new ExecutionContext(homeDir, confPath), consistencyCheckService);
    RecordDatabaseLayout databaseLayout = RecordDatabaseLayout.of(neo4jLayout, "mydb");
    testDirectory.getFileSystem().mkdirs(databaseLayout.databaseDirectory());
    try (Closeable ignored = LockChecker.checkDatabaseLock(databaseLayout)) {
        CommandLine.populateCommand(checkConsistencyCommand, "--database=mydb", "--verbose");
        CommandFailedException exception = assertThrows(CommandFailedException.class, checkConsistencyCommand::execute);
        assertThat(exception.getCause()).isInstanceOf(FileLockException.class);
        assertThat(exception.getMessage()).isEqualTo("The database is in use. Stop database 'mydb' and try again.");
    }
}
Also used : ExecutionContext(org.neo4j.cli.ExecutionContext) Closeable(java.io.Closeable) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) CheckConsistencyCommand(org.neo4j.consistency.CheckConsistencyCommand) RecordDatabaseLayout(org.neo4j.io.layout.recordstorage.RecordDatabaseLayout) CommandFailedException(org.neo4j.cli.CommandFailedException) Test(org.junit.jupiter.api.Test)

Aggregations

RecordDatabaseLayout (org.neo4j.io.layout.recordstorage.RecordDatabaseLayout)29 Test (org.junit.jupiter.api.Test)17 Config (org.neo4j.configuration.Config)13 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)11 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)9 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)8 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)7 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)7 IOException (java.io.IOException)6 Path (java.nio.file.Path)6 ConsistencyFlags (org.neo4j.consistency.checking.full.ConsistencyFlags)6 NeoStores (org.neo4j.kernel.impl.store.NeoStores)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 ExecutionContext (org.neo4j.cli.ExecutionContext)5 CheckConsistencyCommand (org.neo4j.consistency.CheckConsistencyCommand)5 ProgressMonitorFactory (org.neo4j.internal.helpers.progress.ProgressMonitorFactory)5 RecordFormats (org.neo4j.kernel.impl.store.format.RecordFormats)4 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)4 TokenHolders (org.neo4j.token.TokenHolders)4 ArrayList (java.util.ArrayList)3