Skip to content

Commit

Permalink
Simplified logging in LuceneLabelScanStore
Browse files Browse the repository at this point in the history
Currently LuceneLabelScanStore uses monitor to log messages about things like
initialization and rebuild. This logging, while being always valuable, could be
suppressed by passing in other monitor.

This commit makes log statements explicit and removes the logging monitor.
  • Loading branch information
lutovich authored and MishaDemianenko committed Jan 21, 2016
1 parent 92c740f commit b1c25dc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider.FullStoreChangeStream;
import org.neo4j.logging.LogProvider;

import static org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider.fullStoreLabelUpdateStream;

/**
* Means of obtaining a {@link LabelScanStore}, independent of the {@link org.neo4j.kernel.extension.KernelExtensions}
* mechanism, when you need to access the store without running a full database. This is used during consistency
Expand All @@ -48,7 +46,7 @@ public class LuceneLabelScanStoreBuilder
private final FileSystemAbstraction fileSystem;
private final LogProvider logProvider;

private LuceneLabelScanStore labelScanStore = null;
private LuceneLabelScanStore labelScanStore;

public LuceneLabelScanStoreBuilder( File storeDir, FullStoreChangeStream fullStoreStream,
FileSystemAbstraction fileSystem, LogProvider logProvider )
Expand All @@ -68,8 +66,8 @@ public LabelScanStore build()
LabelScanStoreProvider.getStoreDirectory( storeDir ),
LuceneLabelScanStore.INDEX_IDENTIFIER );
LuceneLabelScanIndex index = new LuceneLabelScanIndex( indexStorage );
labelScanStore = new LuceneLabelScanStore( index, fullStoreStream,
LuceneLabelScanStore.loggerMonitor( logProvider ) );
labelScanStore = new LuceneLabelScanStore( index, fullStoreStream, logProvider,
LuceneLabelScanStore.Monitor.EMPTY );

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,75 +42,65 @@ public class LuceneLabelScanStore implements LabelScanStore
private final LuceneLabelScanIndex luceneIndex;
// We get in a full store stream here in case we need to fully rebuild the store if it's missing or corrupted.
private final FullStoreChangeStream fullStoreStream;
private final Log log;
private final Monitor monitor;
private boolean needsRebuild;
private final Lock lock = new ReentrantLock( true );

public interface Monitor
{
void init();

void noIndex();

void lockedIndex( LockObtainFailedException e );

void corruptIndex( IOException e );

void rebuilding();

void rebuilt( long roughNodeCount );
}

// todo: WAT?
public static Monitor loggerMonitor( LogProvider logProvider )
{
final Log log = logProvider.getLog( LuceneLabelScanStore.class );
return new Monitor()
Monitor EMPTY = new Monitor()
{
@Override
public void init()
{ // Don't log anything here
{
}

@Override
public void noIndex()
{
log.info( "No lucene scan store index found, this might just be first use. " +
"Preparing to rebuild." );
}

@Override
public void lockedIndex( LockObtainFailedException e )
{
log.warn( "Index is locked by another process or database", e );
}

@Override
public void corruptIndex( IOException corruptionException )
public void corruptIndex( IOException e )
{
log.warn( "Lucene scan store index could not be read. Preparing to rebuild.",
corruptionException );
}

@Override
public void rebuilding()
{
log.info( "Rebuilding lucene scan store, this may take a while" );
}

@Override
public void rebuilt( long highNodeId )
public void rebuilt( long roughNodeCount )
{
log.info( "Lucene scan store rebuilt (roughly " + highNodeId + " nodes)" );
}
};

void init();

void noIndex();

void lockedIndex( LockObtainFailedException e );

void corruptIndex( IOException e );

void rebuilding();

void rebuilt( long roughNodeCount );
}

public LuceneLabelScanStore( LuceneLabelScanIndex luceneIndex, FullStoreChangeStream fullStoreStream,
Monitor monitor )
LogProvider logProvider, Monitor monitor )
{
this.luceneIndex = luceneIndex;
this.fullStoreStream = fullStoreStream;
this.log = logProvider.getLog( getClass() );
this.monitor = monitor;
}

Expand Down Expand Up @@ -147,7 +137,9 @@ public void init() throws IOException
{
if ( !luceneIndex.exists() )
{
log.info( "No lucene scan store index found, this might just be first use. Preparing to rebuild." );
monitor.noIndex();

luceneIndex.create();
needsRebuild = true;
}
Expand All @@ -158,6 +150,8 @@ else if ( !luceneIndex.isValid() )
// luceneIndex.create();
// needsRebuild = true;

log.warn( "Lucene scan store index could not be read. Preparing to rebuild." );

throw new IOException( "Label scan store could not be read, and needs to be rebuilt. " +
"To trigger a rebuild, ensure the database is stopped, delete the files in '" +
luceneIndex + "', and then start the database again." );
Expand All @@ -169,6 +163,7 @@ else if ( !luceneIndex.isValid() )
catch ( LockObtainFailedException e )
{
luceneIndex.close();
log.error( "Index is locked by another process or database", e );
monitor.lockedIndex( e );
throw e;
}
Expand All @@ -181,8 +176,10 @@ public void start() throws IOException
{ // we saw in init() that we need to rebuild the index, so do it here after the
// neostore has been properly started.
monitor.rebuilding();
log.info( "Rebuilding lucene scan store, this may take a while" );
long numberOfNodes = rebuild();
monitor.rebuilt( numberOfNodes );
log.info( "Lucene scan store rebuilt (roughly " + numberOfNodes + " nodes)" );
needsRebuild = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.neo4j.kernel.lifecycle.Lifecycle;

import static org.neo4j.kernel.api.impl.index.LuceneKernelExtensions.directoryFactory;
import static org.neo4j.kernel.api.impl.index.LuceneLabelScanStore.loggerMonitor;
import static org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider.fullStoreLabelUpdateStream;

@Service.Implementation(KernelExtensionFactory.class)
Expand Down Expand Up @@ -69,7 +68,7 @@ public LuceneLabelScanStoreExtension()
{
super( "lucene-scan-store");
this.priority = priority;
this.monitor = monitor;
this.monitor = (monitor == null) ? Monitor.EMPTY : monitor;
}

@Override
Expand All @@ -80,7 +79,9 @@ public LabelScanStoreProvider newInstance( KernelContext context, Dependencies d

LuceneLabelScanIndex index = getLuceneIndex( context, directoryFactory );
LuceneLabelScanStore scanStore = new LuceneLabelScanStore( index,
fullStoreLabelUpdateStream( dependencies.indexStoreView() ), getMonitor( dependencies ) );
fullStoreLabelUpdateStream( dependencies.indexStoreView() ),
dependencies.getLogService().getInternalLogProvider(), monitor );


return new LabelScanStoreProvider( scanStore, priority );
}
Expand All @@ -93,8 +94,4 @@ private LuceneLabelScanIndex getLuceneIndex( KernelContext context, DirectoryFac
return new LuceneLabelScanIndex( indexStorage );
}

private Monitor getMonitor( Dependencies dependencies )
{
return monitor != null ? monitor : loggerMonitor( dependencies.getLogService().getInternalLogProvider() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider.FullStoreChangeStream;
import org.neo4j.kernel.lifecycle.LifeSupport;
import org.neo4j.kernel.lifecycle.LifecycleException;
import org.neo4j.logging.NullLogProvider;
import org.neo4j.storageengine.api.schema.BoundedIterable;
import org.neo4j.storageengine.api.schema.LabelScanReader;
import org.neo4j.storageengine.api.schema.NodeLabelRange;
Expand Down Expand Up @@ -459,7 +460,8 @@ private void start( List<NodeLabelUpdate> existingData )
LuceneLabelScanStore.INDEX_IDENTIFIER );

LuceneLabelScanIndex index = new LuceneLabelScanIndex( documentFormat, indexStorage );
store = life.add( new LuceneLabelScanStore( index, asStream( existingData ), monitor ) );
store = new LuceneLabelScanStore( index, asStream( existingData ), NullLogProvider.getInstance(), monitor );
life.add( store );

life.start();
assertTrue( monitor.initCalled );
Expand Down

0 comments on commit b1c25dc

Please sign in to comment.