use of org.neo4j.monitoring.DatabaseHealth in project neo4j by neo4j.
the class BatchingNeoStoresTest method someDataInTheDatabase.
private void someDataInTheDatabase(Config config) throws Exception {
NullLog nullLog = NullLog.getInstance();
try (JobScheduler scheduler = JobSchedulerFactory.createInitialisedScheduler();
PageCache pageCache = new ConfiguringPageCacheFactory(fileSystem, Config.defaults(), PageCacheTracer.NULL, nullLog, scheduler, Clocks.nanoClock(), new MemoryPools()).getOrCreatePageCache();
Lifespan life = new Lifespan()) {
// TODO this little dance with TokenHolders is really annoying and must be solved with a better abstraction
DeferredInitializedTokenCreator propertyKeyTokenCreator = new DeferredInitializedTokenCreator() {
@Override
void create(String name, boolean internal, int id) {
txState.propertyKeyDoCreateForName(name, internal, id);
}
};
DeferredInitializedTokenCreator labelTokenCreator = new DeferredInitializedTokenCreator() {
@Override
void create(String name, boolean internal, int id) {
txState.labelDoCreateForName(name, internal, id);
}
};
DeferredInitializedTokenCreator relationshipTypeTokenCreator = new DeferredInitializedTokenCreator() {
@Override
void create(String name, boolean internal, int id) {
txState.relationshipTypeDoCreateForName(name, internal, id);
}
};
TokenHolders tokenHolders = new TokenHolders(new DelegatingTokenHolder(propertyKeyTokenCreator, TokenHolder.TYPE_PROPERTY_KEY), new DelegatingTokenHolder(labelTokenCreator, TokenHolder.TYPE_LABEL), new DelegatingTokenHolder(relationshipTypeTokenCreator, TokenHolder.TYPE_RELATIONSHIP_TYPE));
IndexConfigCompleter indexConfigCompleter = index -> index;
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector = immediate();
RecordStorageEngine storageEngine = life.add(new RecordStorageEngine(databaseLayout, Config.defaults(), pageCache, fileSystem, NullLogProvider.getInstance(), tokenHolders, new DatabaseSchemaState(NullLogProvider.getInstance()), new StandardConstraintSemantics(), indexConfigCompleter, LockService.NO_LOCK_SERVICE, new DatabaseHealth(PanicEventGenerator.NO_OP, nullLog), new DefaultIdGeneratorFactory(fileSystem, immediate(), DEFAULT_DATABASE_NAME), new DefaultIdController(), recoveryCleanupWorkCollector, PageCacheTracer.NULL, true, INSTANCE, writable(), CommandLockVerification.Factory.IGNORE, LockVerificationMonitor.Factory.IGNORE));
// Create the relationship type token
TxState txState = new TxState();
NeoStores neoStores = storageEngine.testAccessNeoStores();
CommandCreationContext commandCreationContext = storageEngine.newCommandCreationContext(INSTANCE);
commandCreationContext.initialize(NULL);
propertyKeyTokenCreator.initialize(neoStores.getPropertyKeyTokenStore(), txState);
labelTokenCreator.initialize(neoStores.getLabelTokenStore(), txState);
relationshipTypeTokenCreator.initialize(neoStores.getRelationshipTypeTokenStore(), txState);
int relTypeId = tokenHolders.relationshipTypeTokens().getOrCreateId(RELTYPE.name());
apply(txState, commandCreationContext, storageEngine);
// Finally, we're initialized and ready to create two nodes and a relationship
txState = new TxState();
long node1 = commandCreationContext.reserveNode();
long node2 = commandCreationContext.reserveNode();
txState.nodeDoCreate(node1);
txState.nodeDoCreate(node2);
txState.relationshipDoCreate(commandCreationContext.reserveRelationship(), relTypeId, node1, node2);
apply(txState, commandCreationContext, storageEngine);
neoStores.flush(NULL);
}
}
use of org.neo4j.monitoring.DatabaseHealth in project neo4j by neo4j.
the class StoreUpgraderInterruptionTestIT method newUpgrader.
private StoreUpgrader newUpgrader(StoreVersionCheck versionCheck, MigrationProgressMonitor progressMonitor, StoreMigrationParticipant... participants) {
Config config = Config.defaults(allow_upgrade, true);
Dependencies dependencies = new Dependencies();
dependencies.satisfyDependencies(new Monitors());
RecordStorageEngineFactory storageEngineFactory = new RecordStorageEngineFactory();
var databaseHealth = new DatabaseHealth(PanicEventGenerator.NO_OP, NullLog.getInstance());
LogsUpgrader logsUpgrader = new LogsUpgrader(fs, storageEngineFactory, workingDatabaseLayout, pageCache, legacyTransactionLogsLocator, config, dependencies, NULL, INSTANCE, databaseHealth, false);
StoreUpgrader upgrader = new StoreUpgrader(versionCheck, progressMonitor, config, fs, NullLogProvider.getInstance(), logsUpgrader, NULL);
for (StoreMigrationParticipant participant : participants) {
upgrader.addParticipant(participant);
}
return upgrader;
}
use of org.neo4j.monitoring.DatabaseHealth in project neo4j by neo4j.
the class RecoveryCleanupIT method dirtyDatabase.
private void dirtyDatabase() throws IOException {
db = startDatabase();
Health databaseHealth = databaseHealth(db);
index(db);
someData(db);
checkpoint(db);
someData(db);
databaseHealth.panic(new Throwable("Trigger recovery on next startup"));
managementService.shutdown();
db = null;
}
use of org.neo4j.monitoring.DatabaseHealth in project neo4j by neo4j.
the class DatabaseHealthTest method shouldGenerateDatabasePanicEvents.
@Test
void shouldGenerateDatabasePanicEvents() {
// GIVEN
DatabasePanicEventGenerator generator = mock(DatabasePanicEventGenerator.class);
Health databaseHealth = new DatabaseHealth(generator, NullLogProvider.getInstance().getLog(DatabaseHealth.class));
databaseHealth.healed();
// WHEN
Exception cause = new Exception("My own fault");
databaseHealth.panic(cause);
databaseHealth.panic(cause);
// THEN
verify(generator).panic(cause);
}
use of org.neo4j.monitoring.DatabaseHealth in project neo4j by neo4j.
the class DatabaseHealthTest method databaseWithCriticalErrorsCanNotBeHealed.
@Test
void databaseWithCriticalErrorsCanNotBeHealed() {
AssertableLogProvider logProvider = new AssertableLogProvider();
Health databaseHealth = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), logProvider.getLog(DatabaseHealth.class));
assertTrue(databaseHealth.isHealthy());
IOException criticalException = new IOException("Space exception.", new OutOfMemoryError("Out of memory."));
databaseHealth.panic(criticalException);
assertFalse(databaseHealth.isHealthy());
assertFalse(databaseHealth.healed());
assertThat(logProvider).doesNotContainMessage("Database health set to OK").containsMessages("Database encountered a critical error and can't be healed. Restart required.");
}
Aggregations