Search in sources :

Example 1 with Kernel

use of org.neo4j.kernel.api.Kernel in project neo4j by neo4j.

the class Database method buildKernel.

private DatabaseKernelModule buildKernel(LogFiles logFiles, TransactionAppender appender, IndexingService indexingService, DatabaseSchemaState databaseSchemaState, StorageEngine storageEngine, TransactionIdStore transactionIdStore, KernelVersionRepository kernelVersionRepository, AvailabilityGuard databaseAvailabilityGuard, SystemNanoClock clock, IndexStatisticsStore indexStatisticsStore, LeaseService leaseService) {
    AtomicReference<CpuClock> cpuClockRef = setupCpuClockAtomicReference();
    TransactionCommitProcess transactionCommitProcess = commitProcessFactory.create(appender, storageEngine, namedDatabaseId, readOnlyDatabaseChecker);
    /*
         * This is used by explicit indexes and constraint indexes whenever a transaction is to be spawned
         * from within an existing transaction. It smells, and we should look over alternatives when time permits.
         */
    Supplier<Kernel> kernelProvider = () -> kernelModule.kernelAPI();
    ConstraintIndexCreator constraintIndexCreator = new ConstraintIndexCreator(kernelProvider, indexingService, internalLogProvider);
    TransactionExecutionMonitor transactionExecutionMonitor = getMonitors().newMonitor(TransactionExecutionMonitor.class);
    KernelTransactions kernelTransactions = life.add(new KernelTransactions(databaseConfig, locks, constraintIndexCreator, transactionCommitProcess, databaseTransactionEventListeners, transactionStats, databaseAvailabilityGuard, storageEngine, globalProcedures, transactionIdStore, globalDependencies.resolveDependency(DbmsRuntimeRepository.class), kernelVersionRepository, clock, cpuClockRef, accessCapabilityFactory, versionContextSupplier, collectionsFactorySupplier, constraintSemantics, databaseSchemaState, tokenHolders, getNamedDatabaseId(), indexingService, indexStatisticsStore, databaseDependencies, tracers, leaseService, transactionsMemoryPool, readOnlyDatabaseChecker, transactionExecutionMonitor, externalIdReuseConditionProvider));
    buildTransactionMonitor(kernelTransactions, databaseConfig);
    KernelImpl kernel = new KernelImpl(kernelTransactions, databaseHealth, transactionStats, globalProcedures, databaseConfig, storageEngine, transactionExecutionMonitor);
    life.add(kernel);
    final DatabaseFileListing fileListing = new DatabaseFileListing(databaseLayout, logFiles, indexingService, storageEngine, idGeneratorFactory);
    databaseDependencies.satisfyDependency(fileListing);
    return new DatabaseKernelModule(transactionCommitProcess, kernel, kernelTransactions, fileListing);
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) DatabaseFileListing(org.neo4j.kernel.impl.transaction.state.DatabaseFileListing) CpuClock(org.neo4j.resources.CpuClock) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) TransactionExecutionMonitor(org.neo4j.kernel.impl.query.TransactionExecutionMonitor) KernelTransactions(org.neo4j.kernel.impl.api.KernelTransactions) KernelImpl(org.neo4j.kernel.impl.api.KernelImpl) Kernel(org.neo4j.kernel.api.Kernel)

Example 2 with Kernel

use of org.neo4j.kernel.api.Kernel in project neo4j by neo4j.

the class TestRecoveryScenarios method shouldRecoverCounts.

