Skip to content

Commit

Permalink
Always delete the temp-copy directory after store copy
Browse files Browse the repository at this point in the history
Not cleaning up the directory might fail the backup tool, since it
expects a db is the target directory is not empty.  It might happen
though that the directory is not empty due to a failed store copy,
hence the backup tool will attempt an incremental backup on a
non-existent db and be unable to recover from there.  This change will
make sure to alway cleanup after store copy no matter what the outcome
is.
  • Loading branch information
davidegrohmann committed Oct 13, 2016
1 parent 90cc660 commit 503f7ff
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 103 deletions.
Expand Up @@ -181,53 +181,61 @@ public StoreCopyClient( File storeDir, Config config, Iterable<KernelExtensionFa
this.forensics = forensics;
}

public void copyStore( StoreCopyRequester requester, CancellationRequest cancellationRequest )
throws Exception
public void copyStore( StoreCopyRequester requester, CancellationRequest cancellationRequest ) throws Exception
{
// Create a temp directory (or clean if present)
File tempStore = new File( storeDir, TEMP_COPY_DIRECTORY_NAME );
List<FileMoveAction> fileMoveActions = new ArrayList<>();
cleanDirectory( tempStore );

// Request store files and transactions that will need recovery
monitor.startReceivingStoreFiles();
try ( Response<?> response = requester.copyStore( decorateWithProgressIndicator(
new ToFileStoreWriter( tempStore, monitor, pageCache, fileMoveActions ) ) ) )
{
monitor.finishReceivingStoreFiles();
// Update highest archived log id
// Write transactions that happened during the copy to the currently active logical log
writeTransactionsToActiveLogFile( tempStore, response );
}
finally
try
{
requester.done();
}
// Request store files and transactions that will need recovery
monitor.startReceivingStoreFiles();
try ( Response<?> response = requester.copyStore( decorateWithProgressIndicator(
new ToFileStoreWriter( tempStore, monitor, pageCache, fileMoveActions ) ) ) )
{
monitor.finishReceivingStoreFiles();
// Update highest archived log id
// Write transactions that happened during the copy to the currently active logical log
writeTransactionsToActiveLogFile( tempStore, response );
}
finally
{
requester.done();
}

// This is a good place to check if the switch has been cancelled
checkCancellation( cancellationRequest, tempStore );
// This is a good place to check if the switch has been cancelled
checkCancellation( cancellationRequest, tempStore );

// Run recovery, so that the transactions we just wrote into the active log will be applied.
monitor.startRecoveringStore();
GraphDatabaseService graphDatabaseService = newTempDatabase( tempStore );
graphDatabaseService.shutdown();
monitor.finishRecoveringStore();
// Run recovery, so that the transactions we just wrote into the active log will be applied.
monitor.startRecoveringStore();
GraphDatabaseService graphDatabaseService = newTempDatabase( tempStore );
graphDatabaseService.shutdown();
monitor.finishRecoveringStore();

// All is well, move the streamed files to the real store directory
// Start with the files written through the page cache. Should only be record store files
for ( FileMoveAction fileMoveAction : fileMoveActions )
{
fileMoveAction.move( storeDir, StandardCopyOption.REPLACE_EXISTING );
}
// All is well, move the streamed files to the real store directory
// Start with the files written through the page cache. Should only be record store files
for ( FileMoveAction fileMoveAction : fileMoveActions )
{
fileMoveAction.move( storeDir, StandardCopyOption.REPLACE_EXISTING );
}

// And continue with the rest of the files
for ( File candidate : tempStore.listFiles( STORE_FILE_FILTER ) )
// And continue with the rest of the files
File[] files = tempStore.listFiles( STORE_FILE_FILTER );
if ( files != null )
{
for ( File candidate : files )
{
FileUtils.moveFileToDirectory( candidate, storeDir );
}
}
}
finally
{
FileUtils.moveFileToDirectory( candidate, storeDir );
// All done, delete temp directory
FileUtils.deleteRecursively( tempStore );
}

// All done, delete temp directory
FileUtils.deleteRecursively( tempStore );
}

private void writeTransactionsToActiveLogFile( File tempStoreDir, Response<?> response ) throws Exception
Expand Down

0 comments on commit 503f7ff

Please sign in to comment.