Skip to content

Commit

Permalink
Extract NeoStoreDataSource diagnostics into separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Aug 3, 2018
1 parent dc47173 commit 1719bbd
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 73 deletions.
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel;

import java.io.IOException;

import org.neo4j.kernel.impl.transaction.log.entry.LogHeader;
import org.neo4j.kernel.impl.transaction.log.files.LogFiles;
import org.neo4j.kernel.info.DiagnosticsExtractor;
import org.neo4j.kernel.info.DiagnosticsPhase;
import org.neo4j.logging.Logger;

enum DataSourceDiagnostics implements DiagnosticsExtractor<NeoStoreDataSource>
{
TRANSACTION_RANGE( "Transaction log:" )
{
@Override
void dump( NeoStoreDataSource source, Logger log )
{
LogFiles logFiles = source.getDependencyResolver().resolveDependency( LogFiles.class );
try
{
for ( long logVersion = logFiles.getLowestLogVersion();
logFiles.versionExists( logVersion ); logVersion++ )
{
if ( logFiles.hasAnyEntries( logVersion ) )
{
LogHeader header = logFiles.extractHeader( logVersion );
long firstTransactionIdInThisLog = header.lastCommittedTxId + 1;
log.log( "Oldest transaction " + firstTransactionIdInThisLog +
" found in log with version " + logVersion );
return;
}
}
log.log( "No transactions found in any log" );
}
catch ( IOException e )
{ // It's fine, we just tried to be nice and log this. Failing is OK
log.log( "Error trying to figure out oldest transaction in log" );
}
}
};

private final String message;

DataSourceDiagnostics( String message )
{
this.message = message;
}

@Override
public void dumpDiagnostics( final NeoStoreDataSource source, DiagnosticsPhase phase, Logger logger )
{
if ( applicable( phase ) )
{
logger.log( message );
dump( source, logger );
}
}

boolean applicable( DiagnosticsPhase phase )
{
return phase.isInitialization() || phase.isExplicitlyRequested();
}

abstract void dump( NeoStoreDataSource source, Logger logger );
}
Expand Up @@ -109,7 +109,6 @@
import org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo;
import org.neo4j.kernel.impl.transaction.log.checkpoint.StoreCopyCheckPointMutex;
import org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader;
import org.neo4j.kernel.impl.transaction.log.entry.LogHeader;
import org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader;
import org.neo4j.kernel.impl.transaction.log.files.LogFileCreationMonitor;
import org.neo4j.kernel.impl.transaction.log.files.LogFiles;
Expand All @@ -129,9 +128,7 @@
import org.neo4j.kernel.impl.util.monitoring.LogProgressReporter;
import org.neo4j.kernel.impl.util.monitoring.ProgressReporter;
import org.neo4j.kernel.impl.util.watcher.FileSystemWatcherService;
import org.neo4j.kernel.info.DiagnosticsExtractor;
import org.neo4j.kernel.info.DiagnosticsManager;
import org.neo4j.kernel.info.DiagnosticsPhase;
import org.neo4j.kernel.internal.DatabaseHealth;
import org.neo4j.kernel.internal.TransactionEventHandlers;
import org.neo4j.kernel.lifecycle.LifeSupport;
Expand All @@ -150,7 +147,6 @@
import org.neo4j.kernel.recovery.RecoveryStartInformationProvider;
import org.neo4j.logging.Log;
import org.neo4j.logging.LogProvider;
import org.neo4j.logging.Logger;
import org.neo4j.resources.CpuClock;
import org.neo4j.resources.HeapAllocation;
import org.neo4j.scheduler.JobScheduler;
Expand All @@ -163,63 +159,6 @@

