Archive for the ‘Raven DB’ Category

Raven DB Exception

January 8, 2016

This post is about an exception that was logged in Elmah in one of the web projects I’ve worked on:

Could not open database named: X
System.TimeoutException: The database X is currently being loaded, but after 5 seconds, this request has been aborted. Please try again later, database loading continues.

This happens when the below code is executed on a database of 65.000 documents:

var documentStore = new DocumentStore

{

ConnectionStringName = RavenDbInstance
};
documentStore.Initialize();
using (var session = documentStore.OpenSession())
{
registered = session.Query<MyModel>().FirstOrDefault(x => x.Name == name);
}

The reason why this happens is that if the database is loaded for the first time in memory, the task that loads it will wait for 5 seconds before throwing an exception. There is a configuration setting called Raven/MaxSecondsForTaskToWaitForDatabaseToLoad which can be increased to avoid such scenarios if the database is getting larger and larger.

 

One other thing to consider is increasing the time allowed for a database to be idle.

If the database is idle for long periods of time it will get evicted from the memory which causes the web server to load the DB from disk which will get us to the first scenario.

The default value for this configuration setting is 900 seconds:

Raven/Tenants/MaxIdleTimeForTenantDatabase