Skip to content

Commit

Permalink
disabling backup extension when it is not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
lassewesth committed Aug 16, 2017
1 parent 5bc1a61 commit 552d0b0
Show file tree
Hide file tree
Showing 18 changed files with 204 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.neo4j.backup.OnlineBackupSettings;
import org.neo4j.causalclustering.core.CausalClusteringSettings;
import org.neo4j.causalclustering.core.CoreGraphDatabase;
import org.neo4j.causalclustering.discovery.Cluster;
import org.neo4j.causalclustering.discovery.CoreClusterMember;
import org.neo4j.com.ports.allocation.PortAuthority;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.HostnamePort;
import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacade;
import org.neo4j.kernel.impl.store.format.standard.Standard;
Expand Down Expand Up @@ -121,6 +124,11 @@ static String[] backupArguments( String from, File backupsDir, String name )

static Config getConfig()
{
return Config.defaults( GraphDatabaseSettings.record_format, Standard.LATEST_NAME );
Map<String, String> config = MapUtil.stringMap(
GraphDatabaseSettings.record_format.name(), Standard.LATEST_NAME,
OnlineBackupSettings.online_backup_server.name(), "127.0.0.1:" + PortAuthority.allocatePort()
);

return Config.defaults( config );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@

import java.io.File;

import org.neo4j.backup.OnlineBackupSettings;
import org.neo4j.causalclustering.core.CoreGraphDatabase;
import org.neo4j.causalclustering.discovery.Cluster;
import org.neo4j.causalclustering.discovery.CoreClusterMember;
import org.neo4j.causalclustering.discovery.IpFamily;
import org.neo4j.causalclustering.discovery.SharedDiscoveryService;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.store.format.standard.Standard;
import org.neo4j.test.DbRepresentation;
import org.neo4j.test.rule.TestDirectory;
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.neo4j.backup.OnlineBackupCommandIT.runBackupToolFromOtherJvmToGetExitCode;
import static org.neo4j.causalclustering.backup.BackupCoreIT.backupAddress;
Expand Down Expand Up @@ -107,7 +110,8 @@ public void shouldRestoreBySeedingAllMembers() throws Throwable
{
// given
File backupDir = createBackupUsingAnotherCluster();
DbRepresentation before = DbRepresentation.of( backupDir );
Config config = Config.defaults( OnlineBackupSettings.online_backup_enabled, Boolean.FALSE.toString() );
DbRepresentation before = DbRepresentation.of( backupDir, config );

// when
fsa.copyRecursively( backupDir, cluster.getCoreMemberById( 0 ).storeDir() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.File;

import org.neo4j.backup.OnlineBackupSettings;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
Expand All @@ -43,6 +44,7 @@ public static File createClassicNeo4jStore( File base, FileSystemAbstraction fil
.setFileSystem( fileSystem )
.newEmbeddedDatabaseBuilder( existingDbDir )
.setConfig( GraphDatabaseSettings.record_format, recordFormat )
.setConfig( OnlineBackupSettings.online_backup_enabled, Boolean.FALSE.toString() )
.newGraphDatabase();

for ( int i = 0; i < (nodesToCreate / 2); i++ )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
import org.junit.Rule;
import org.junit.Test;

import org.neo4j.backup.OnlineBackupSettings;
import org.neo4j.causalclustering.discovery.Cluster;
import org.neo4j.causalclustering.discovery.IpFamily;
import org.neo4j.causalclustering.discovery.SharedDiscoveryService;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.configuration.Settings;
import org.neo4j.kernel.impl.store.format.highlimit.HighLimit;
import org.neo4j.test.DbRepresentation;
Expand All @@ -41,6 +43,7 @@

import static java.util.Collections.emptyMap;

import static java.util.Collections.singletonMap;
import static org.neo4j.causalclustering.discovery.Cluster.dataMatchesEventually;

public class ClusterCommunityToEnterpriseIT
Expand Down Expand Up @@ -78,9 +81,12 @@ public void shouldRestoreBySeedingAllMembers() throws Throwable
File storeDir = testDir.makeGraphDbDir();
GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir )
.setConfig( GraphDatabaseSettings.allow_store_upgrade, Settings.TRUE )
.setConfig( GraphDatabaseSettings.record_format, HighLimit.NAME ).newGraphDatabase();
.setConfig( GraphDatabaseSettings.record_format, HighLimit.NAME )
.setConfig( OnlineBackupSettings.online_backup_enabled, Boolean.FALSE.toString() )
.newGraphDatabase();
database.shutdown();
DbRepresentation before = DbRepresentation.of( storeDir );
Config config = Config.defaults( OnlineBackupSettings.online_backup_enabled, Settings.FALSE );
DbRepresentation before = DbRepresentation.of( storeDir, config );

// when
fsa.copyRecursively( storeDir, cluster.getCoreMemberById( 0 ).storeDir() );
Expand Down
16 changes: 11 additions & 5 deletions enterprise/ha/src/test/java/org/neo4j/ha/BackupHaIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
import java.util.List;

import org.neo4j.backup.OnlineBackupSettings;
import org.neo4j.com.ports.allocation.PortAuthority;
import org.neo4j.helpers.HostnamePort;
import org.neo4j.kernel.configuration.Settings;
import org.neo4j.kernel.ha.HighlyAvailableGraphDatabase;
import org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster;
import org.neo4j.test.DbRepresentation;
import org.neo4j.test.ha.ClusterRule;
Expand All @@ -44,7 +47,7 @@ public class BackupHaIT
@Rule
public ClusterRule clusterRule = new ClusterRule( getClass() )
.withSharedSetting( OnlineBackupSettings.online_backup_enabled, Settings.TRUE )
.withInstanceSetting( OnlineBackupSettings.online_backup_server, serverId -> ":" + (4444 + serverId) );
.withInstanceSetting( OnlineBackupSettings.online_backup_server, serverId -> ":" + PortAuthority.allocatePort() );
@Rule
public final SuppressOutput suppressOutput = SuppressOutput.suppressAll();

Expand All @@ -63,7 +66,9 @@ public void makeSureBackupCanBePerformed() throws Throwable
// Run backup
ManagedCluster cluster = clusterRule.startCluster();
DbRepresentation beforeChange = DbRepresentation.of( cluster.getMaster() );
assertEquals( 0, runBackupToolFromOtherJvmToGetExitCode( backupPath, backupArguments( "localhost:4445",
HighlyAvailableGraphDatabase hagdb = cluster.getAllMembers().iterator().next();
HostnamePort address = cluster.getBackupAddress(hagdb);
assertEquals( 0, runBackupToolFromOtherJvmToGetExitCode( backupPath, backupArguments( address.toString(),
backupPath, "basic" ) ) );

// Add some new data
Expand All @@ -80,13 +85,14 @@ public void makeSureBackupCanBePerformed() throws Throwable
public void makeSureBackupCanBePerformedFromAnyInstance() throws Throwable
{
ManagedCluster cluster = clusterRule.startCluster();
Integer[] backupPorts = {4445, 4446, 4447};

for ( Integer port : backupPorts )
for ( HighlyAvailableGraphDatabase hagdb : cluster.getAllMembers() )
{
HostnamePort address = cluster.getBackupAddress(hagdb);

// Run backup
DbRepresentation beforeChange = DbRepresentation.of( cluster.getMaster() );
assertEquals( 0, runBackupToolFromOtherJvmToGetExitCode( backupPath, backupArguments( "localhost:" + port,
assertEquals( 0, runBackupToolFromOtherJvmToGetExitCode( backupPath, backupArguments( address.toString(),
backupPath, "anyinstance" ) ) );

// Add some new data
Expand Down
2 changes: 2 additions & 0 deletions enterprise/ha/src/test/java/org/neo4j/ha/BranchedDataIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Set;
import java.util.function.Consumer;

import org.neo4j.backup.OnlineBackupSettings;
import org.neo4j.cluster.ClusterSettings;
import org.neo4j.com.ports.allocation.PortAuthority;
import org.neo4j.com.storecopy.StoreUtil;
Expand Down Expand Up @@ -101,6 +102,7 @@ public void migrationOfBranchedDataDirectories() throws Exception
.setConfig( ClusterSettings.cluster_server, "127.0.0.1:" + clusterPort )
.setConfig( ClusterSettings.initial_hosts, "localhost:" + clusterPort )
.setConfig( HaSettings.ha_server, "127.0.0.1:" + PortAuthority.allocatePort() )
.setConfig( OnlineBackupSettings.online_backup_enabled, Boolean.FALSE.toString() )
.newGraphDatabase().shutdown();
// It should have migrated those to the new location. Verify that.
for ( long timestamp : timestamps )
Expand Down
11 changes: 10 additions & 1 deletion enterprise/ha/src/test/java/org/neo4j/ha/ForeignStoreIdIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@

import java.io.File;

import org.neo4j.backup.OnlineBackupSettings;
import org.neo4j.com.ports.allocation.PortAuthority;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.EnterpriseGraphDatabaseFactory;
import org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory;
import org.neo4j.kernel.configuration.Settings;
import org.neo4j.test.rule.TestDirectory;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -73,6 +75,7 @@ public void emptyForeignDbShouldJoinAfterHavingItsEmptyDbDeleted() throws Except
.setConfig( cluster_server, "127.0.0.1:" + firstInstanceClusterPort )
.setConfig( ha_server, "127.0.0.1:" + PortAuthority.allocatePort() )
.setConfig( initial_hosts, "127.0.0.1:" + firstInstanceClusterPort )
.setConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE )
.newGraphDatabase();
// -- another instance preparing to join with a store with a different store ID
File foreignDbStoreDir = createAnotherStore( testDirectory.directory( "2" ), 0 );
Expand All @@ -85,6 +88,7 @@ public void emptyForeignDbShouldJoinAfterHavingItsEmptyDbDeleted() throws Except
.setConfig( initial_hosts, "127.0.0.1:" + firstInstanceClusterPort )
.setConfig( cluster_server, "127.0.0.1:" + PortAuthority.allocatePort() )
.setConfig( ha_server, "127.0.0.1:" + PortAuthority.allocatePort() )
.setConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE )
.newGraphDatabase();
// -- and creates a node
long foreignNode = createNode( foreignInstance, "foreigner" );
Expand All @@ -106,6 +110,7 @@ public void nonEmptyForeignDbShouldNotBeAbleToJoin() throws Exception
.setConfig( initial_hosts, "127.0.0.1:" + firstInstanceClusterPort )
.setConfig( cluster_server, "127.0.0.1:" + firstInstanceClusterPort )
.setConfig( ha_server, "127.0.0.1:" + PortAuthority.allocatePort() )
.setConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE )
.newGraphDatabase();
createNodes( firstInstance, 3, "first" );
// -- another instance preparing to join with a store with a different store ID
Expand All @@ -120,6 +125,7 @@ public void nonEmptyForeignDbShouldNotBeAbleToJoin() throws Exception
.setConfig( cluster_server, "127.0.0.1:" + PortAuthority.allocatePort() )
.setConfig( ha_server, "127.0.0.1:" + PortAuthority.allocatePort() )
.setConfig( state_switch_timeout, "5s" )
.setConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE )
.newGraphDatabase();

try
Expand Down Expand Up @@ -153,7 +159,10 @@ private long findNode( GraphDatabaseService db, String name )

private File createAnotherStore( File directory, int transactions )
{
GraphDatabaseService db = new EnterpriseGraphDatabaseFactory().newEmbeddedDatabase( directory );
GraphDatabaseService db = new EnterpriseGraphDatabaseFactory()
.newEmbeddedDatabaseBuilder( directory )
.setConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE )
.newGraphDatabase();
createNodes( db, transactions, "node" );
db.shutdown();
return directory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

import org.neo4j.backup.OnlineBackupSettings;
import org.neo4j.cluster.ClusterSettings;
import org.neo4j.cluster.InstanceId;
import org.neo4j.cluster.client.ClusterClient;
Expand Down Expand Up @@ -258,6 +259,7 @@ private static HighlyAvailableGraphDatabase database( int serverId, int clusterP
.setConfig( ClusterSettings.server_id, Integer.toString( serverId ) )
.setConfig( HaSettings.ha_server, "localhost:" + haPort )
.setConfig( HaSettings.pull_interval, "0ms" )
.setConfig( OnlineBackupSettings.online_backup_enabled, Boolean.FALSE.toString() )
.newGraphDatabase();
}

Expand Down
22 changes: 15 additions & 7 deletions enterprise/ha/src/test/java/org/neo4j/ha/PullUpdatesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import org.neo4j.backup.OnlineBackupSettings;
import org.neo4j.cluster.ClusterSettings;
import org.neo4j.cluster.InstanceId;
import org.neo4j.cluster.client.ClusterClient;
Expand All @@ -42,6 +43,7 @@
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.TransientTransactionFailureException;
import org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.configuration.Settings;
import org.neo4j.kernel.ha.HaSettings;
import org.neo4j.kernel.ha.HighlyAvailableGraphDatabase;
Expand Down Expand Up @@ -70,7 +72,6 @@
public class PullUpdatesIT
{
private static final int PULL_INTERVAL = 100;
private static final int SHELL_PORT = 6370;

@Rule
public final ClusterRule clusterRule = new ClusterRule( getClass() );
Expand Down Expand Up @@ -172,15 +173,19 @@ public void pullUpdatesShellAppPullsUpdates() throws Throwable
withSharedSetting( HaSettings.pull_interval, "0" ).
withSharedSetting( HaSettings.tx_push_factor, "0" ).
withSharedSetting( ShellSettings.remote_shell_enabled, Settings.TRUE ).
withInstanceSetting( ShellSettings.remote_shell_port,
oneBasedServerId -> oneBasedServerId >= 1 && oneBasedServerId <= 2 ?
"" + (SHELL_PORT + oneBasedServerId) : null ).
withInstanceSetting( ShellSettings.remote_shell_port, i -> String.valueOf( PortAuthority.allocatePort() ) ).
startCluster();

long commonNodeId = createNodeOnMaster( cluster );

setProperty( cluster.getMaster(), commonNodeId, 1 );
callPullUpdatesViaShell( 2 );

int shellPort = cluster.getAnySlave()
.getDependencyResolver().resolveDependency( Config.class )
.get( ShellSettings.remote_shell_port );

callPullUpdatesViaShell( shellPort );

HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
try ( Transaction tx = slave.beginTx() )
{
Expand All @@ -205,6 +210,7 @@ public void shouldPullUpdatesOnStartupNoMatterWhat() throws Exception
.setConfig( ClusterSettings.cluster_server, "127.0.0.1:" + masterClusterPort )
.setConfig( ClusterSettings.initial_hosts, "localhost:" + masterClusterPort )
.setConfig( HaSettings.ha_server, "127.0.0.1:" + PortAuthority.allocatePort() )
.setConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE )
.newGraphDatabase();

// Copy the store, then shutdown, so update pulling later makes sense
Expand All @@ -215,6 +221,7 @@ public void shouldPullUpdatesOnStartupNoMatterWhat() throws Exception
.setConfig( ClusterSettings.cluster_server, "127.0.0.1:" + PortAuthority.allocatePort() )
.setConfig( ClusterSettings.initial_hosts, "localhost:" + masterClusterPort )
.setConfig( HaSettings.ha_server, "127.0.0.1:" + PortAuthority.allocatePort() )
.setConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE )
.newGraphDatabase();

// Required to block until the slave has left for sure
Expand Down Expand Up @@ -256,6 +263,7 @@ public void leftCluster( InstanceId instanceId, URI member )
.setConfig( ClusterSettings.initial_hosts, "localhost:" + masterClusterPort )
.setConfig( HaSettings.ha_server, "127.0.0.1:" + PortAuthority.allocatePort() )
.setConfig( HaSettings.pull_interval, "0" ) // no pull updates, should pull on startup
.setConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE )
.newGraphDatabase();

slave.beginTx().close(); // Make sure switch to slave completes and so does the update pulling on startup
Expand Down Expand Up @@ -302,9 +310,9 @@ private static long createNodeOn( GraphDatabaseService db )
}
}

private void callPullUpdatesViaShell( int i ) throws ShellException
private void callPullUpdatesViaShell( int port ) throws ShellException
{
ShellClient client = ShellLobby.newClient( SHELL_PORT + i );
ShellClient client = ShellLobby.newClient( port );
client.evaluate( "pullupdates" );
}

Expand Down

0 comments on commit 552d0b0

Please sign in to comment.