Skip to content

Commit

Permalink
Native indexes recovery cleanup.
Browse files Browse the repository at this point in the history
Do not try to recover native label scan store on CC.
Allow native scan store to shutdown even if init failed.
Cleanup in RecoverRequiredChecker.
  • Loading branch information
MishaDemianenko committed Feb 14, 2018
1 parent 3c0202d commit cfd8efe
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
Expand Up @@ -37,7 +37,6 @@
import org.neo4j.function.Suppliers;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.progress.ProgressMonitorFactory;
import org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector;
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
Expand Down Expand Up @@ -244,7 +243,7 @@ fileSystem, config, new SimpleLogService( logProvider, logProvider ), pageCache,

LabelScanStore labelScanStore =
new NativeLabelScanStore( pageCache, storeDir, FullStoreChangeStream.EMPTY, true, monitors,
RecoveryCleanupWorkCollector.IMMEDIATE );
RECOVERY_PREVENTING_COLLECTOR );
life.add( labelScanStore );

int numberOfThreads = defaultConsistencyCheckThreadsNumber();
Expand Down
Expand Up @@ -467,7 +467,10 @@ public void stop() throws IOException
@Override
public void shutdown() throws IOException
{
index.close();
if ( index != null )
{
index.close();
}
}

@Override
Expand Down
Expand Up @@ -24,7 +24,6 @@

import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.impl.store.MetaDataStore;
import org.neo4j.kernel.impl.store.NeoStores;
import org.neo4j.kernel.impl.transaction.log.LogPosition;
import org.neo4j.kernel.impl.transaction.log.LogTailScanner;
Expand Down Expand Up @@ -52,13 +51,9 @@ public RecoveryRequiredChecker( FileSystemAbstraction fs, PageCache pageCache )

public boolean isRecoveryRequiredAt( File dataDir ) throws IOException
{
File neoStore = new File( dataDir, MetaDataStore.DEFAULT_NAME );
boolean noStoreFound = !NeoStores.isStorePresent( pageCache, dataDir );

// We need config to determine where the logical log files are
if ( noStoreFound )
{
// No database in the specified directory.
return false;
}

Expand Down
Expand Up @@ -37,7 +37,13 @@
import org.neo4j.kernel.monitoring.Monitors;
import org.neo4j.test.rule.PageCacheRule;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.neo4j.kernel.impl.api.scan.FullStoreChangeStream.EMPTY;

public class NativeLabelScanStoreTest extends LabelScanStoreTest
Expand All @@ -52,6 +58,12 @@ protected LabelScanStore createLabelScanStore( FileSystemAbstraction fileSystemA
{
Monitors monitors = new Monitors();
monitors.addMonitorListener( monitor );
return getLabelScanStore( fileSystemAbstraction, rootFolder, fullStoreChangeStream, readOnly, monitors );
}

private LabelScanStore getLabelScanStore( FileSystemAbstraction fileSystemAbstraction, File rootFolder,
FullStoreChangeStream fullStoreChangeStream, boolean readOnly, Monitors monitors )
{
PageCache pageCache = pageCacheRule.getPageCache( fileSystemAbstraction );
return new NativeLabelScanStore( pageCache, rootFolder,
fullStoreChangeStream, readOnly, monitors, RecoveryCleanupWorkCollector.IMMEDIATE );
Expand All @@ -70,6 +82,28 @@ protected void corruptIndex( FileSystemAbstraction fileSystem, File rootFolder )
scrambleFile( lssFile );
}

@Test
public void shutdownNonInitialisedNativeScanStoreWithoutException() throws IOException
{
String expectedMessage = "Expected exception message";
Monitors monitors = mock( Monitors.class );
when( monitors.newMonitor( LabelScanStore.Monitor.class ) ).thenReturn( LabelScanStore.Monitor.EMPTY );
doThrow( new RuntimeException( expectedMessage ) ).when( monitors ).addMonitorListener( any() );

LabelScanStore scanStore = getLabelScanStore( fileSystemRule.get(), dir, EMPTY, true, monitors );
try
{
scanStore.init();
fail( "Initialisation of store should fail." );
}
catch ( RuntimeException e )
{
assertEquals( expectedMessage, e.getMessage() );
}

scanStore.shutdown();
}

@Test
public void shouldStartPopulationAgainIfNotCompletedFirstTime() throws Exception
{
Expand Down

0 comments on commit cfd8efe

Please sign in to comment.