Search in sources :

Example 46 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class AllNodesInStoreExistInLabelIndexTest method replaceLabelIndexWithCopy.

private void replaceLabelIndexWithCopy(Path labelIndexFileCopy) throws IOException {
    managementService.shutdown();
    DatabaseLayout databaseLayout = db.databaseLayout();
    fs.deleteFile(databaseLayout.labelScanStore());
    fs.copyFile(labelIndexFileCopy, databaseLayout.labelScanStore());
}
Also used : DatabaseLayout(org.neo4j.io.layout.DatabaseLayout)

Example 47 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class AllNodesInStoreExistInLabelIndexTest method reportNotCleanLabelIndex.

@Test
void reportNotCleanLabelIndex() throws IOException, ConsistencyCheckIncompleteException {
    DatabaseLayout databaseLayout = db.databaseLayout();
    someData();
    checkPointer.forceCheckPoint(new SimpleTriggerInfo("forcedCheckpoint"));
    Path labelIndexFileCopy = databaseLayout.file("label_index_copy");
    copyFile(databaseLayout.labelScanStore(), labelIndexFileCopy);
    try (Transaction tx = db.beginTx()) {
        tx.createNode(LABEL_ONE);
        tx.commit();
    }
    managementService.shutdown();
    copyFile(labelIndexFileCopy, databaseLayout.labelScanStore());
    ConsistencyCheckService.Result result = fullConsistencyCheck();
    assertFalse(result.isSuccessful(), "Expected consistency check to fail");
    assertThat(readReport(result)).contains("WARN  Index was dirty on startup which means it was not shutdown correctly and need to be cleaned up with a successful recovery.");
}
Also used : Path(java.nio.file.Path) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) Transaction(org.neo4j.graphdb.Transaction) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) Test(org.junit.jupiter.api.Test)

Example 48 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class AllNodesInStoreExistInLabelIndexTest method reportNotCleanLabelIndexWithCorrectData.

@Test
void reportNotCleanLabelIndexWithCorrectData() throws IOException, ConsistencyCheckIncompleteException {
    DatabaseLayout databaseLayout = db.databaseLayout();
    someData();
    checkPointer.forceCheckPoint(new SimpleTriggerInfo("forcedCheckpoint"));
    Path labelIndexFileCopy = databaseLayout.file("label_index_copy");
    copyFile(databaseLayout.labelScanStore(), labelIndexFileCopy);
    managementService.shutdown();
    copyFile(labelIndexFileCopy, databaseLayout.labelScanStore());
    ConsistencyCheckService.Result result = fullConsistencyCheck();
    assertTrue(result.isSuccessful(), "Expected consistency check to fail");
    assertThat(readReport(result)).contains("WARN  Index was dirty on startup which means it was not shutdown correctly and need to be cleaned up with a successful recovery.");
}
Also used : Path(java.nio.file.Path) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) Test(org.junit.jupiter.api.Test)

Example 49 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class MemoryRecommendationsCommandTest method includeAllDatabasesToMemoryRecommendations.

@Test
void includeAllDatabasesToMemoryRecommendations() throws IOException {
    PrintStream output = mock(PrintStream.class);
    Path homeDir = neo4jLayout.homeDirectory();
    Path configDir = homeDir.resolve("conf");
    Files.createDirectories(configDir);
    Path configFile = configDir.resolve(DEFAULT_CONFIG_FILE_NAME);
    Files.createFile(configFile);
    long totalPageCacheSize = 0;
    long totalLuceneIndexesSize = 0;
    for (int i = 0; i < 5; i++) {
        DatabaseLayout databaseLayout = neo4jLayout.databaseLayout("db" + i);
        createDatabaseWithNativeIndexes(homeDir, databaseLayout.getDatabaseName());
        long[] expectedSizes = calculatePageCacheFileSize(databaseLayout);
        totalPageCacheSize += expectedSizes[0];
        totalLuceneIndexesSize += expectedSizes[1];
    }
    DatabaseLayout systemLayout = neo4jLayout.databaseLayout(SYSTEM_DATABASE_NAME);
    long[] expectedSizes = calculatePageCacheFileSize(systemLayout);
    totalPageCacheSize += expectedSizes[0];
    totalLuceneIndexesSize += expectedSizes[1];
    MemoryRecommendationsCommand command = new MemoryRecommendationsCommand(new ExecutionContext(homeDir, configDir, output, mock(PrintStream.class), testDirectory.getFileSystem()));
    CommandLine.populateCommand(command, "--memory=8g");
    command.execute();
    final long expectedLuceneIndexesSize = totalLuceneIndexesSize;
    final long expectedPageCacheSize = totalPageCacheSize;
    verify(output).println(contains("Total size of lucene indexes in all databases: " + bytesToString(expectedLuceneIndexesSize)));
    verify(output).println(contains("Total size of data and native indexes in all databases: " + bytesToString(expectedPageCacheSize)));
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) ExecutionContext(org.neo4j.cli.ExecutionContext) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Test(org.junit.jupiter.api.Test)

Example 50 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class IndexConsistencyIT method fullConsistencyCheck.

private ConsistencyCheckService.Result fullConsistencyCheck() throws ConsistencyCheckIncompleteException, IOException {
    try (FileSystemAbstraction fsa = new DefaultFileSystemAbstraction()) {
        ConsistencyCheckService service = new ConsistencyCheckService();
        DatabaseLayout databaseLayout = db.databaseLayout();
        Config config = Config.defaults(logs_directory, databaseLayout.databaseDirectory());
        return service.runFullConsistencyCheck(databaseLayout, config, NONE, log, fsa, false, ConsistencyFlags.DEFAULT);
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Config(org.neo4j.configuration.Config) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService)

Aggregations

DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)108 Test (org.junit.jupiter.api.Test)66 Path (java.nio.file.Path)51 Config (org.neo4j.configuration.Config)35 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)24 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)19 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)17 PageCache (org.neo4j.io.pagecache.PageCache)17 IOException (java.io.IOException)16 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)16 Transaction (org.neo4j.graphdb.Transaction)13 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)10 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)9 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)9 CommandFailedException (org.neo4j.cli.CommandFailedException)8 ExecutionContext (org.neo4j.cli.ExecutionContext)8 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)8 StorageEngineFactory (org.neo4j.storageengine.api.StorageEngineFactory)8 Closeable (java.io.Closeable)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7