Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fail loudly when doing backup against an old version backup
Incremental backup has the following scenarios, when run against an existing backup B: 1. B is "up to date" (incremental backup possible) 2. B is "too far out of date" (full backup required) 3. B is a backup of an older database store (because you just updated to 3.1 and your backup is of 3.0) 4. B is a backup of a different store but the same version Previously, 3 and 4 were intended to behave differently. 4 would correctly fail with an error to avoid deleting someone's precious backup files. 3 failed with an error due a bug in the error handling logic, the intention was to move the old backup and then do a full backup. However, another bug (masked by the error handling bug) would have deleted that directory. Regardless, the correct thing is to fail for 3. The primary reason being that it is impossible (or unreasonably hard) to determine if both 3 and 4 apply (e.g., it's a backup of a different store which also has a different version). This because we start an embedded database server as part of the backup, and that will always fail if the store is of a different version. Conflicts: enterprise/backup/src/main/java/org/neo4j/backup/BackupTool.java
- Loading branch information
1 parent
4304147
commit 7f2985e
Showing
4 changed files
with
135 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
enterprise/backup/src/test/java/org/neo4j/backup/BackupToolIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.backup; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import java.io.File; | ||
import java.io.PrintStream; | ||
import java.nio.file.Path; | ||
|
||
import org.neo4j.helpers.HostnamePort; | ||
import org.neo4j.io.fs.DefaultFileSystemAbstraction; | ||
import org.neo4j.io.pagecache.PageCache; | ||
import org.neo4j.kernel.configuration.Config; | ||
import org.neo4j.kernel.impl.pagecache.StandalonePageCacheFactory; | ||
import org.neo4j.kernel.impl.store.MetaDataStore; | ||
import org.neo4j.kernel.impl.store.format.standard.StandardV2_3; | ||
import org.neo4j.test.EmbeddedDatabaseRule; | ||
import org.neo4j.test.TargetDirectory; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.neo4j.kernel.impl.store.MetaDataStore.Position.STORE_VERSION; | ||
|
||
public class BackupToolIT | ||
{ | ||
@Rule | ||
public TargetDirectory.TestDirectory testDirectory = TargetDirectory.testDirForTest( getClass() ); | ||
|
||
@Rule | ||
public ExpectedException expected = ExpectedException.none(); | ||
|
||
@Rule | ||
public EmbeddedDatabaseRule dbRule = new EmbeddedDatabaseRule( getClass() ).startLazily(); | ||
|
||
private DefaultFileSystemAbstraction fs; | ||
private PageCache pageCache; | ||
private Path backupDir; | ||
private BackupTool backupTool; | ||
|
||
@Before | ||
public void setUp() throws Exception | ||
{ | ||
backupDir = testDirectory.directory( "backups/graph.db" ).toPath(); | ||
fs = new DefaultFileSystemAbstraction(); | ||
pageCache = StandalonePageCacheFactory.createPageCache( fs ); | ||
backupTool = new BackupTool( new BackupService(), mock( PrintStream.class ) ); | ||
} | ||
|
||
@After | ||
public void teardown() throws Exception | ||
{ | ||
pageCache.close(); | ||
} | ||
|
||
@Test | ||
public void oldIncompatibleBackupsAreMovedToSubDir() throws Exception | ||
{ | ||
// Prepare an "old" backup | ||
prepareNeoStoreFile( StandardV2_3.STORE_VERSION ); | ||
|
||
// Start database to backup | ||
dbRule.getGraphDatabaseAPI(); | ||
|
||
expected.expect( BackupTool.ToolFailureException.class ); | ||
expected.expectMessage( "Failed to perform backup because existing backup is from a different version." ); | ||
|
||
// Perform backup | ||
backupTool.executeBackup( new HostnamePort( "localhost", 6362 ), backupDir.toFile(), | ||
ConsistencyCheck.NONE, Config.defaults(), 20L * 60L * 1000L, false ); | ||
} | ||
|
||
private void prepareNeoStoreFile( String storeVersion ) throws Exception | ||
{ | ||
File neoStoreFile = createNeoStoreFile(); | ||
long value = MetaDataStore.versionStringToLong( storeVersion ); | ||
MetaDataStore.setRecord( pageCache, neoStoreFile, STORE_VERSION, value ); | ||
} | ||
|
||
private File createNeoStoreFile() throws Exception | ||
{ | ||
fs.mkdirs( backupDir.toFile() ); | ||
File neoStoreFile = new File( backupDir.toFile(), MetaDataStore.DEFAULT_NAME ); | ||
fs.create( neoStoreFile ).close(); | ||
return neoStoreFile; | ||
} | ||
} |