Skip to content

Commit

Permalink
Add config setting for debug log path
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed May 29, 2017
1 parent 6d75f74 commit f246708
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 41 deletions.
Expand Up @@ -75,6 +75,7 @@
import org.neo4j.unsafe.impl.batchimport.staging.ExecutionMonitors;

import static java.nio.charset.Charset.defaultCharset;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.store_internal_log_path;
import static org.neo4j.helpers.Exceptions.launderedException;
import static org.neo4j.helpers.Format.bytes;
import static org.neo4j.helpers.Strings.TAB;
Expand Down Expand Up @@ -501,7 +502,8 @@ public static void doImport( PrintStream out, PrintStream err, File storeDir, Fi
boolean success;
LifeSupport life = new LifeSupport();

LogService logService = life.add( StoreLogService.inLogsDirectory( fs, logsDir ) );
File internalLogFile = dbConfig.get( store_internal_log_path );
LogService logService = life.add( StoreLogService.withInternalLog( internalLogFile ).build( fs ) );

life.start();
//TODO: add file watcher here?
Expand Down
Expand Up @@ -502,6 +502,12 @@ public class GraphDatabaseSettings implements LoadableConfig
( logs ) -> new File( logs, "query.log" ),
PATH );

@Description( "Path to the debug log file." )
public static final Setting<File> store_internal_log_path = derivedSetting( "dbms.logs.debug.path",
logs_directory,
( logs ) -> new File( logs, "debug.log" ),
PATH );

@Description( "Log parameters for the executed queries being logged." )
public static final Setting<Boolean> log_queries_parameter_logging_enabled =
setting( "dbms.logs.query.parameter_logging_enabled", BOOLEAN, TRUE );
Expand Down
Expand Up @@ -66,6 +66,7 @@
import org.neo4j.udc.UsageData;
import org.neo4j.udc.UsageDataKeys;

import static org.neo4j.graphdb.factory.GraphDatabaseSettings.store_internal_log_path;
import static org.neo4j.helpers.collection.MapUtil.stringMap;

