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);
}
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();
}
}
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));
}
}
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();
}
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();
}
Aggregations