Search in sources :

Example 41 with GraphDatabaseAPI

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());
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Config(org.neo4j.kernel.configuration.Config) Test(org.junit.Test)

Example 42 with GraphDatabaseAPI

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));
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Config(org.neo4j.kernel.configuration.Config) Test(org.junit.Test)

Example 43 with GraphDatabaseAPI

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();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) File(java.io.File) Test(org.junit.Test)

Example 44 with GraphDatabaseAPI

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());
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) COUNTS_STORE_RIGHT(org.neo4j.kernel.impl.storemigration.StoreFile.COUNTS_STORE_RIGHT) ResourceIterator(org.neo4j.graphdb.ResourceIterator) SimpleKernelContext(org.neo4j.kernel.impl.spi.SimpleKernelContext) Log(org.neo4j.logging.Log) Dependencies(org.neo4j.kernel.impl.util.Dependencies) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) NullLogProvider(org.neo4j.logging.NullLogProvider) IOCursor(org.neo4j.cursor.IOCursor) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) FormattedLogProvider(org.neo4j.logging.FormattedLogProvider) LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) Assert.fail(org.junit.Assert.fail) MismatchingStoreIdException(org.neo4j.kernel.impl.store.MismatchingStoreIdException) Transaction(org.neo4j.graphdb.Transaction) StoreUtil(org.neo4j.com.storecopy.StoreUtil) LogFiles(org.neo4j.kernel.impl.storemigration.LogFiles) PageCache(org.neo4j.io.pagecache.PageCache) Position(org.neo4j.kernel.impl.store.MetaDataStore.Position) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) StorageEngine(org.neo4j.storageengine.api.StorageEngine) FileUtils(org.neo4j.io.fs.FileUtils) TestDirectory(org.neo4j.test.rule.TestDirectory) LogService(org.neo4j.kernel.impl.logging.LogService) ReadOnlyTransactionStore(org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionStore) Executors(java.util.concurrent.Executors) EmbeddedDatabaseRule(org.neo4j.test.rule.EmbeddedDatabaseRule) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) Logger(org.neo4j.logging.Logger) Assert.assertFalse(org.junit.Assert.assertFalse) DependencyResolver(org.neo4j.graphdb.DependencyResolver) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) SuppressOutput(org.neo4j.test.rule.SuppressOutput) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) Index(org.neo4j.graphdb.index.Index) LogHeaderReader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader) DependenciesProxy(org.neo4j.kernel.impl.util.DependenciesProxy) Mockito.mock(org.mockito.Mockito.mock) CoreMatchers.anyOf(org.hamcrest.CoreMatchers.anyOf) Label(org.neo4j.graphdb.Label) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) UncloseableDelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Monitors(org.neo4j.kernel.monitoring.Monitors) LogProvider(org.neo4j.logging.LogProvider) IOLimiter(org.neo4j.io.pagecache.IOLimiter) Node(org.neo4j.graphdb.Node) BaseMatcher(org.hamcrest.BaseMatcher) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) PageCacheRule(org.neo4j.test.rule.PageCacheRule) StoreCopyServer(org.neo4j.com.storecopy.StoreCopyServer) ConnectException(java.net.ConnectException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) Description(org.hamcrest.Description) Config(org.neo4j.kernel.configuration.Config) Barrier(org.neo4j.test.Barrier) DatabaseInfo(org.neo4j.kernel.impl.factory.DatabaseInfo) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) File(java.io.File) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Mockito.verify(org.mockito.Mockito.verify) RuleChain(org.junit.rules.RuleChain) TimeUnit(java.util.concurrent.TimeUnit) Rule(org.junit.Rule) FileFilter(java.io.FileFilter) Iterables(org.neo4j.helpers.collection.Iterables) DefaultFileSystemRule(org.neo4j.test.rule.fs.DefaultFileSystemRule) DbRepresentation(org.neo4j.test.DbRepresentation) COUNTS_STORE_LEFT(org.neo4j.kernel.impl.storemigration.StoreFile.COUNTS_STORE_LEFT) Assert.assertEquals(org.junit.Assert.assertEquals) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) File(java.io.File) Test(org.junit.Test)

Example 45 with GraphDatabaseAPI

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));
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Test(org.junit.Test)

Aggregations

GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)133 Test (org.junit.Test)96 Transaction (org.neo4j.graphdb.Transaction)50 File (java.io.File)25 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)25 Node (org.neo4j.graphdb.Node)20 DependencyResolver (org.neo4j.graphdb.DependencyResolver)19 Config (org.neo4j.kernel.configuration.Config)15 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)12 IOException (java.io.IOException)8 PageCache (org.neo4j.io.pagecache.PageCache)8 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)8 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)8 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)6 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)6 Before (org.junit.Before)5 Label (org.neo4j.graphdb.Label)5 GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)5 GuardTimeoutException (org.neo4j.kernel.guard.GuardTimeoutException)5