/**
Expand Down Expand Up @@ -273,11 +274,15 @@ protected LogService createLogService( LogProvider userLogProvider )
}
builder.withDefaultLevel( config.get( GraphDatabaseSettings.store_internal_log_level ) );

File logsDir = config.get( GraphDatabaseSettings.logs_directory );
File logFile = config.get( store_internal_log_path );
if ( !logFile.getParentFile().exists() )
{
logFile.getParentFile().mkdirs();
}
StoreLogService logService;
try
{
logService = builder.inLogsDirectory( fileSystem, logsDir );
logService = builder.withInternalLog( logFile ).build( fileSystem );
}
catch ( IOException ex )
{
Expand Down
Expand Up @@ -41,7 +41,7 @@

public class StoreLogService extends AbstractLogService implements Lifecycle
{
public static final String INTERNAL_LOG_NAME = "debug.log";
//public static final String INTERNAL_LOG_NAME = "debug.log";

public static class Builder
{
Expand All @@ -55,6 +55,7 @@ public static class Builder
};
private Map<String, Level> logLevels = new HashMap<>();
private Level defaultLevel = Level.INFO;
private File debugLog;

private Builder()
{
Expand Down Expand Up @@ -101,12 +102,21 @@ public Builder withDefaultLevel( Level defaultLevel )
return this;
}

public StoreLogService inLogsDirectory( FileSystemAbstraction fileSystem, File logsDir ) throws IOException
public Builder withInternalLog( File logFile ) throws IOException
{
return new StoreLogService(
userLogProvider,
fileSystem, new File( logsDir, INTERNAL_LOG_NAME ), logLevels, defaultLevel,
internalLogRotationThreshold, internalLogRotationDelay, maxInternalLogArchives, rotationExecutor, rotationListener );
this.debugLog = logFile;
return this;
}

public StoreLogService build( FileSystemAbstraction fileSystem ) throws IOException
{
if ( debugLog == null )
{
throw new IllegalArgumentException( "Debug log can't be null; set its value using `withInternalLog`" );
}
return new StoreLogService( userLogProvider, fileSystem, debugLog, logLevels, defaultLevel,
internalLogRotationThreshold, internalLogRotationDelay, maxInternalLogArchives, rotationExecutor,
rotationListener );
}
}

Expand All @@ -122,9 +132,9 @@ public static Builder withRotation( long internalLogRotationThreshold, long inte
jobScheduler );
}

public static StoreLogService inLogsDirectory( FileSystemAbstraction fileSystem, File storeDir ) throws IOException
public static Builder withInternalLog( File logFile ) throws IOException
{
return new Builder().inLogsDirectory( fileSystem, storeDir );
return new Builder().withInternalLog( logFile );
}

private final Closeable closeable;
Expand Down
Expand Up @@ -168,6 +168,7 @@
import static java.util.Collections.emptyIterator;
import static org.neo4j.collection.primitive.PrimitiveLongCollections.map;
import static org.neo4j.graphdb.Label.label;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.store_internal_log_path;
import static org.neo4j.kernel.impl.store.NodeLabelsField.parseLabelsField;
import static org.neo4j.kernel.impl.store.PropertyStore.encodeString;
import static org.neo4j.kernel.impl.util.IoPrimitiveUtils.safeCastLongToInt;
Expand Down Expand Up @@ -238,7 +239,8 @@ public BatchInserterImpl( final File storeDir, final FileSystemAbstraction fileS
PageCache pageCache = pageCacheFactory.getOrCreatePageCache();
life.add( new PageCacheLifecycle( pageCache ) );

StoreLogService logService = life.add( StoreLogService.inLogsDirectory( fileSystem, this.storeDir ) );
File internalLog = config.get( store_internal_log_path );
StoreLogService logService = life.add( StoreLogService.withInternalLog( internalLog).build( fileSystem ) );
msgLog = logService.getInternalLog( getClass() );
storeLocker = tryLockStore( fileSystem );

Expand Down
Expand Up @@ -30,7 +30,6 @@

import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.logging.StoreLogService;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.TestDirectory;
Expand All @@ -42,6 +41,7 @@

public class GraphDatabaseInternalLogIT
{
public static final String INTERNAL_LOG_FILE = "debug.log";
@Rule
public TestDirectory testDir = TestDirectory.testDirectory();

Expand All @@ -52,7 +52,7 @@ public void shouldWriteToInternalDiagnosticsLog() throws Exception
new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( testDir.graphDbDir() )
.setConfig( GraphDatabaseSettings.logs_directory, testDir.directory("logs").getAbsolutePath() )
.newGraphDatabase().shutdown();
File internalLog = new File( testDir.directory( "logs" ), StoreLogService.INTERNAL_LOG_NAME );
File internalLog = new File( testDir.directory( "logs" ), INTERNAL_LOG_FILE );

// Then
assertThat( internalLog.isFile(), is( true ) );
Expand All @@ -75,7 +75,7 @@ public void shouldNotWriteDebugToInternalDiagnosticsLogByDefault() throws Except
logService.getInternalLog( getClass() ).debug( "A debug entry" );

db.shutdown();
File internalLog = new File( testDir.directory( "logs" ), StoreLogService.INTERNAL_LOG_NAME );
File internalLog = new File( testDir.directory( "logs" ), INTERNAL_LOG_FILE );

// Then
assertThat( internalLog.isFile(), is( true ) );
Expand All @@ -100,7 +100,7 @@ public void shouldWriteDebugToInternalDiagnosticsLogForEnabledContexts() throws
logService.getInternalLog( StringWriter.class ).debug( "A SW debug entry" );

db.shutdown();
File internalLog = new File( testDir.directory( "logs" ), StoreLogService.INTERNAL_LOG_NAME );
File internalLog = new File( testDir.directory( "logs" ), INTERNAL_LOG_FILE );

// Then
assertThat( internalLog.isFile(), is( true ) );
Expand Down
Expand Up @@ -76,7 +76,6 @@
import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig;
import org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider;
import org.neo4j.kernel.impl.api.scan.NativeLabelScanStoreExtension;
import org.neo4j.kernel.impl.logging.StoreLogService;
import org.neo4j.kernel.impl.spi.KernelContext;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine;
import org.neo4j.kernel.impl.store.NeoStores;
Expand Down Expand Up @@ -639,7 +638,7 @@ public void messagesLogGetsClosed() throws Exception
File storeDir = this.storeDir.graphDbDir();
BatchInserter inserter = BatchInserters.inserter( storeDir, fileSystemRule.get(), stringMap() );
inserter.shutdown();
assertTrue( new File( storeDir, StoreLogService.INTERNAL_LOG_NAME ).delete() );
assertTrue( new File( storeDir, "debug.log" ).delete() );
}

@Test
Expand Down
8 changes: 4 additions & 4 deletions community/neo4j/src/test/java/upgrade/StoreUpgraderTest.java
Expand Up @@ -45,7 +45,6 @@
import org.neo4j.kernel.impl.api.index.inmemory.InMemoryIndexProvider;
import org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider;
import org.neo4j.kernel.impl.logging.NullLogService;
import org.neo4j.kernel.impl.logging.StoreLogService;
import org.neo4j.kernel.impl.store.MetaDataStore;
import org.neo4j.kernel.impl.store.NeoStores;
import org.neo4j.kernel.impl.store.StoreFactory;
Expand Down Expand Up @@ -89,6 +88,7 @@
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.neo4j.graphdb.GraphDatabaseInternalLogIT.INTERNAL_LOG_FILE;
import static org.neo4j.kernel.impl.storemigration.MigrationTestUtils.prepareSampleLegacyDatabase;
import static org.neo4j.kernel.impl.storemigration.MigrationTestUtils.removeCheckPointFromTxLog;
import static org.neo4j.kernel.impl.storemigration.MigrationTestUtils.verifyFilesHaveSameContent;
Expand Down Expand Up @@ -318,7 +318,7 @@ public void shouldContinueMovingFilesIfUpgradeCancelledWhileMoving() throws Exce
public void upgradedNeoStoreShouldHaveNewUpgradeTimeAndUpgradeId() throws Exception
{
// Given
fileSystem.deleteFile( new File( dbDirectory, StoreLogService.INTERNAL_LOG_NAME ) );
fileSystem.deleteFile( new File( dbDirectory, INTERNAL_LOG_FILE ) );
PageCache pageCache = pageCacheRule.getPageCache( fileSystem );
UpgradableDatabase upgradableDatabase = new UpgradableDatabase( fileSystem,
new StoreVersionCheck( pageCache ),
Expand All @@ -345,7 +345,7 @@ public void upgradedNeoStoreShouldHaveNewUpgradeTimeAndUpgradeId() throws Except
public void upgradeShouldNotLeaveLeftoverAndMigrationDirs() throws Exception
{
// Given
fileSystem.deleteFile( new File( dbDirectory, StoreLogService.INTERNAL_LOG_NAME ) );
fileSystem.deleteFile( new File( dbDirectory, INTERNAL_LOG_FILE ) );
PageCache pageCache = pageCacheRule.getPageCache( fileSystem );
UpgradableDatabase upgradableDatabase = new UpgradableDatabase( fileSystem,
new StoreVersionCheck( pageCache ),
Expand All @@ -362,7 +362,7 @@ public void upgradeShouldNotLeaveLeftoverAndMigrationDirs() throws Exception
public void upgraderShouldCleanupLegacyLeftoverAndMigrationDirs() throws Exception
{
// Given
fileSystem.deleteFile( new File( dbDirectory, StoreLogService.INTERNAL_LOG_NAME ) );
fileSystem.deleteFile( new File( dbDirectory, INTERNAL_LOG_FILE ) );
fileSystem.mkdir( new File( dbDirectory, StoreUpgrader.MIGRATION_DIRECTORY ) );
fileSystem.mkdir( new File( dbDirectory, StoreUpgrader.MIGRATION_LEFT_OVERS_DIRECTORY ) );
fileSystem.mkdir( new File( dbDirectory, StoreUpgrader.MIGRATION_LEFT_OVERS_DIRECTORY + "_1" ) );
Expand Down
Expand Up @@ -57,7 +57,6 @@
import org.neo4j.kernel.configuration.Settings;
import org.neo4j.kernel.extension.KernelExtensionFactory;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.logging.StoreLogService;
import org.neo4j.kernel.impl.store.MetaDataStore;
import org.neo4j.kernel.impl.store.MismatchingStoreIdException;
import org.neo4j.kernel.impl.store.StoreId;
Expand All @@ -78,6 +77,7 @@

import static org.neo4j.com.RequestContext.anonymous;
import static org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.DEFAULT_BATCH_SIZE;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.store_internal_log_path;
import static org.neo4j.helpers.Exceptions.rootCause;
import static org.neo4j.kernel.impl.pagecache.ConfigurableStandalonePageCacheFactory.createPageCache;

Expand Down Expand Up @@ -177,7 +177,8 @@ private BackupOutcome fullBackup( FileSystemAbstraction fileSystem, String sourc
CancellationRequest.NEVER_CANCELLED,
MoveAfterCopy.moveReplaceExisting() );

bumpDebugDotLogFileVersion( targetDirectory, timestamp );
File debugLogFile = tuningConfiguration.get( store_internal_log_path );
bumpDebugDotLogFileVersion( debugLogFile, timestamp );
boolean consistent = checkDbConsistency( fileSystem, targetDirectory, consistencyCheck, tuningConfiguration, pageCache );
clearIdFiles( fileSystem, targetDirectory );
return new BackupOutcome( lastCommittedTx, consistent );
Expand Down Expand Up @@ -234,7 +235,8 @@ private BackupOutcome incrementalBackup( FileSystemAbstraction fileSystem, Strin
{
targetDb.shutdown();
}
bumpDebugDotLogFileVersion( targetDirectory, backupStartTime );
File debugLogFile = config.get( store_internal_log_path );
bumpDebugDotLogFileVersion( debugLogFile, backupStartTime );
boolean consistent = checkDbConsistency( fileSystem, targetDirectory, consistencyCheck, config, pageCache );
clearIdFiles( fileSystem, targetDirectory );
return new BackupOutcome( lastCommittedTx, consistent );
Expand Down Expand Up @@ -410,18 +412,15 @@ private long incrementalWithContext( String sourceHostNameOrIp, int sourcePort,
return handler.getLastSeenTransactionId();
}

private static boolean bumpDebugDotLogFileVersion( File dbDirectory, long toTimestamp )
private static boolean bumpDebugDotLogFileVersion( final File debugLogFile, final long toTimestamp )
{
File[] candidates = dbDirectory.listFiles( ( dir, name ) -> name.equals( StoreLogService.INTERNAL_LOG_NAME ) );
if ( candidates == null || candidates.length != 1 )
if ( !debugLogFile.exists() )
{
return false;
}
// candidates has a unique member, the right one
File previous = candidates[0];
// Build to, from existing parent + new filename
File to = new File( previous.getParentFile(), StoreLogService.INTERNAL_LOG_NAME + "." + toTimestamp );
return previous.renameTo( to );
File to = new File( debugLogFile.getParentFile(), debugLogFile.getName() + "." + toTimestamp );
return debugLogFile.renameTo( to );
}

private List<KernelExtensionFactory<?>> loadKernelExtensions()
Expand Down
Expand Up @@ -55,7 +55,6 @@
import org.neo4j.kernel.impl.factory.EditionModule;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory;
import org.neo4j.kernel.impl.factory.PlatformModule;
import org.neo4j.kernel.impl.logging.StoreLogService;
import org.neo4j.kernel.impl.store.MetaDataStore;
import org.neo4j.kernel.impl.store.MetaDataStore.Position;
import org.neo4j.kernel.impl.store.MismatchingStoreIdException;
Expand All @@ -81,6 +80,9 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.dense_node_threshold;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.logs_directory;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.store_internal_log_path;
import static org.neo4j.helpers.collection.MapUtil.stringMap;
import static org.neo4j.kernel.impl.MyRelTypes.TEST;

@RunWith( Parameterized.class )
Expand Down Expand Up @@ -576,7 +578,8 @@ protected void startup( File path ) throws Throwable

private static boolean checkLogFileExistence( String directory )
{
return new File( directory, StoreLogService.INTERNAL_LOG_NAME ).exists();
return Config.embeddedDefaults( stringMap( logs_directory.name(), directory ) ).get( store_internal_log_path )
.exists();
}

private long lastTxChecksumOf( File storeDir, PageCache pageCache ) throws IOException
Expand Down
Expand Up @@ -49,7 +49,6 @@
import org.neo4j.kernel.impl.ha.ClusterManager;
import org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster;
import org.neo4j.kernel.impl.ha.ClusterManager.RepairKit;
import org.neo4j.kernel.impl.logging.StoreLogService;
import org.neo4j.kernel.impl.util.Listener;
import org.neo4j.kernel.lifecycle.LifeRule;
import org.neo4j.kernel.monitoring.Monitors;
Expand Down Expand Up @@ -338,7 +337,7 @@ private long moveAwayToLookLikeOldBranchedDirectory() throws IOException
for ( File file : Objects.requireNonNull( dir.listFiles() ) )
{
String fileName = file.getName();
if ( !fileName.equals( StoreLogService.INTERNAL_LOG_NAME ) && !file.getName().startsWith( "branched-" ) )
if ( !fileName.equals( "debug.log" ) && !file.getName().startsWith( "branched-" ) )
{
FileUtils.renameFile( file, new File( branchDir, file.getName() ) );
}
Expand Down
Expand Up @@ -33,7 +33,6 @@
import org.neo4j.cluster.client.ClusterClientModule;
import org.neo4j.cluster.protocol.election.NotElectableElectionCredentialsProvider;
import org.neo4j.function.Predicates;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.helpers.collection.Pair;
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
Expand All @@ -50,6 +49,7 @@
import org.neo4j.logging.FormattedLogProvider;
import org.neo4j.server.Bootstrapper;

import static org.neo4j.graphdb.factory.GraphDatabaseSettings.store_internal_log_path;
import static org.neo4j.helpers.Exceptions.peel;

public class ArbiterBootstrapper implements Bootstrapper, AutoCloseable
Expand Down Expand Up @@ -148,11 +148,12 @@ private static void verifyConfig( Map<String, String> config )

private static LogService logService( FileSystemAbstraction fileSystem, Config config )
{
File logDir = config.get( GraphDatabaseSettings.logs_directory );
File logFile = config.get( store_internal_log_path );
try
{
return StoreLogService.withUserLogProvider( FormattedLogProvider.toOutputStream( System.out ) )
.inLogsDirectory( fileSystem, logDir );
.withInternalLog( logFile )
.build( fileSystem );
}
catch ( IOException e )
{
Expand Down
Expand Up @@ -58,6 +58,7 @@
import org.neo4j.logging.LogProvider;

import static java.lang.String.format;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.store_internal_log_path;
import static org.neo4j.kernel.extension.UnsatisfiedDependencyStrategies.ignore;
import static org.neo4j.kernel.impl.pagecache.ConfigurableStandalonePageCacheFactory.createPageCache;

Expand Down Expand Up @@ -95,8 +96,8 @@ private static Config getMigrationConfig()
public void run( final FileSystemAbstraction fs, final File storeDirectory, Config config,
LogProvider userLogProvider ) throws IOException
{
StoreLogService logService =
StoreLogService.withUserLogProvider( userLogProvider ).inLogsDirectory( fs, storeDirectory );
StoreLogService logService = StoreLogService.withUserLogProvider( userLogProvider )
.withInternalLog( config.get( store_internal_log_path ) ).build( fs );

VisibleMigrationProgressMonitor progressMonitor =
new VisibleMigrationProgressMonitor( logService.getUserLog( StoreMigration.class ) );
Expand Down

0 comments on commit f246708

Please sign in to comment.