Skip to content

Commit

Permalink
Revert backup log files delete, fix tools tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Nov 16, 2017
1 parent c67aa10 commit 90a60e0
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 62 deletions.
28 changes: 0 additions & 28 deletions enterprise/backup/src/main/java/org/neo4j/backup/BackupFlow.java
Expand Up @@ -20,7 +20,6 @@
package org.neo4j.backup;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
Expand All @@ -30,10 +29,7 @@
import org.neo4j.consistency.ConsistencyCheckService;
import org.neo4j.consistency.checking.full.ConsistencyFlags;
import org.neo4j.helpers.progress.ProgressMonitorFactory;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.transaction.log.files.LogFiles;
import org.neo4j.kernel.impl.transaction.log.files.LogFilesBuilder;
import org.neo4j.logging.LogProvider;

import static java.lang.String.format;
Expand Down Expand Up @@ -104,30 +100,6 @@ void performBackup( OnlineBackupContext onlineBackupContext ) throws CommandFail
{
performConsistencyCheck( onlineBackupContext.getConfig(), requiredArgs, consistencyFlags, destination );
}
cleanupTransactionLogFiles( destination );
}

/**
* As result of backup database should be fully restored and it should be safe to delete any transaction log
* files that available since they also can be configured to live in a separate place on the instance where db
* will be restored.
* @param backupFolder backup folder
*/
private void cleanupTransactionLogFiles( File backupFolder ) throws CommandFailed
{
try
{
FileSystemAbstraction fileSystem = outsideWorld.fileSystem();
LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder( backupFolder, fileSystem ).build();
for ( File file : logFiles.logFiles() )
{
fileSystem.deleteFile( file );
}
}
catch ( IOException e )
{
throw new CommandFailed( format( "Fail to cleanup transaction logs." ), e );
}
}

private static Supplier<CommandFailed> commandFailedWithCause( PotentiallyErroneousState<BackupStrategyOutcome> cause )
Expand Down
Expand Up @@ -66,8 +66,6 @@
import org.neo4j.kernel.impl.transaction.log.MissingLogDataException;
import org.neo4j.kernel.impl.transaction.log.TransactionIdStore;
import org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader;
import org.neo4j.kernel.impl.transaction.log.files.LogFiles;
import org.neo4j.kernel.impl.transaction.log.files.LogFilesBuilder;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.kernel.lifecycle.Lifespan;
import org.neo4j.kernel.monitoring.ByteCounterMonitor;
Expand Down Expand Up @@ -166,7 +164,6 @@ private BackupOutcome fullBackup( FileSystemAbstraction fileSystem, String sourc
bumpDebugDotLogFileVersion( debugLogFile, timestamp );
boolean consistent = checkDbConsistency( fileSystem, targetDirectory, consistencyCheck, tuningConfiguration, pageCache );
clearIdFiles( fileSystem, targetDirectory );
clearTransactionLogFiles( fileSystem, targetDirectory );
return new BackupOutcome( lastCommittedTx, consistent );
}
catch ( Exception e )
Expand Down Expand Up @@ -221,7 +218,6 @@ private BackupOutcome incrementalBackup( FileSystemAbstraction fileSystem, Strin
bumpDebugDotLogFileVersion( debugLogFile, backupStartTime );
boolean consistent = checkDbConsistency( fileSystem, targetDirectory, consistencyCheck, config, pageCache );
clearIdFiles( fileSystem, targetDirectory );
clearTransactionLogFiles( fileSystem, targetDirectory );
return new BackupOutcome( lastCommittedTx, consistent );
}
catch ( IOException e )
Expand Down Expand Up @@ -418,17 +414,6 @@ private List<KernelExtensionFactory<?>> loadKernelExtensions()
return kernelExtensions;
}

private void clearTransactionLogFiles( FileSystemAbstraction fileSystem, File targetDirectory ) throws IOException
{
LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder( targetDirectory, fileSystem ).build();
File[] files = logFiles.logFiles();
for ( File file : files )
{
fileSystem.deleteFile( file );
}

}

