Skip to content

Commit

Permalink
Fix for too small rotation in backup client
Browse files Browse the repository at this point in the history
  • Loading branch information
phughk committed Jun 26, 2018
1 parent 97a7aed commit 4de9aa3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
Expand Up @@ -311,7 +311,7 @@ private String argAdditionalConf( File backupTarget ) throws IOException
return format( "--additional-config=%s", configFile );
}

private void writeConfigToFile( Config config, File file ) throws IOException
static void writeConfigToFile( Config config, File file ) throws IOException
{
try ( Writer fileWriter = new BufferedWriter( new FileWriter( file ) ) )
{
Expand Down
Expand Up @@ -194,7 +194,9 @@ public OnlineBackupContext createContext( String... args ) throws IncorrectUsage
// We only replace the page cache memory setting.
// Any other custom page swapper, etc. settings are preserved and used.
config.augment( pagecache_memory, pagecacheMemory );
overrideConfigWithBackupSpecificSettings( config );

// Disable prometheus to avoid binding exceptions
config.augment( "metrics.prometheus.enabled", Settings.FALSE );

// Build consistency-checker configuration.
// Note: We can remove the loading from config file in 4.0.
Expand All @@ -217,15 +219,6 @@ public OnlineBackupContext createContext( String... args ) throws IncorrectUsage
}
}

private void overrideConfigWithBackupSpecificSettings( Config config )
{
// We don't want to pile up tx logs
config.augment( GraphDatabaseSettings.logical_log_rotation_threshold, "1m" ); // Forces rotations to be performed when catching up

// Disable prometheus to avoid binding exceptions
config.augment( "metrics.prometheus.enabled", Settings.FALSE );
}

private Path getBackupDirectory( Arguments arguments ) throws CommandFailed
{
Path path = arguments.getMandatoryPath( ARG_NAME_BACKUP_DIRECTORY );
Expand Down
Expand Up @@ -285,13 +285,22 @@ public void onlyTheLatestTransactionIsKeptAfterIncrementalBackup() throws Except
Cluster cluster = startCluster( recordFormat );
createSomeData( cluster );

// and backup client is told to rotate conveniently
Config config = Config
.builder()
.withSetting( GraphDatabaseSettings.logical_log_rotation_threshold, "1m" )
.build();
File configOverrideFile = testDirectory.file( "neo4j-backup.conf" );
OnlineBackupCommandBuilder.writeConfigToFile( config, configOverrideFile );

// and we have a full backup
String backupName = "backupName" + recordFormat;
String address = CausalClusteringTestHelpers.backupAddress( clusterLeader( cluster ).database() );
assertEquals( 0, runBackupToolFromOtherJvmToGetExitCode(
"--from", address,
"--cc-report-dir=" + backupDir,
"--backup-dir=" + backupDir,
"--additional-config=" + configOverrideFile,
"--name=" + backupName ) );

// and the database contains a few more transactions
Expand All @@ -303,6 +312,7 @@ public void onlyTheLatestTransactionIsKeptAfterIncrementalBackup() throws Except
"--from", address,
"--cc-report-dir=" + backupDir,
"--backup-dir=" + backupDir,
"--additional-config=" + configOverrideFile,
"--name=" + backupName ) );

// then there has been a rotation
Expand Down
Expand Up @@ -338,6 +338,14 @@ public void onlyTheLatestTransactionIsKeptAfterIncrementalBackup() throws Except
startDb( port );
createSomeData( db );

// and backup client is told to rotate conveniently
Config config = Config
.builder()
.withSetting( GraphDatabaseSettings.logical_log_rotation_threshold, "1m" )
.build();
File configOverrideFile = testDirectory.file( "neo4j-backup.conf" );
OnlineBackupCommandBuilder.writeConfigToFile( config, configOverrideFile );

// and we have a full backup
String backupName = "backupName" + recordFormat;
String address = "localhost:" + port;
Expand All @@ -346,6 +354,7 @@ public void onlyTheLatestTransactionIsKeptAfterIncrementalBackup() throws Except
"--cc-report-dir=" + backupDir,
"--backup-dir=" + backupDir,
"--protocol=common",
"--additional-config=" + configOverrideFile,
"--name=" + backupName ) );

// and the database contains a few more transactions
Expand All @@ -358,6 +367,7 @@ public void onlyTheLatestTransactionIsKeptAfterIncrementalBackup() throws Except
"--cc-report-dir=" + backupDir,
"--backup-dir=" + backupDir,
"--protocol=common",
"--additional-config=" + configOverrideFile,
"--name=" + backupName ) );

// then there has been a rotation
Expand Down
Expand Up @@ -334,18 +334,6 @@ public void overrideWithLegacy() throws CommandFailed, IncorrectUsage
}
}

@Test
public void configIsProvided1mRotation() throws CommandFailed, IncorrectUsage
{
OnlineBackupContextFactory builder = new OnlineBackupContextFactory( homeDir, configDir );

//
OnlineBackupContext context = builder.createContext( requiredAnd() );

// then
assertEquals( ByteUnit.mebiBytes( 1 ), context.getConfig().get( GraphDatabaseSettings.logical_log_rotation_threshold ).longValue() );
}

@Test
public void prometheusShouldBeDisabledToAvoidPortConflicts() throws CommandFailed, IncorrectUsage
{
Expand Down

0 comments on commit 4de9aa3

Please sign in to comment.