Skip to content

Commit

Permalink
Remove server startup timeout
Browse files Browse the repository at this point in the history
The startup block for the server is no longer wrapped in a timeout. This
startup timout has been severely watered down - upgrades and recovery happen
outside it, and HA has it disabled entirely. As such, it does not guard against
any known blocking startup actions, and remains only for historical reasons.

This commit removes it entirely, which simplifies the code.

We also remove all preflight tasks other than one. The upgrade and recovery
ones because they no longer need to happen outside the timeout, and the
config validating one becuase it was not used and is covered by the new Config
system usage in server instead
  • Loading branch information
jakewins committed Jul 1, 2015
1 parent 37d90c9 commit 709c804
Show file tree
Hide file tree
Showing 27 changed files with 272 additions and 2,046 deletions.
Expand Up @@ -28,7 +28,6 @@
import org.neo4j.server.advanced.AdvancedNeoServer; import org.neo4j.server.advanced.AdvancedNeoServer;
import org.neo4j.server.configuration.ConfigurationBuilder; import org.neo4j.server.configuration.ConfigurationBuilder;
import org.neo4j.server.helpers.CommunityServerBuilder; import org.neo4j.server.helpers.CommunityServerBuilder;
import org.neo4j.server.preflight.PreFlightTasks;
import org.neo4j.server.rest.web.DatabaseActions; import org.neo4j.server.rest.web.DatabaseActions;


import static org.neo4j.server.database.LifecycleManagingDatabase.lifecycleManagingDatabase; import static org.neo4j.server.database.LifecycleManagingDatabase.lifecycleManagingDatabase;
Expand Down Expand Up @@ -72,12 +71,6 @@ public TestAdvancedNeoServer( ConfigurationBuilder propertyFileConfigurator, Fil
this.configFile = configFile; this.configFile = configFile;
} }


@Override
protected PreFlightTasks createPreflightTasks()
{
return preflightTasks;
}

