Skip to content

Commit

Permalink
Add error message to debug log when core bootstrap fail recovery check
Browse files Browse the repository at this point in the history
  • Loading branch information
RagnarW committed Sep 26, 2018
1 parent 510a68c commit a888414
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Expand Up @@ -58,6 +58,7 @@
import org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter;
import org.neo4j.kernel.lifecycle.Lifespan;
import org.neo4j.kernel.monitoring.Monitors;
import org.neo4j.logging.Log;
import org.neo4j.logging.LogProvider;

import static org.neo4j.kernel.impl.store.MetaDataStore.Position.LAST_TRANSACTION_ID;
Expand Down Expand Up @@ -102,6 +103,7 @@ public class CoreBootstrapper
private final Config config;
private final LogProvider logProvider;
private final RecoveryRequiredChecker recoveryRequiredChecker;
private final Log log;

CoreBootstrapper( File storeDir, PageCache pageCache, FileSystemAbstraction fs, Config config, LogProvider logProvider )
{
Expand All @@ -110,15 +112,18 @@ public class CoreBootstrapper
this.fs = fs;
this.config = config;
this.logProvider = logProvider;
this.log = logProvider.getLog( getClass() );
this.recoveryRequiredChecker = new RecoveryRequiredChecker( fs, pageCache );
}

public CoreSnapshot bootstrap( Set<MemberId> members ) throws IOException
{
if ( recoveryRequiredChecker.isRecoveryRequiredAt( storeDir ) )
{
throw new IllegalStateException( "Cannot bootstrap. Recovery is required. Please ensure that the store being seeded comes from a cleanly shutdown " +
"instance of Neo4j or a Neo4j backup" );
String message = "Cannot bootstrap. Recovery is required. Please ensure that the store being seeded comes from a cleanly shutdown " +
"instance of Neo4j or a Neo4j backup";
log.error( message );
throw new IllegalStateException( message );
}
StoreFactory factory = new StoreFactory( storeDir, config,
new DefaultIdGeneratorFactory( fs ), pageCache, fs, logProvider, EmptyVersionContextSupplier.INSTANCE );
Expand Down
Expand Up @@ -46,6 +46,7 @@
import org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionIdStore;
import org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionStore;
import org.neo4j.kernel.monitoring.Monitors;
import org.neo4j.logging.AssertableLogProvider;
import org.neo4j.logging.NullLogProvider;
import org.neo4j.test.rule.PageCacheRule;
import org.neo4j.test.rule.TestDirectory;
Expand Down Expand Up @@ -113,10 +114,11 @@ public void shouldFailToBootstrapIfClusterIsInNeedOfRecovery() throws IOExceptio
int nodeCount = 100;
FileSystemAbstraction fileSystem = fileSystemRule.get();
File storeInNeedOfRecovery = ClassicNeo4jStore.builder( testDirectory.directory(), fileSystem ).amountOfNodes( nodeCount ).needToRecover().build().getStoreDir();
AssertableLogProvider assertableLogProvider = new AssertableLogProvider();

PageCache pageCache = pageCacheRule.getPageCache( fileSystem );
CoreBootstrapper bootstrapper = new CoreBootstrapper( storeInNeedOfRecovery, pageCache, fileSystem,
Config.defaults(), NullLogProvider.getInstance() );
Config.defaults(), assertableLogProvider );

// when
Set<MemberId> membership = asSet( randomMember(), randomMember(), randomMember() );
Expand All @@ -127,8 +129,10 @@ public void shouldFailToBootstrapIfClusterIsInNeedOfRecovery() throws IOExceptio
}
catch ( IllegalStateException e )
{
assertEquals( e.getMessage(), "Cannot bootstrap. Recovery is required. Please ensure that the store being seeded comes from a cleanly shutdown " +
"instance of Neo4j or a Neo4j backup" );
String errorMessage = "Cannot bootstrap. Recovery is required. Please ensure that the store being seeded comes from a cleanly shutdown " +
"instance of Neo4j or a Neo4j backup";
assertEquals( e.getMessage(), errorMessage );
assertableLogProvider.assertExactly( AssertableLogProvider.inLog( CoreBootstrapper.class ).error( errorMessage ) );
}
}

Expand Down

0 comments on commit a888414

Please sign in to comment.