private void clearIdFiles( FileSystemAbstraction fileSystem, File targetDirectory ) throws IOException
{
for ( File file : fileSystem.listFiles( targetDirectory ) )
Expand Down
Expand Up @@ -510,11 +510,11 @@ public void backupDatabaseWithCustomTransactionLogsLocation() throws IOException
LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder( new File( backupStore ), fileSystemRule.get() ).build();

backup.full( backupStore );
assertThat( logFiles.logFiles(), Matchers.emptyArray() );
assertThat( logFiles.logFiles(), Matchers.arrayWithSize( 1 ) );

DbRepresentation representation = addLotsOfData( db );
backup.incremental( backupStore );
assertThat( logFiles.logFiles(), Matchers.emptyArray() );
assertThat( logFiles.logFiles(), Matchers.arrayWithSize( 1 ) );

assertEquals( representation, getDbRepresentation() );
}
Expand Down
Expand Up @@ -24,7 +24,6 @@
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -36,19 +35,15 @@
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.enterprise.configuration.OnlineBackupSettings;
import org.neo4j.kernel.impl.store.format.standard.Standard;
import org.neo4j.kernel.impl.transaction.log.files.LogFiles;
import org.neo4j.kernel.impl.transaction.log.files.LogFilesBuilder;
import org.neo4j.ports.allocation.PortAuthority;
import org.neo4j.test.DbRepresentation;
import org.neo4j.test.causalclustering.ClusterRule;
import org.neo4j.test.rule.SuppressOutput;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.neo4j.graphdb.Label.label;
import static org.neo4j.util.TestHelpers.runBackupToolFromOtherJvmToGetExitCode;
Expand Down Expand Up @@ -82,8 +77,6 @@ public void makeSureBackupCanBePerformedFromAnyInstance() throws Throwable
String[] args = backupArguments( backupAddress( cluster ), backupsDir, "" + db.serverId() );
assertEquals( 0, runBackupToolFromOtherJvmToGetExitCode( clusterRule.clusterDirectory(), args ) );

checkThatTxLogFilesDoesNotExist( db );

// Add some new data
DbRepresentation afterChange = DbRepresentation.of( createSomeData( cluster ) );

Expand All @@ -94,14 +87,6 @@ public void makeSureBackupCanBePerformedFromAnyInstance() throws Throwable
}
}

private void checkThatTxLogFilesDoesNotExist( CoreClusterMember db ) throws IOException
{
FileSystemAbstraction fileSystemAbstraction =
db.database().getDependencyResolver().resolveDependency( FileSystemAbstraction.class );
LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder( backupsDir, fileSystemAbstraction ).build();
assertFalse( logFiles.versionExists( 0 ) );
}

static CoreGraphDatabase createSomeData( Cluster cluster ) throws Exception
{
return cluster.coreTx( ( db, tx ) ->
Expand Down
Expand Up @@ -95,7 +95,7 @@ else if ( whereTo.equals( "last" ) )
out.println( "Applied transactions up to and including " + lastApplied );
}

private long applyTransactions( File fromPath, GraphDatabaseAPI toDb, Config config,
private long applyTransactions( File fromPath, GraphDatabaseAPI toDb, Config toConfig,
long fromTxExclusive, long toTxInclusive, PrintStream out )
throws IOException, TransactionFailureException
{
Expand All @@ -109,7 +109,7 @@ private long applyTransactions( File fromPath, GraphDatabaseAPI toDb, Config con
PageCache pageCache = StandalonePageCacheFactory.createPageCache( fileSystem ) )
{
LogicalTransactionStore source = life.add( new ReadOnlyTransactionStore( pageCache, fileSystem, fromPath,
config, new Monitors() ) );
Config.defaults(), new Monitors() ) );
life.start();
long lastAppliedTx = fromTxExclusive;
// Some progress if there are more than a couple of transactions to apply
Expand Down

0 comments on commit 90a60e0

Please sign in to comment.