Search in sources :

Example 36 with DatabaseLayout

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

the class RecoveryIT method shouldForceRecoveryEvenThoughNotSeeminglyRequired.

@Test
void shouldForceRecoveryEvenThoughNotSeeminglyRequired() throws Exception {
    // given
    GraphDatabaseAPI db = createDatabase();
    generateSomeData(db);
    DatabaseLayout layout = db.databaseLayout();
    managementService.shutdown();
    assertFalse(isRecoveryRequired(layout));
    // Make an ID generator, say for the node store, dirty
    DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fileSystem, immediate(), "my db");
    try (IdGenerator idGenerator = idGeneratorFactory.open(pageCache, layout.idNodeStore(), IdType.NODE, () -> 0L, /*will not be used*/
    10_000, writable(), Config.defaults(), NULL, Sets.immutable.empty())) {
        // Merely opening a marker will make the backing GBPTree dirty
        idGenerator.marker(NULL).close();
    }
    assertFalse(isRecoveryRequired(layout));
    assertTrue(idGeneratorIsDirty(layout.idNodeStore(), IdType.NODE));
    // when
    MutableBoolean recoveryRunEvenThoughNoCommitsAfterLastCheckpoint = new MutableBoolean();
    RecoveryStartInformationProvider.Monitor monitor = new RecoveryStartInformationProvider.Monitor() {

        @Override
        public void noCommitsAfterLastCheckPoint(LogPosition logPosition) {
            recoveryRunEvenThoughNoCommitsAfterLastCheckpoint.setTrue();
        }
    };
    Monitors monitors = new Monitors();
    monitors.addMonitorListener(monitor);
    Recovery.performRecovery(fileSystem, pageCache, EMPTY, Config.defaults(), layout, defaultStorageEngine(), true, nullLogProvider(), monitors, Iterables.cast(Services.loadAll(ExtensionFactory.class)), Optional.empty(), null, INSTANCE, Clock.systemUTC());
    // then
    assertFalse(idGeneratorIsDirty(layout.idNodeStore(), IdType.NODE));
    assertTrue(recoveryRunEvenThoughNoCommitsAfterLastCheckpoint.booleanValue());
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) Monitors(org.neo4j.monitoring.Monitors) IdGenerator(org.neo4j.internal.id.IdGenerator) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 37 with DatabaseLayout

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

the class DatabaseFileListingTest method shouldListNeostoreFiles.

@Test
void shouldListNeostoreFiles() throws Exception {
    DatabaseLayout layout = database.getDatabaseLayout();
    Set<Path> expectedFiles = layout.storeFiles();
    // there was no rotation
    ResourceIterator<StoreFileMetadata> storeFiles = database.listStoreFiles(false);
    Set<Path> listedStoreFiles = storeFiles.stream().map(StoreFileMetadata::path).collect(Collectors.toSet());
    assertEquals(expectedFiles, listedStoreFiles);
}
Also used : Path(java.nio.file.Path) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata) Test(org.junit.jupiter.api.Test)

Example 38 with DatabaseLayout

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

the class LabelScanStoreTxApplyRaceIT method shouldStressIt.

/**
 * The test case is basically loads of concurrent CREATE/DELETE NODE or sometimes just CREATE, keeping the created node in an array
 * for dedicated deleter threads to pick up and delete as fast as they can see them. This concurrently with large creation transactions.
 */
@Test
void shouldStressIt() throws Throwable {
    // given
    Race race = new Race().withMaxDuration(5, TimeUnit.SECONDS);
    AtomicReferenceArray<Node> nodeHeads = new AtomicReferenceArray<>(NUMBER_OF_CREATORS);
    for (int i = 0; i < NUMBER_OF_CREATORS; i++) {
        race.addContestant(creator(nodeHeads, i));
    }
    race.addContestants(NUMBER_OF_DELETORS, deleter(nodeHeads));
    // when
    race.go();
    // then
    DatabaseLayout dbLayout = db.databaseLayout();
    managementService.shutdown();
    assertTrue(new ConsistencyCheckService().runFullConsistencyCheck(dbLayout, defaults(GraphDatabaseSettings.neo4j_home, testDirectory.homePath()), NONE, new Log4jLogProvider(System.out), false, new ConsistencyFlags(true, true, true)).isSuccessful());
}
Also used : ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) Race(org.neo4j.test.Race) Node(org.neo4j.graphdb.Node) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Test(org.junit.jupiter.api.Test)

Example 39 with DatabaseLayout

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

the class IndexRecoveryIT method snapshotFs.

