Search in sources :

Example 1 with LifecycleException

use of org.neo4j.kernel.lifecycle.LifecycleException in project neo4j by neo4j.

the class NeoStoreDataSourceTest method shouldAlwaysShutdownLifeEvenWhenCheckPointingFails.

@Test
public void shouldAlwaysShutdownLifeEvenWhenCheckPointingFails() throws Exception {
    // Given
    File storeDir = dir.graphDbDir();
    FileSystemAbstraction fs = this.fs.get();
    PageCache pageCache = pageCacheRule.getPageCache(fs);
    DatabaseHealth databaseHealth = mock(DatabaseHealth.class);
    when(databaseHealth.isHealthy()).thenReturn(true);
    IOException ex = new IOException("boom!");
    doThrow(ex).when(databaseHealth).assertHealthy(// <- this is a trick to simulate a failure during checkpointing
    IOException.class);
    NeoStoreDataSource dataSource = dsRule.getDataSource(storeDir, fs, pageCache, emptyMap(), databaseHealth);
    dataSource.start();
    try {
        // When
        dataSource.stop();
        fail("it should have thrown");
    } catch (LifecycleException e) {
        // Then
        assertEquals(ex, e.getCause());
    }
}
Also used : DatabaseHealth(org.neo4j.kernel.internal.DatabaseHealth) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) IOException(java.io.IOException) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 2 with LifecycleException

use of org.neo4j.kernel.lifecycle.LifecycleException in project neo4j by neo4j.

the class ServerStartupErrorsTest method shouldDescribeUpgradeFailureInAFriendlyWay.

@Test
public void shouldDescribeUpgradeFailureInAFriendlyWay() {
    // given
    AssertableLogProvider logging = new AssertableLogProvider();
    LifecycleException error = new LifecycleException(new Object(), STARTING, STARTED, new RuntimeException("Error starting org.neo4j.kernel.ha.factory.EnterpriseFacadeFactory", new LifecycleException(new Object(), STARTING, STARTED, new LifecycleException(new Object(), STARTING, STARTED, new UpgradeNotAllowedByConfigurationException()))));
    // when
    translateToServerStartupError(error).describeTo(logging.getLog("console"));
    // then
    logging.assertExactly(inLog("console").error("Neo4j cannot be started, because the database files require upgrading and upgrades are " + "disabled in configuration. Please set '%s' to 'true' in your configuration file and try " + "again.", "dbms.allow_format_migration"));
}
Also used : UpgradeNotAllowedByConfigurationException(org.neo4j.kernel.impl.storemigration.UpgradeNotAllowedByConfigurationException) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 3 with LifecycleException

use of org.neo4j.kernel.lifecycle.LifecycleException in project neo4j by neo4j.

the class DatabaseStartupTest method startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed.

@Test
public void startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed() throws Throwable {
    // given
    // create a store
    File storeDir = testDirectory.graphDbDir();
    GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
    try (Transaction tx = db.beginTx()) {
        db.createNode();
        tx.success();
    }
    db.shutdown();
    // mess up the version in the metadatastore
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem)) {
        MetaDataStore.setRecord(pageCache, new File(storeDir, MetaDataStore.DEFAULT_NAME), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong("bad"));
    }
    // when
    try {
        new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
        fail("It should have failed.");
    } catch (RuntimeException ex) {
        // then
        assertTrue(ex.getCause() instanceof LifecycleException);
        assertTrue(ex.getCause().getCause() instanceof UpgradeNotAllowedByConfigurationException);
        assertEquals("Failed to start Neo4j with an older data store version. To enable automatic upgrade, " + "please set configuration parameter \"dbms.allow_format_migration=true\"", ex.getCause().getCause().getMessage());
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) UpgradeNotAllowedByConfigurationException(org.neo4j.kernel.impl.storemigration.UpgradeNotAllowedByConfigurationException) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 4 with LifecycleException

use of org.neo4j.kernel.lifecycle.LifecycleException in project neo4j by neo4j.

the class ArbiterBootstrapper method start.

