Skip to content

Commit

Permalink
Use RestoreDatabaseCommand when seeding stores
Browse files Browse the repository at this point in the history
Make sure configurations such as logical_logs_location are respected by
using the RestoreDatabaseCommand instead of simply recursively copy
the files.
  • Loading branch information
RagnarW committed Dec 4, 2017
1 parent ce914ba commit 1c6b0d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Expand Up @@ -26,11 +26,9 @@
import org.junit.Test;

import java.io.File;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.IntFunction;

import org.neo4j.causalclustering.catchup.tx.FileCopyMonitor;
import org.neo4j.causalclustering.catchup.tx.PullRequestMonitor;
Expand All @@ -51,9 +49,9 @@
import org.neo4j.test.rule.fs.DefaultFileSystemRule;

import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.neo4j.causalclustering.BackupCoreIT.backupAddress;
import static org.neo4j.causalclustering.discovery.Cluster.dataMatchesEventually;
import static org.neo4j.causalclustering.helpers.DataCreator.createEmptyNodes;
Expand Down Expand Up @@ -138,15 +136,19 @@ public void shouldRestoreBySeedingAllMembers() throws Throwable
DbRepresentation before = DbRepresentation.of( backupDir, config );

// when
fsa.copyRecursively( backupDir, cluster.getCoreMemberById( 0 ).storeDir() );
fsa.copyRecursively( backupDir, cluster.getCoreMemberById( 1 ).storeDir() );
fsa.copyRecursively( backupDir, cluster.getCoreMemberById( 2 ).storeDir() );
for ( CoreClusterMember coreClusterMember : cluster.coreMembers() )
{
String databaseName = coreClusterMember
.getMemberConfig().get( GraphDatabaseSettings.active_database );
new RestoreDatabaseCommand( fsa, backupDir, coreClusterMember.getMemberConfig(), databaseName, true )
.execute();
}
cluster.start();

// then
dataMatchesEventually( before, cluster.coreMembers() );
assertFalse( detectFileCopyMonitor.fileCopyDetected.get() );
assertEquals( 4, pullRequestMonitor.numberOfRequests() );
assertTrue( pullRequestMonitor.numberOfRequests() >= 2 );
}

@Test
Expand Down Expand Up @@ -174,7 +176,6 @@ public void shouldSeedNewMemberFromEmptyIdleCluster() throws Throwable
dataMatchesEventually( DbRepresentation.of( newMember.database() ), cluster.coreMembers() );
assertFalse( detectFileCopyMonitor.fileCopyDetected.get() );
assertEquals( 1, pullRequestMonitor.numberOfRequests() );
assertEquals( 1, pullRequestMonitor.lastRequestedTxId() );
}

@Test
Expand Down
Expand Up @@ -35,10 +35,12 @@
import org.neo4j.function.ThrowingSupplier;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.store.format.highlimit.HighLimit;
import org.neo4j.kernel.impl.store.format.standard.Standard;
import org.neo4j.restore.RestoreDatabaseCommand;
import org.neo4j.test.causalclustering.ClusterRule;

import static java.util.concurrent.TimeUnit.SECONDS;
Expand Down Expand Up @@ -81,7 +83,8 @@ public void shouldReplicateTransactionToCoreMembers() throws Throwable
{
for ( CoreClusterMember core : cluster.coreMembers() )
{
fileSystem.copyRecursively( classicNeo4jStore, core.storeDir() );
new RestoreDatabaseCommand( fileSystem, classicNeo4jStore, core.getMemberConfig(), core.settingValue(
GraphDatabaseSettings.active_database.name() ), true ).execute();
}
}

Expand Down

0 comments on commit 1c6b0d8

Please sign in to comment.