private void snapshotFs(Path snapshotDir) {
    try {
        DatabaseLayout layout = databaseLayout;
        FileUtils.copyDirectory(layout.databaseDirectory(), snapshotDir.resolve("data"));
        FileUtils.copyDirectory(layout.getTransactionLogsDirectory(), snapshotDir.resolve("transactions"));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) IOException(java.io.IOException)

Example 40 with DatabaseLayout

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

the class IndexRecoveryIT method shouldBeAbleToRecoverInTheMiddleOfPopulatingAnIndexWhereLogHasRotated.

@Test
void shouldBeAbleToRecoverInTheMiddleOfPopulatingAnIndexWhereLogHasRotated() throws Exception {
    // Given
    startDb();
    Semaphore populationSemaphore = new Semaphore(0);
    Future<Void> killFuture;
    try {
        when(mockedIndexProvider.getPopulator(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class))).thenReturn(indexPopulatorWithControlledCompletionTiming(populationSemaphore));
        createSomeData();
        createIndex(myLabel);
        // And Given
        killFuture = killDbInSeparateThread();
        int iterations = 0;
        do {
            rotateLogsAndCheckPoint();
            Thread.sleep(10);
        } while (iterations++ < 100 && !killFuture.isDone());
    } finally {
        populationSemaphore.release();
    }
    killFuture.get();
    when(mockedIndexProvider.getInitialState(any(IndexDescriptor.class), any(CursorContext.class))).thenReturn(InternalIndexState.POPULATING);
    Semaphore recoverySemaphore = new Semaphore(0);
    try {
        when(mockedIndexProvider.getPopulator(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class))).thenReturn(indexPopulatorWithControlledCompletionTiming(recoverySemaphore));
        boolean recoveryRequired = Recovery.isRecoveryRequired(testDirectory.getFileSystem(), databaseLayout, defaults(), INSTANCE);
        monitors.addMonitorListener(new MyRecoveryMonitor(recoverySemaphore));
        // When
        startDb();
        try (Transaction transaction = db.beginTx()) {
            assertThat(transaction.schema().getIndexes(myLabel)).hasSize(1);
            assertThat(transaction.schema().getIndexes(myLabel)).extracting(i -> transaction.schema().getIndexState(i)).containsOnly(Schema.IndexState.POPULATING);
        }
        // in case if kill was not that fast and killed db after flush there will be no need to do recovery and
        // we will not gonna need to get index populators during recovery index service start
        verify(mockedIndexProvider, times(recoveryRequired ? 3 : 2)).getPopulator(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class));
        verify(mockedIndexProvider, never()).getOnlineAccessor(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(TokenNameLookup.class));
    } finally {
        recoverySemaphore.release();
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SchemaIndexTestHelper.singleInstanceIndexProviderFactory(org.neo4j.kernel.impl.api.index.SchemaIndexTestHelper.singleInstanceIndexProviderFactory) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TokenNameLookup(org.neo4j.common.TokenNameLookup) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) Future(java.util.concurrent.Future) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Monitors(org.neo4j.monitoring.Monitors) Arrays.asList(java.util.Arrays.asList) Transaction(org.neo4j.graphdb.Transaction) Path(java.nio.file.Path) RecoveryMonitor(org.neo4j.kernel.recovery.RecoveryMonitor) PageCache(org.neo4j.io.pagecache.PageCache) TokenIndexProviderFactory(org.neo4j.kernel.impl.index.schema.TokenIndexProviderFactory) Recovery(org.neo4j.kernel.recovery.Recovery) Set(java.util.Set) FileUtils(org.neo4j.io.fs.FileUtils) TestDirectory(org.neo4j.test.rule.TestDirectory) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) Neo4jLayoutExtension(org.neo4j.test.extension.Neo4jLayoutExtension) Schema(org.neo4j.graphdb.schema.Schema) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Test(org.junit.jupiter.api.Test) GraphDatabaseSettings.default_schema_provider(org.neo4j.configuration.GraphDatabaseSettings.default_schema_provider) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) PROVIDER_DESCRIPTOR(org.neo4j.kernel.impl.api.index.TestIndexProviderDescriptor.PROVIDER_DESCRIPTOR) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CollectingIndexUpdater(org.neo4j.kernel.impl.index.schema.CollectingIndexUpdater) Label(org.neo4j.graphdb.Label) Config.defaults(org.neo4j.configuration.Config.defaults) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) MINUTES(java.util.concurrent.TimeUnit.MINUTES) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) Node(org.neo4j.graphdb.Node) IndexProvider(org.neo4j.kernel.api.index.IndexProvider) Values(org.neo4j.values.storable.Values) HashSet(java.util.HashSet) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Inject(org.neo4j.test.extension.Inject) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ONLINE(org.neo4j.internal.kernel.api.InternalIndexState.ONLINE) ExecutorService(java.util.concurrent.ExecutorService) IndexSample(org.neo4j.kernel.api.index.IndexSample) Semaphore(java.util.concurrent.Semaphore) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) LogAppendEvent(org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent) StoreMigrationParticipant(org.neo4j.storageengine.migration.StoreMigrationParticipant) Mockito.when(org.mockito.Mockito.when) Label.label(org.neo4j.graphdb.Label.label) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) AfterEach(org.junit.jupiter.api.AfterEach) ExtensionFactory(org.neo4j.kernel.extension.ExtensionFactory) Mockito.never(org.mockito.Mockito.never) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) TokenNameLookup(org.neo4j.common.TokenNameLookup) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Semaphore(java.util.concurrent.Semaphore) CursorContext(org.neo4j.io.pagecache.context.CursorContext) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

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