@SafeVarargs
@Override
public final int start(File homeDir, Optional<File> configFile, Pair<String, String>... configOverrides) {
    Config config = getConfig(configFile, configOverrides);
    try {
        DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        life.add(new FileSystemLifecycleAdapter(fileSystem));
        life.add(new Neo4jJobScheduler());
        new ClusterClientModule(life, new Dependencies(), new Monitors(), config, logService(fileSystem, config), new NotElectableElectionCredentialsProvider());
    } catch (LifecycleException e) {
        @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "unchecked" }) Throwable cause = peel(e, Predicates.<Throwable>instanceOf(LifecycleException.class));
        if (cause instanceof ChannelException) {
            System.err.println("ERROR: " + cause.getMessage() + (cause.getCause() != null ? ", caused by:" + cause.getCause().getMessage() : ""));
        } else {
            System.err.println("ERROR: Unknown error");
            throw e;
        }
    }
    addShutdownHook();
    life.start();
    return 0;
}
Also used : FileSystemLifecycleAdapter(org.neo4j.io.fs.FileSystemLifecycleAdapter) Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) NotElectableElectionCredentialsProvider(org.neo4j.cluster.protocol.election.NotElectableElectionCredentialsProvider) Monitors(org.neo4j.kernel.monitoring.Monitors) Dependencies(org.neo4j.kernel.impl.util.Dependencies) ClusterClientModule(org.neo4j.cluster.client.ClusterClientModule) ChannelException(org.jboss.netty.channel.ChannelException)

Example 5 with LifecycleException

use of org.neo4j.kernel.lifecycle.LifecycleException in project neo4j by neo4j.

the class DatabaseStartupTest method startTheDatabaseWithWrongVersionShouldFailAlsoWhenUpgradeIsAllowed.

@Test
public void startTheDatabaseWithWrongVersionShouldFailAlsoWhenUpgradeIsAllowed() throws Throwable {
    // given
    // create a store
    File storeDir = testDirectory.graphDbDir();
    GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
    try (Transaction tx = db.beginTx()) {
        db.createNode();
        tx.success();
    }
    db.shutdown();
    // mess up the version in the metadatastore
    String badStoreVersion = "bad";
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem)) {
        MetaDataStore.setRecord(pageCache, new File(storeDir, MetaDataStore.DEFAULT_NAME), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong(badStoreVersion));
    }
    // when
    try {
        new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir).setConfig(GraphDatabaseSettings.allow_store_upgrade, "true").newGraphDatabase();
        fail("It should have failed.");
    } catch (RuntimeException ex) {
        // then
        assertTrue(ex.getCause() instanceof LifecycleException);
        assertTrue(ex.getCause().getCause() instanceof StoreUpgrader.UnexpectedUpgradingStoreVersionException);
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Aggregations

LifecycleException (org.neo4j.kernel.lifecycle.LifecycleException)5 Test (org.junit.Test)4 File (java.io.File)3 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)3 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)3 PageCache (org.neo4j.io.pagecache.PageCache)3 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 Transaction (org.neo4j.graphdb.Transaction)2 UpgradeNotAllowedByConfigurationException (org.neo4j.kernel.impl.storemigration.UpgradeNotAllowedByConfigurationException)2 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)2 IOException (java.io.IOException)1 ChannelException (org.jboss.netty.channel.ChannelException)1 ClusterClientModule (org.neo4j.cluster.client.ClusterClientModule)1 NotElectableElectionCredentialsProvider (org.neo4j.cluster.protocol.election.NotElectableElectionCredentialsProvider)1 FileSystemLifecycleAdapter (org.neo4j.io.fs.FileSystemLifecycleAdapter)1 Config (org.neo4j.kernel.configuration.Config)1 Dependencies (org.neo4j.kernel.impl.util.Dependencies)1 Neo4jJobScheduler (org.neo4j.kernel.impl.util.Neo4jJobScheduler)1 DatabaseHealth (org.neo4j.kernel.internal.DatabaseHealth)1 Monitors (org.neo4j.kernel.monitoring.Monitors)1