use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.
the class BackupServiceIT method shouldFallbackToFullBackupIfIncrementalFailsAndExplicitlyAskedToDoThis.
@Test
public void shouldFallbackToFullBackupIfIncrementalFailsAndExplicitlyAskedToDoThis() throws Exception {
// Given
defaultBackupPortHostParams();
Config defaultConfig = dbRule.getConfigCopy();
dbRule.setConfig(GraphDatabaseSettings.keep_logical_logs, "false");
// have logs rotated on every transaction
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
BackupService backupService = backupService();
createAndIndexNode(db, 1);
// A full backup
backupService.doFullBackup(BACKUP_HOST, backupPort, backupDir.getAbsoluteFile(), ConsistencyCheck.NONE, defaultConfig, BackupClient.BIG_READ_TIMEOUT, false);
// And the log the backup uses is rotated out
createAndIndexNode(db, 2);
rotateAndCheckPoint(db);
createAndIndexNode(db, 3);
rotateAndCheckPoint(db);
createAndIndexNode(db, 4);
rotateAndCheckPoint(db);
// when
backupService.doIncrementalBackupOrFallbackToFull(BACKUP_HOST, backupPort, backupDir.getAbsoluteFile(), ConsistencyCheck.NONE, defaultConfig, BackupClient.BIG_READ_TIMEOUT, false);
// Then
db.shutdown();
assertEquals(getDbRepresentation(), getBackupDbRepresentation());
}
use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.
the class BackupServiceIT method shouldGiveHelpfulErrorMessageIfLogsPrunedPastThePointOfNoReturn.
@Test
public void shouldGiveHelpfulErrorMessageIfLogsPrunedPastThePointOfNoReturn() throws Exception {
// Given
defaultBackupPortHostParams();
Config defaultConfig = dbRule.getConfigCopy();
dbRule.setConfig(GraphDatabaseSettings.keep_logical_logs, "false");
// have logs rotated on every transaction
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
BackupService backupService = backupService();
createAndIndexNode(db, 1);
rotateAndCheckPoint(db);
// A full backup
backupService.doFullBackup(BACKUP_HOST, backupPort, backupDir.getAbsoluteFile(), ConsistencyCheck.NONE, defaultConfig, BackupClient.BIG_READ_TIMEOUT, false);
// And the log the backup uses is rotated out
createAndIndexNode(db, 2);
rotateAndCheckPoint(db);
createAndIndexNode(db, 3);
rotateAndCheckPoint(db);
createAndIndexNode(db, 4);
rotateAndCheckPoint(db);
createAndIndexNode(db, 5);
rotateAndCheckPoint(db);
// when
try {
backupService.doIncrementalBackup(BACKUP_HOST, backupPort, backupDir.getAbsoluteFile(), BackupClient.BIG_READ_TIMEOUT, defaultConfig);
fail("Should have thrown exception.");
}// Then
catch (IncrementalBackupNotPossibleException e) {
assertThat(e.getMessage(), equalTo(BackupService.TOO_OLD_BACKUP));
}
}
use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.
the class BackupServiceIT method shouldThrowExceptionWhenDoingFullBackupWhenDirectoryHasSomeFiles.
@Test
public void shouldThrowExceptionWhenDoingFullBackupWhenDirectoryHasSomeFiles() throws Exception {
// given
defaultBackupPortHostParams();
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
createAndIndexNode(db, 1);
// Touch a random file
assertTrue(new File(backupDir, ".jibberishfile").createNewFile());
try {
// when
backupService().doFullBackup(BACKUP_HOST, backupPort, backupDir.getAbsoluteFile(), ConsistencyCheck.FULL, dbRule.getConfigCopy(), BackupClient.BIG_READ_TIMEOUT, false);
fail("Should have thrown an exception");
} catch (RuntimeException ex) {
// then
assertThat(ex.getMessage(), containsString("is not empty"));
} finally {
db.shutdown();
}
}
use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.
the class BackupServiceIT method shouldBeAbleToBackupEvenIfTransactionLogsAreIncomplete.
@Test
public void shouldBeAbleToBackupEvenIfTransactionLogsAreIncomplete() throws Throwable {
/*
* This test deletes the old persisted log file and expects backup to still be functional. It
* should not be assumed that the log files have any particular length of history. They could
* for example have been mangled during backups or removed during pruning.
*/
// given
defaultBackupPortHostParams();
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
for (int i = 0; i < 100; i++) {
createAndIndexNode(db, i);
}
final File oldLog = db.getDependencyResolver().resolveDependency(LogFile.class).currentLogFile();
rotateAndCheckPoint(db);
for (int i = 0; i < 1; i++) {
createAndIndexNode(db, i);
}
rotateAndCheckPoint(db);
long lastCommittedTxBefore = db.getDependencyResolver().resolveDependency(TransactionIdStore.class).getLastCommittedTransactionId();
db = dbRule.restartDatabase((fs, storeDirectory) -> FileUtils.deleteFile(oldLog));
long lastCommittedTxAfter = db.getDependencyResolver().resolveDependency(TransactionIdStore.class).getLastCommittedTransactionId();
// when
BackupService backupService = backupService();
BackupService.BackupOutcome outcome = backupService.doFullBackup(BACKUP_HOST, backupPort, backupDir.getAbsoluteFile(), ConsistencyCheck.FULL, dbRule.getConfigCopy(), BackupClient.BIG_READ_TIMEOUT, false);
db.shutdown();
// then
assertEquals(lastCommittedTxBefore, lastCommittedTxAfter);
assertTrue(outcome.isConsistent());
assertEquals(getDbRepresentation(), getBackupDbRepresentation());
}
use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.
the class BackupServiceIT method shouldThrowUsefulMessageWhenCannotConnectDuringIncrementalBackup.
@Test
public void shouldThrowUsefulMessageWhenCannotConnectDuringIncrementalBackup() throws Exception {
defaultBackupPortHostParams();
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
BackupService backupService = backupService();
createAndIndexNode(db, 1);
// A full backup
backupService.doFullBackup(BACKUP_HOST, backupPort, backupDir, ConsistencyCheck.NONE, dbRule.getConfigCopy(), BackupClient.BIG_READ_TIMEOUT, false);
try {
backupService().doIncrementalBackupOrFallbackToFull(BACKUP_HOST, 56789, backupDir, ConsistencyCheck.NONE, dbRule.getConfigCopy(), BackupClient.BIG_READ_TIMEOUT, false);
fail("No exception thrown");
} catch (RuntimeException e) {
assertThat(e.getMessage(), containsString("BackupClient could not connect"));
assertThat(e.getCause(), instanceOf(ConnectException.class));
}
}
Aggregations