public class NeoStoreDataSource extends LifecycleAdapter
{

enum Diagnostics implements DiagnosticsExtractor<NeoStoreDataSource>
{
TRANSACTION_RANGE( "Transaction log:" )
{
@Override
void dump( NeoStoreDataSource source, Logger log )
{
LogFiles logFiles = source.getDependencyResolver().resolveDependency( LogFiles.class );
try
{
for ( long logVersion = logFiles.getLowestLogVersion();
logFiles.versionExists( logVersion ); logVersion++ )
{
if ( logFiles.hasAnyEntries( logVersion ) )
{
LogHeader header = logFiles.extractHeader( logVersion );
long firstTransactionIdInThisLog = header.lastCommittedTxId + 1;
log.log( "Oldest transaction " + firstTransactionIdInThisLog +
" found in log with version " + logVersion );
return;
}
}
log.log( "No transactions found in any log" );
}
catch ( IOException e )
{ // It's fine, we just tried to be nice and log this. Failing is OK
log.log( "Error trying to figure out oldest transaction in log" );
}
}
};

private final String message;

Diagnostics( String message )
{
this.message = message;
}

@Override
public void dumpDiagnostics( final NeoStoreDataSource source, DiagnosticsPhase phase, Logger logger )
{
if ( applicable( phase ) )
{
logger.log( message );
dump( source, logger );
}
}

boolean applicable( DiagnosticsPhase phase )
{
return phase.isInitialization() || phase.isExplicitlyRequested();
}

abstract void dump( NeoStoreDataSource source, Logger logger );
}

public static final String DEFAULT_DATA_SOURCE_NAME = "nioneodb";

private final Monitors monitors;
Expand Down Expand Up @@ -798,7 +737,7 @@ public NeoStoreFileListing getNeoStoreFileListing()
public void registerDiagnosticsWith( DiagnosticsManager manager )
{
storageEngine.registerDiagnostics( manager );
manager.registerAll( Diagnostics.class, this );
manager.registerAll( DataSourceDiagnostics.class, this );
}

public DependencyResolver getDependencyResolver()
Expand Down Expand Up @@ -855,13 +794,6 @@ public String getDatabaseName()
return databaseName;
}

// For test purposes only, not thread safe
@VisibleForTesting
public LifeSupport getLife()
{
return life;
}

public AutoIndexing getAutoIndexing()
{
return autoIndexing;
Expand All @@ -871,4 +803,10 @@ public TransactionEventHandlers getTransactionEventHandlers()
{
return transactionEventHandlers;
}

@VisibleForTesting
public LifeSupport getLife()
{
return life;
}
}
Expand Up @@ -29,7 +29,6 @@
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.IOLimiter;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.NeoStoreDataSource.Diagnostics;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.core.DatabasePanicEventGenerator;
import org.neo4j.kernel.impl.logging.SimpleLogService;
Expand Down Expand Up @@ -163,7 +162,7 @@ public void shouldLogCorrectTransactionLogDiagnosticsForNoTransactionLogs()
Logger logger = logProvider.getLog( getClass() ).infoLogger();

// WHEN
Diagnostics.TRANSACTION_RANGE.dump( dataSource, logger );
DataSourceDiagnostics.TRANSACTION_RANGE.dump( dataSource, logger );

// THEN
logProvider.assertContainsMessageContaining( "No transactions" );
Expand All @@ -181,7 +180,7 @@ public void shouldLogCorrectTransactionLogDiagnosticsForTransactionsInOldestLog(
Logger logger = logProvider.getLog( getClass() ).infoLogger();

// WHEN
Diagnostics.TRANSACTION_RANGE.dump( dataSource, logger );
DataSourceDiagnostics.TRANSACTION_RANGE.dump( dataSource, logger );

// THEN
logProvider.assertContainsMessageContaining( "transaction " + (prevLogLastTxId + 1) );
Expand All @@ -200,7 +199,7 @@ public void shouldLogCorrectTransactionLogDiagnosticsForTransactionsInSecondOlde
Logger logger = logProvider.getLog( getClass() ).infoLogger();

// WHEN
Diagnostics.TRANSACTION_RANGE.dump( dataSource, logger );
DataSourceDiagnostics.TRANSACTION_RANGE.dump( dataSource, logger );

// THEN
logProvider.assertContainsMessageContaining( "transaction " + (prevLogLastTxId + 1) );
Expand Down

0 comments on commit 1719bbd

Please sign in to comment.