@Override @Override
protected DatabaseActions createDatabaseActions() protected DatabaseActions createDatabaseActions()
{ {
Expand Down
104 changes: 22 additions & 82 deletions community/server/src/main/java/org/neo4j/server/AbstractNeoServer.java
Expand Up @@ -66,8 +66,6 @@
import org.neo4j.server.modules.ServerModule; import org.neo4j.server.modules.ServerModule;
import org.neo4j.server.plugins.PluginInvocatorProvider; import org.neo4j.server.plugins.PluginInvocatorProvider;
import org.neo4j.server.plugins.PluginManager; import org.neo4j.server.plugins.PluginManager;
import org.neo4j.server.preflight.PreFlightTasks;
import org.neo4j.server.preflight.PreflightFailedException;
import org.neo4j.server.rest.paging.LeaseManager; import org.neo4j.server.rest.paging.LeaseManager;
import org.neo4j.server.rest.repr.InputFormatProvider; import org.neo4j.server.rest.repr.InputFormatProvider;
import org.neo4j.server.rest.repr.OutputFormatProvider; import org.neo4j.server.rest.repr.OutputFormatProvider;
Expand All @@ -82,9 +80,9 @@
import org.neo4j.server.rrd.RrdFactory; import org.neo4j.server.rrd.RrdFactory;
import org.neo4j.server.security.auth.AuthManager; import org.neo4j.server.security.auth.AuthManager;
import org.neo4j.server.security.auth.FileUserRepository; import org.neo4j.server.security.auth.FileUserRepository;
import org.neo4j.server.security.ssl.Certificates;
import org.neo4j.server.security.ssl.KeyStoreFactory; import org.neo4j.server.security.ssl.KeyStoreFactory;
import org.neo4j.server.security.ssl.KeyStoreInformation; import org.neo4j.server.security.ssl.KeyStoreInformation;
import org.neo4j.server.security.ssl.Certificates;
import org.neo4j.server.web.ServerInternalSettings; import org.neo4j.server.web.ServerInternalSettings;
import org.neo4j.server.web.SimpleUriBuilder; import org.neo4j.server.web.SimpleUriBuilder;
import org.neo4j.server.web.WebServer; import org.neo4j.server.web.WebServer;
Expand Down Expand Up @@ -118,8 +116,6 @@ public abstract class AbstractNeoServer implements NeoServer
protected final LogProvider logProvider; protected final LogProvider logProvider;
protected final Log log; protected final Log log;


private final PreFlightTasks preFlight;

private final List<ServerModule> serverModules = new ArrayList<>(); private final List<ServerModule> serverModules = new ArrayList<>();
private final SimpleUriBuilder uriBuilder = new SimpleUriBuilder(); private final SimpleUriBuilder uriBuilder = new SimpleUriBuilder();
private final Config dbConfig; private final Config dbConfig;
Expand All @@ -140,8 +136,6 @@ public abstract class AbstractNeoServer implements NeoServer
private TransactionFacade transactionFacade; private TransactionFacade transactionFacade;
private TransactionHandleRegistry transactionRegistry; private TransactionHandleRegistry transactionRegistry;


protected abstract PreFlightTasks createPreflightTasks();

protected abstract Iterable<ServerModule> createServerModules(); protected abstract Iterable<ServerModule> createServerModules();


protected abstract WebServer createWebServer(); protected abstract WebServer createWebServer();
Expand All @@ -158,7 +152,6 @@ public AbstractNeoServer( ConfigurationBuilder configurator, Database.Factory db
FileUserRepository users = life.add( new FileUserRepository( configurator.configuration().get( ServerInternalSettings.auth_store ).toPath(), logProvider ) ); FileUserRepository users = life.add( new FileUserRepository( configurator.configuration().get( ServerInternalSettings.auth_store ).toPath(), logProvider ) );


this.authManager = life.add(new AuthManager( users, Clock.SYSTEM_CLOCK, configurator.configuration().get( ServerSettings.auth_enabled ) )); this.authManager = life.add(new AuthManager( users, Clock.SYSTEM_CLOCK, configurator.configuration().get( ServerSettings.auth_enabled ) ));
this.preFlight = dependencyResolver.satisfyDependency(createPreflightTasks());
this.webServer = createWebServer(); this.webServer = createWebServer();


this.keyStoreInfo = initHttpsKeyStore(); this.keyStoreInfo = initHttpsKeyStore();
Expand All @@ -178,55 +171,39 @@ public void init()
@Override @Override
public void start() throws ServerStartupException public void start() throws ServerStartupException
{ {
InterruptThreadTimer interruptStartupTimer =
dependencyResolver.satisfyDependency( createInterruptStartupTimer() );

try try
{ {
// Pre-flight tasks run outside the boot timeout limit this.dbConfig.applyChanges( reloadConfigFromDisk() );
runPreflightTasks();

interruptStartupTimer.startCountdown();

try
{
this.dbConfig.applyChanges( reloadConfigFromDisk() );


life.start(); life.start();


DiagnosticsManager diagnosticsManager = resolveDependency(DiagnosticsManager.class); DiagnosticsManager diagnosticsManager = resolveDependency(DiagnosticsManager.class);


Log diagnosticsLog = diagnosticsManager.getTargetLog(); Log diagnosticsLog = diagnosticsManager.getTargetLog();
diagnosticsLog.info( "--- SERVER STARTED START ---" ); diagnosticsLog.info( "--- SERVER STARTED START ---" );


databaseActions = createDatabaseActions(); databaseActions = createDatabaseActions();


if(getConfig().get( ServerInternalSettings.webadmin_enabled )) if(getConfig().get( ServerInternalSettings.webadmin_enabled ))
{ {
// TODO: RrdDb is not needed once we remove the old webadmin // TODO: RrdDb is not needed once we remove the old webadmin
rrdDbScheduler = new RoundRobinJobScheduler( logProvider ); rrdDbScheduler = new RoundRobinJobScheduler( logProvider );
rrdDbWrapper = new RrdFactory( configurator.configuration(), logProvider ) rrdDbWrapper = new RrdFactory( configurator.configuration(), logProvider ).createRrdDbAndSampler( database, rrdDbScheduler );
.createRrdDbAndSampler( database, rrdDbScheduler ); }
}


transactionFacade = createTransactionalActions(); transactionFacade = createTransactionalActions();


cypherExecutor = new CypherExecutor( database ); cypherExecutor = new CypherExecutor( database );


configureWebServer(); configureWebServer();


cypherExecutor.start(); cypherExecutor.start();


startModules(); startModules();


startWebServer(); startWebServer();


diagnosticsLog.info( "--- SERVER STARTED END ---" ); diagnosticsLog.info( "--- SERVER STARTED END ---" );
}
finally
{
interruptStartupTimer.stopCountdown();
}
} }
catch ( Throwable t ) catch ( Throwable t )
{ {
Expand All @@ -236,17 +213,6 @@ public void start() throws ServerStartupException
// If the database has been started, attempt to cleanly shut it down to avoid unclean shutdowns. // If the database has been started, attempt to cleanly shut it down to avoid unclean shutdowns.
life.shutdown(); life.shutdown();


// Guard against poor operating systems that don't clear interrupt flags
// after having handled interrupts (looking at you, Bill).
Thread.interrupted();
if ( interruptStartupTimer.wasTriggered() )
{
throw new ServerStartupException(
"Startup took longer than " + interruptStartupTimer.getTimeoutMillis() + "ms, " +
"and was stopped. You can disable this behavior by setting '" + ServerInternalSettings.startup_timeout.name() + "' to 0.",
1 );
}

throw new ServerStartupException( format( "Starting Neo4j Server failed: %s", t.getMessage() ), t ); throw new ServerStartupException( format( "Starting Neo4j Server failed: %s", t.getMessage() ), t );
} }
} }
Expand Down Expand Up @@ -329,24 +295,6 @@ private long getTransactionTimeoutMillis()
return Math.max( timeout, MINIMUM_TIMEOUT + ROUNDING_SECOND ); return Math.max( timeout, MINIMUM_TIMEOUT + ROUNDING_SECOND );
} }


protected InterruptThreadTimer createInterruptStartupTimer()
{
long startupTimeout = configurator.configuration().get( ServerInternalSettings.startup_timeout );
InterruptThreadTimer stopStartupTimer;
if ( startupTimeout > 0 )
{
log.info( "Setting startup timeout to %dms", startupTimeout );
stopStartupTimer = InterruptThreadTimer.createTimer(
startupTimeout,
Thread.currentThread() );
}
else
{
stopStartupTimer = InterruptThreadTimer.createNoOpTimer();
}
return stopStartupTimer;
}

/** /**
* Use this method to register server modules from subclasses * Use this method to register server modules from subclasses
*/ */
Expand Down Expand Up @@ -383,14 +331,6 @@ public void run()
.run(); .run();
} }