@Test
void shouldRecoverCounts() throws Exception {
    // GIVEN
    Node node = createNode(label);
    checkPoint();
    deleteNode(node);
    // WHEN
    crashAndRestart();
    // THEN
    // -- really the problem was that recovery threw exception, so mostly assert that.
    Kernel kernel = db.getDependencyResolver().resolveDependency(Kernel.class);
    try (KernelTransaction tx = kernel.beginTransaction(EXPLICIT, LoginContext.AUTH_DISABLED)) {
        assertEquals(0, tx.dataRead().countsForNode(ANY_LABEL));
        final TokenHolder holder = db.getDependencyResolver().resolveDependency(TokenHolders.class).labelTokens();
        int labelId = holder.getIdByName(label.name());
        assertEquals(0, tx.dataRead().countsForNode(labelId));
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Node(org.neo4j.graphdb.Node) TokenHolder(org.neo4j.token.api.TokenHolder) TokenHolders(org.neo4j.token.TokenHolders) Kernel(org.neo4j.kernel.api.Kernel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with Kernel

use of org.neo4j.kernel.api.Kernel in project neo4j by neo4j.

the class CountsStoreRecoveryTest method shouldRecoverTheCountsStoreEvenWhenIfNeoStoreDoesNotNeedRecovery.

@Test
void shouldRecoverTheCountsStoreEvenWhenIfNeoStoreDoesNotNeedRecovery() throws Exception {
    // given
    createNode("A");
    checkPoint();
    createNode("B");
    flushNeoStoreOnly();
    // when
    crashAndRestart();
    // then
    Kernel kernel = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(Kernel.class);
    try (KernelTransaction tx = kernel.beginTransaction(EXPLICIT, AUTH_DISABLED)) {
        assertEquals(1, tx.dataRead().countsForNode(tx.tokenRead().nodeLabel("A")));
        assertEquals(1, tx.dataRead().countsForNode(tx.tokenRead().nodeLabel("B")));
        assertEquals(2, tx.dataRead().countsForNode(NO_TOKEN));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Kernel(org.neo4j.kernel.api.Kernel) Test(org.junit.jupiter.api.Test)

Example 4 with Kernel

use of org.neo4j.kernel.api.Kernel in project neo4j by neo4j.

the class RebuildCountsTest method shouldRebuildMissingCountsStoreOnStart.

@Test
void shouldRebuildMissingCountsStoreOnStart() throws IOException, TransactionFailureException {
    // given
    createAliensAndHumans();
    // when
    FileSystemAbstraction fs = shutdown();
    deleteCounts(fs);
    restart(fs);
    // then
    Kernel kernel = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(Kernel.class);
    try (KernelTransaction tx = kernel.beginTransaction(EXPLICIT, AUTH_DISABLED)) {
        assertEquals(ALIENS + HUMANS, tx.dataRead().countsForNode(-1));
        assertEquals(ALIENS, tx.dataRead().countsForNode(labelId(ALIEN)));
        assertEquals(HUMANS, tx.dataRead().countsForNode(labelId(HUMAN)));
    }
    // and also
    assertRebuildLogged();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) UncloseableDelegatingFileSystemAbstraction(org.neo4j.io.fs.UncloseableDelegatingFileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Kernel(org.neo4j.kernel.api.Kernel) Test(org.junit.jupiter.api.Test)

Example 5 with Kernel

use of org.neo4j.kernel.api.Kernel in project neo4j by neo4j.

the class RebuildCountsTest method shouldRebuildMissingCountsStoreAfterRecovery.

@Test
void shouldRebuildMissingCountsStoreAfterRecovery() throws IOException, TransactionFailureException {
    // given
    createAliensAndHumans();
    // when
    rotateLog();
    deleteHumans();
    FileSystemAbstraction fs = crash();
    deleteCounts(fs);
    restart(fs);
    // then
    Kernel kernel = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(Kernel.class);
    try (KernelTransaction tx = kernel.beginTransaction(EXPLICIT, AUTH_DISABLED)) {
        assertEquals(ALIENS, tx.dataRead().countsForNode(-1));
        assertEquals(ALIENS, tx.dataRead().countsForNode(labelId(ALIEN)));
        assertEquals(0, tx.dataRead().countsForNode(labelId(HUMAN)));
    }
    // and also
    assertRebuildLogged();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) UncloseableDelegatingFileSystemAbstraction(org.neo4j.io.fs.UncloseableDelegatingFileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Kernel(org.neo4j.kernel.api.Kernel) Test(org.junit.jupiter.api.Test)

Aggregations

Kernel (org.neo4j.kernel.api.Kernel)14 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)10 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Test (org.junit.jupiter.api.Test)4 TokenHolders (org.neo4j.token.TokenHolders)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 UncloseableDelegatingFileSystemAbstraction (org.neo4j.io.fs.UncloseableDelegatingFileSystemAbstraction)2 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 Dependencies (org.neo4j.collection.Dependencies)1 DependencyResolver (org.neo4j.common.DependencyResolver)1 TokenNameLookup (org.neo4j.common.TokenNameLookup)1 Config (org.neo4j.configuration.Config)1 DefaultCacheAccess (org.neo4j.consistency.checking.cache.DefaultCacheAccess)1 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Node (org.neo4j.graphdb.Node)1 PopulationProgress (org.neo4j.internal.kernel.api.PopulationProgress)1