Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.4' into 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
RagnarW committed Sep 24, 2018
2 parents 628d48c + b0bb221 commit 9cfcccf
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public ClusteringModule( DiscoveryServiceFactory discoveryServiceFactory, Member
dependencies.satisfyDependency( topologyService ); // for tests

CoreBootstrapper coreBootstrapper =
new CoreBootstrapper( databaseLayout, platformModule.pageCache, fileSystem, config, logProvider );
new CoreBootstrapper( databaseLayout, platformModule.pageCache, fileSystem, config, logProvider, platformModule.monitors );

SimpleStorage<ClusterId> clusterIdStorage =
new SimpleFileStorage<>( fileSystem, clusterStateDirectory, CLUSTER_ID_NAME, new ClusterId.Marshal(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.io.pagecache.tracing.cursor.context.EmptyVersionContextSupplier;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.recovery.RecoveryRequiredChecker;
import org.neo4j.kernel.impl.store.MetaDataStore;
import org.neo4j.kernel.impl.store.NeoStores;
import org.neo4j.kernel.impl.store.StoreFactory;
Expand All @@ -55,6 +56,7 @@
import org.neo4j.kernel.impl.transaction.log.files.LogFiles;
import org.neo4j.kernel.impl.transaction.log.files.LogFilesBuilder;
import org.neo4j.kernel.lifecycle.Lifespan;
import org.neo4j.kernel.monitoring.Monitors;
import org.neo4j.logging.LogProvider;

import static org.neo4j.kernel.impl.store.MetaDataStore.Position.LAST_TRANSACTION_ID;
Expand Down Expand Up @@ -84,18 +86,25 @@ public class CoreBootstrapper
private final FileSystemAbstraction fs;
private final Config config;
private final LogProvider logProvider;
private final RecoveryRequiredChecker recoveryRequiredChecker;

CoreBootstrapper( DatabaseLayout databaseLayout, PageCache pageCache, FileSystemAbstraction fs, Config config, LogProvider logProvider )
CoreBootstrapper( DatabaseLayout databaseLayout, PageCache pageCache, FileSystemAbstraction fs, Config config, LogProvider logProvider, Monitors monitors )
{
this.databaseLayout = databaseLayout;
this.pageCache = pageCache;
this.fs = fs;
this.config = config;
this.logProvider = logProvider;
this.recoveryRequiredChecker = new RecoveryRequiredChecker( fs, pageCache, config, monitors );
}

public CoreSnapshot bootstrap( Set<MemberId> members ) throws Exception
{
if ( recoveryRequiredChecker.isRecoveryRequiredAt( databaseLayout ) )
{
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" );
}
StoreFactory factory = new StoreFactory( databaseLayout, config,
new DefaultIdGeneratorFactory( fs ), pageCache, fs, logProvider, EmptyVersionContextSupplier.EMPTY );

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@
import org.junit.rules.RuleChain;

import java.io.File;
import java.io.IOException;
import java.util.Set;

import org.neo4j.causalclustering.backup.RestoreClusterUtils;
import org.neo4j.causalclustering.core.replication.session.GlobalSessionTrackerState;
import org.neo4j.causalclustering.core.state.machines.id.IdAllocationState;
import org.neo4j.causalclustering.core.state.machines.locks.ReplicatedLockTokenState;
import org.neo4j.causalclustering.core.state.machines.tx.LastCommittedIndexFinder;
import org.neo4j.causalclustering.core.state.snapshot.CoreSnapshot;
import org.neo4j.causalclustering.core.state.snapshot.CoreStateType;
import org.neo4j.causalclustering.core.state.snapshot.RaftCoreState;
import org.neo4j.causalclustering.helpers.ClassicNeo4jStore;
import org.neo4j.causalclustering.identity.MemberId;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.layout.DatabaseLayout;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.store.format.standard.Standard;
import org.neo4j.kernel.impl.store.id.IdType;
import org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionIdStore;
import org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionStore;
Expand All @@ -60,6 +60,7 @@
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.record_id_batch_size;
import static org.neo4j.helpers.collection.Iterators.asSet;

Expand All @@ -70,22 +71,20 @@ public class CoreBootstrapperIT
private final DefaultFileSystemRule fileSystemRule = new DefaultFileSystemRule();

@Rule
public RuleChain ruleChain = RuleChain.outerRule( pageCacheRule )
.around( pageCacheRule ).around( testDirectory );
public RuleChain ruleChain = RuleChain.outerRule( pageCacheRule ).around( pageCacheRule ).around( testDirectory );

@Test
public void shouldSetAllCoreState() throws Exception
{
// given
int nodeCount = 100;
FileSystemAbstraction fileSystem = fileSystemRule.get();
File classicNeo4jStore = RestoreClusterUtils.createClassicNeo4jStore(
testDirectory.directory(), fileSystem, nodeCount, Standard.LATEST_NAME );
File classicNeo4jStore = ClassicNeo4jStore.builder( testDirectory.directory(), fileSystem ).amountOfNodes( nodeCount ).build().getStoreDir();

PageCache pageCache = pageCacheRule.getPageCache( fileSystem );
DatabaseLayout databaseLayout = DatabaseLayout.of( classicNeo4jStore );
CoreBootstrapper bootstrapper = new CoreBootstrapper( databaseLayout, pageCache, fileSystem,
Config.defaults(), NullLogProvider.getInstance() );
CoreBootstrapper bootstrapper =
new CoreBootstrapper( databaseLayout, pageCache, fileSystem, Config.defaults(), NullLogProvider.getInstance(), new Monitors() );
bootstrapAndVerify( nodeCount, fileSystem, databaseLayout, pageCache, Config.defaults(), bootstrapper );
}

Expand All @@ -95,21 +94,84 @@ public void setAllCoreStateOnDatabaseWithCustomLogFilesLocation() throws Excepti
// given
int nodeCount = 100;
FileSystemAbstraction fileSystem = fileSystemRule.get();
File baseDirectory = testDirectory.directory();
String customTransactionLogsLocation = "transaction-logs";
File classicNeo4jStore = RestoreClusterUtils.createClassicNeo4jStore( baseDirectory, fileSystem, nodeCount,
Standard.LATEST_NAME, customTransactionLogsLocation );
File classicNeo4jStore = ClassicNeo4jStore
.builder( testDirectory.directory(), fileSystem )
.amountOfNodes( nodeCount )
.logicalLogsLocation( customTransactionLogsLocation )
.build()
.getStoreDir();

PageCache pageCache = pageCacheRule.getPageCache( fileSystem );
DatabaseLayout databaseLayout = DatabaseLayout.of( classicNeo4jStore );
Config config = Config.defaults( GraphDatabaseSettings.logical_logs_location,
customTransactionLogsLocation );
CoreBootstrapper bootstrapper = new CoreBootstrapper( databaseLayout, pageCache, fileSystem,
config, NullLogProvider.getInstance() );
Config config = Config.defaults( GraphDatabaseSettings.logical_logs_location, customTransactionLogsLocation );
CoreBootstrapper bootstrapper = new CoreBootstrapper( databaseLayout, pageCache, fileSystem, config, NullLogProvider.getInstance(), new Monitors() );

bootstrapAndVerify( nodeCount, fileSystem, databaseLayout, pageCache, config, bootstrapper );
}

@Test
public void shouldFailToBootstrapIfClusterIsInNeedOfRecovery() throws IOException
{
// given
int nodeCount = 100;
FileSystemAbstraction fileSystem = fileSystemRule.get();
File storeInNeedOfRecovery =
ClassicNeo4jStore.builder( testDirectory.directory(), fileSystem ).amountOfNodes( nodeCount ).needToRecover().build().getStoreDir();

PageCache pageCache = pageCacheRule.getPageCache( fileSystem );
DatabaseLayout databaseLayout = DatabaseLayout.of( storeInNeedOfRecovery );
CoreBootstrapper bootstrapper =
new CoreBootstrapper( databaseLayout, pageCache, fileSystem, Config.defaults(), NullLogProvider.getInstance(), new Monitors() );

// when
Set<MemberId> membership = asSet( randomMember(), randomMember(), randomMember() );
try
{
bootstrapper.bootstrap( membership );
fail();
}
catch ( Exception 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" );
}
}

@Test
public void shouldFailToBootstrapIfClusterIsInNeedOfRecoveryWithCustomLogicalLogsLocation() throws IOException
{
// given
int nodeCount = 100;
FileSystemAbstraction fileSystem = fileSystemRule.get();
String customTransactionLogsLocation = "transaction-logs";
File storeInNeedOfRecovery = ClassicNeo4jStore
.builder( testDirectory.directory(), fileSystem )
.amountOfNodes( nodeCount )
.logicalLogsLocation( customTransactionLogsLocation )
.needToRecover()
.build()
.getStoreDir();

PageCache pageCache = pageCacheRule.getPageCache( fileSystem );
DatabaseLayout databaseLayout = DatabaseLayout.of( storeInNeedOfRecovery );
Config config = Config.defaults( GraphDatabaseSettings.logical_logs_location, customTransactionLogsLocation );
CoreBootstrapper bootstrapper = new CoreBootstrapper( databaseLayout, pageCache, fileSystem, config, NullLogProvider.getInstance(), new Monitors() );

// when
Set<MemberId> membership = asSet( randomMember(), randomMember(), randomMember() );
try
{
bootstrapper.bootstrap( membership );
fail();
}
catch ( Exception 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" );
}
}

private static void bootstrapAndVerify( long nodeCount, FileSystemAbstraction fileSystem, DatabaseLayout databaseLayout, PageCache pageCache, Config config,
CoreBootstrapper bootstrapper ) throws Exception
{
Expand Down

0 comments on commit 9cfcccf

Please sign in to comment.