use of org.neo4j.kernel.impl.logging.LogService in project neo4j by neo4j.
the class GraphDatabaseInternalLogIT method shouldWriteDebugToInternalDiagnosticsLogForEnabledContexts.
@Test
public void shouldWriteDebugToInternalDiagnosticsLogForEnabledContexts() throws Exception {
// Given
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(testDir.graphDbDir()).setConfig(GraphDatabaseSettings.store_internal_debug_contexts, getClass().getName() + ",java.io").setConfig(GraphDatabaseSettings.logs_directory, testDir.directory("logs").getAbsolutePath()).newGraphDatabase();
// When
LogService logService = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(LogService.class);
logService.getInternalLog(getClass()).debug("A debug entry");
logService.getInternalLog(GraphDatabaseService.class).debug("A GDS debug entry");
logService.getInternalLog(StringWriter.class).debug("A SW debug entry");
db.shutdown();
File internalLog = new File(testDir.directory("logs"), StoreLogService.INTERNAL_LOG_NAME);
// Then
assertThat(internalLog.isFile(), is(true));
assertThat(internalLog.length(), greaterThan(0L));
assertEquals(1, countOccurrences(internalLog, "A debug entry"));
assertEquals(0, countOccurrences(internalLog, "A GDS debug entry"));
assertEquals(1, countOccurrences(internalLog, "A SW debug entry"));
}
use of org.neo4j.kernel.impl.logging.LogService in project neo4j by neo4j.
the class SwitchToSlaveCopyThenBranch method stopServicesAndHandleBranchedStore.
void stopServicesAndHandleBranchedStore(BranchedDataPolicy branchPolicy, URI masterUri, URI me, CancellationRequest cancellationRequest) throws Throwable {
MoveAfterCopy moveWithCopyThenBranch = (moves, fromDirectory, toDirectory) -> {
stopServices();
msgLog.debug("Branching store: " + storeDir);
branchPolicy.handle(storeDir, pageCache, logService);
msgLog.debug("Moving downloaded store from " + fromDirectory + " to " + toDirectory);
MoveAfterCopy.moveReplaceExisting().move(moves, fromDirectory, toDirectory);
msgLog.debug("Moved downloaded store from " + fromDirectory + " to " + toDirectory);
};
copyStore(masterUri, me, cancellationRequest, moveWithCopyThenBranch);
}
use of org.neo4j.kernel.impl.logging.LogService in project neo4j by neo4j.
the class StoreMigrator method migrateWithBatchImporter.
private void migrateWithBatchImporter(File storeDir, File migrationDir, long lastTxId, long lastTxChecksum, long lastTxLogVersion, long lastTxLogByteOffset, MigrationProgressMonitor.Section progressMonitor, RecordFormats oldFormat, RecordFormats newFormat) throws IOException {
prepareBatchImportMigration(storeDir, migrationDir, oldFormat, newFormat);
boolean requiresDynamicStoreMigration = !newFormat.dynamic().equals(oldFormat.dynamic());
boolean requiresPropertyMigration = !newFormat.property().equals(oldFormat.property()) || requiresDynamicStoreMigration;
File badFile = new File(storeDir, Configuration.BAD_FILE_NAME);
try (NeoStores legacyStore = instantiateLegacyStore(oldFormat, storeDir);
RecordCursors nodeInputCursors = new RecordCursors(legacyStore);
RecordCursors relationshipInputCursors = new RecordCursors(legacyStore);
OutputStream badOutput = new BufferedOutputStream(new FileOutputStream(badFile, false))) {
Configuration importConfig = new Configuration.Overridden(config);
AdditionalInitialIds additionalInitialIds = readAdditionalIds(lastTxId, lastTxChecksum, lastTxLogVersion, lastTxLogByteOffset);
// We have to make sure to keep the token ids if we're migrating properties/labels
BatchImporter importer = new ParallelBatchImporter(migrationDir.getAbsoluteFile(), fileSystem, pageCache, importConfig, logService, withDynamicProcessorAssignment(migrationBatchImporterMonitor(legacyStore, progressMonitor, importConfig), importConfig), additionalInitialIds, config, newFormat);
InputIterable<InputNode> nodes = legacyNodesAsInput(legacyStore, requiresPropertyMigration, nodeInputCursors);
InputIterable<InputRelationship> relationships = legacyRelationshipsAsInput(legacyStore, requiresPropertyMigration, relationshipInputCursors);
importer.doImport(Inputs.input(nodes, relationships, IdMappers.actual(), IdGenerators.fromInput(), Collectors.badCollector(badOutput, 0)));
// During migration the batch importer doesn't necessarily writes all entities, depending on
// which stores needs migration. Node, relationship, relationship group stores are always written
// anyways and cannot be avoided with the importer, but delete the store files that weren't written
// (left empty) so that we don't overwrite those in the real store directory later.
Collection<StoreFile> storesToDeleteFromMigratedDirectory = new ArrayList<>();
storesToDeleteFromMigratedDirectory.add(StoreFile.NEO_STORE);
if (!requiresPropertyMigration) {
// We didn't migrate properties, so the property stores in the migrated store are just empty/bogus
storesToDeleteFromMigratedDirectory.addAll(asList(StoreFile.PROPERTY_STORE, StoreFile.PROPERTY_STRING_STORE, StoreFile.PROPERTY_ARRAY_STORE));
}
if (!requiresDynamicStoreMigration) {
// We didn't migrate labels (dynamic node labels) or any other dynamic store
storesToDeleteFromMigratedDirectory.addAll(asList(StoreFile.NODE_LABEL_STORE, StoreFile.LABEL_TOKEN_STORE, StoreFile.LABEL_TOKEN_NAMES_STORE, StoreFile.RELATIONSHIP_TYPE_TOKEN_STORE, StoreFile.RELATIONSHIP_TYPE_TOKEN_NAMES_STORE, StoreFile.PROPERTY_KEY_TOKEN_STORE, StoreFile.PROPERTY_KEY_TOKEN_NAMES_STORE, StoreFile.SCHEMA_STORE));
}
StoreFile.fileOperation(DELETE, fileSystem, migrationDir, null, storesToDeleteFromMigratedDirectory, true, null, StoreFileType.values());
// When migrating on a block device there might be some files only accessible via the page cache.
try {
Predicate<FileHandle> fileHandlePredicate = fileHandle -> storesToDeleteFromMigratedDirectory.stream().anyMatch(storeFile -> storeFile.fileName(StoreFileType.STORE).equals(fileHandle.getFile().getName()));
pageCache.streamFilesRecursive(migrationDir).filter(fileHandlePredicate).forEach(FileHandle.HANDLE_DELETE);
} catch (NoSuchFileException e) {
// This means that we had no files only present in the page cache, this is fine.
}
}
}
use of org.neo4j.kernel.impl.logging.LogService in project neo4j by neo4j.
the class RunnableBoltWorkerTest method setup.
@Before
public void setup() {
internalLog = new AssertableLogProvider();
userLog = new AssertableLogProvider();
logService = mock(LogService.class);
when(logService.getUserLogProvider()).thenReturn(userLog);
when(logService.getUserLog(RunnableBoltWorker.class)).thenReturn(userLog.getLog(RunnableBoltWorker.class));
when(logService.getInternalLogProvider()).thenReturn(internalLog);
when(logService.getInternalLog(RunnableBoltWorker.class)).thenReturn(internalLog.getLog(RunnableBoltWorker.class));
machine = mock(BoltStateMachine.class);
when(machine.key()).thenReturn("test-session");
}
use of org.neo4j.kernel.impl.logging.LogService in project neo4j by neo4j.
the class ImportTool method doImport.
public static void doImport(PrintStream out, PrintStream err, File storeDir, File logsDir, File badFile, FileSystemAbstraction fs, Collection<Option<File[]>> nodesFiles, Collection<Option<File[]>> relationshipsFiles, boolean enableStacktrace, Input input, Config dbConfig, OutputStream badOutput, org.neo4j.unsafe.impl.batchimport.Configuration configuration) throws IOException {
boolean success;
LifeSupport life = new LifeSupport();
LogService logService = life.add(StoreLogService.inLogsDirectory(fs, logsDir));
life.start();
//TODO: add file watcher here?
BatchImporter importer = new ParallelBatchImporter(storeDir, fs, configuration, logService, ExecutionMonitors.defaultVisible(), dbConfig);
printOverview(storeDir, nodesFiles, relationshipsFiles, configuration, out);
success = false;
try {
importer.doImport(input);
success = true;
} catch (Exception e) {
throw andPrintError("Import error", e, enableStacktrace, err);
} finally {
Collector collector = input.badCollector();
int numberOfBadEntries = collector.badEntries();
collector.close();
badOutput.close();
if (numberOfBadEntries > 0) {
out.println("There were bad entries which were skipped and logged into " + badFile.getAbsolutePath());
}
life.shutdown();
if (!success) {
try {
StoreFile.fileOperation(FileOperation.DELETE, fs, storeDir, null, Iterables.<StoreFile, StoreFile>iterable(StoreFile.values()), false, ExistingTargetStrategy.FAIL, StoreFileType.values());
} catch (IOException e) {
err.println("Unable to delete store files after an aborted import " + e);
if (enableStacktrace) {
e.printStackTrace();
}
}
}
}
}
Aggregations