private void runPreflightTasks()
{
if ( !preFlight.run() )
{
throw new PreflightFailedException( preFlight.failedTask() );
}
}

@Override @Override
public Config getConfig() public Config getConfig()
{ {
Expand Down Expand Up @@ -476,7 +416,7 @@ private void setUpHttpLogging()
} }
boolean contentLoggingEnabled = configurator.configuration().get( ServerSettings.http_logging_enabled ); boolean contentLoggingEnabled = configurator.configuration().get( ServerSettings.http_logging_enabled );


File logFile = configurator.configuration().get( ServerSettings.http_log_config_File ); File logFile = configurator.configuration().get( ServerSettings.http_log_config_file );
webServer.setHttpLoggingConfiguration( logFile, contentLoggingEnabled ); webServer.setHttpLoggingConfiguration( logFile, contentLoggingEnabled );
} }


Expand Down Expand Up @@ -506,7 +446,7 @@ private boolean httpLoggingProperlyConfigured()


private boolean configLocated() private boolean configLocated()
{ {
final File logFile = getConfig().get( ServerSettings.http_log_config_File ); final File logFile = getConfig().get( ServerSettings.http_log_config_file );
return logFile != null && logFile.exists(); return logFile != null && logFile.exists();
} }


Expand Down
Expand Up @@ -28,7 +28,6 @@
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.CommunityFacadeFactory; import org.neo4j.kernel.impl.factory.CommunityFacadeFactory;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory; import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory;
import org.neo4j.kernel.impl.storemigration.StoreUpgrader;
import org.neo4j.logging.LogProvider; import org.neo4j.logging.LogProvider;
import org.neo4j.server.configuration.ConfigurationBuilder; import org.neo4j.server.configuration.ConfigurationBuilder;
import org.neo4j.server.database.Database; import org.neo4j.server.database.Database;
Expand All @@ -43,10 +42,6 @@
import org.neo4j.server.modules.ServerModule; import org.neo4j.server.modules.ServerModule;
import org.neo4j.server.modules.ThirdPartyJAXRSModule; import org.neo4j.server.modules.ThirdPartyJAXRSModule;
import org.neo4j.server.modules.WebAdminModule; import org.neo4j.server.modules.WebAdminModule;
import org.neo4j.server.preflight.EnsurePreparedForHttpLogging;
import org.neo4j.server.preflight.PerformRecoveryIfNecessary;
import org.neo4j.server.preflight.PerformUpgradeIfNecessary;
import org.neo4j.server.preflight.PreFlightTasks;
import org.neo4j.server.rest.management.AdvertisableService; import org.neo4j.server.rest.management.AdvertisableService;
import org.neo4j.server.rest.management.JmxService; import org.neo4j.server.rest.management.JmxService;
import org.neo4j.server.rest.management.MonitorService; import org.neo4j.server.rest.management.MonitorService;
Expand Down Expand Up @@ -84,19 +79,6 @@ public CommunityNeoServer( ConfigurationBuilder configurator, Database.Factory d
super( configurator, dbFactory, dependencies, logProvider ); super( configurator, dbFactory, dependencies, logProvider );
} }


@Override
protected PreFlightTasks createPreflightTasks()
{
return new PreFlightTasks( logProvider,
// TODO: Move the config check into bootstrapper
//new EnsureNeo4jPropertiesExist(configurator.configuration()),
new EnsurePreparedForHttpLogging(configurator.configuration()),
new PerformUpgradeIfNecessary(getConfig(),
configurator.getDatabaseTuningProperties(), logProvider, StoreUpgrader.NO_MONITOR ),
new PerformRecoveryIfNecessary(getConfig(),
configurator.getDatabaseTuningProperties(), logProvider ) );
}

@Override @Override
protected Iterable<ServerModule> createServerModules() protected Iterable<ServerModule> createServerModules()
{ {
Expand Down

0 comments on commit 709c804

Please sign in to comment.