5
votes

I'm having an issue trying to create indexes on RavenDB 3.5

When creating more than 3 indexes the application just dies, getting a

Unable to connect to the remote server Status Code: ConnectFailure

The index creation code is farely straight forward:

    private static void CreateIndexes(IDocumentStore documentStore)
    {
        new PurchaseOrder_QueryByExternalReference().Execute(documentStore);
        new SupplierDocument_QueryBySupplierName().Execute(documentStore);
        new ProductDocument_QueryByProductIdAndName().Execute(documentStore);
        new PurchaseOrderLine_QueryableIndex().Execute(documentStore);
        new PurchaseOrderLine_ForPurchaseOrderIndex().Execute(documentStore);
    }

But the same happens if the

IndexCreation.CreateIndexes(typeof(MyIndexClass).Assembly, store);

method is called. This happens with any 3 indexes from the list on any order.

Full stack-trace is this:

exception {"A task was canceled."} Data: {System.Collections.ListDictionaryInternal} Etag: null HResult: -2146233088 HelpLink: null InnerException: null Message: "A task was canceled." Response: {StatusCode: 503, ReasonPhrase: 'Service Unavailable', Version: 1.1, Content: , Headers: { }} ResponseString: "Unable to connect to the remote server Status Code: ConnectFailure" Source: "Raven.Client.Lightweight" StackTrace: " at Raven.Client.Connection.Implementation.HttpJsonRequest.<>c__DisplayClass36_0.<b__0>d.MoveNext() in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Connection\Implementation\HttpJsonRequest.cs:line 258 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Client.Connection.Implementation.HttpJsonRequest.d__381.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\Implementation\\HttpJsonRequest.cs:line 312 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Client.Connection.Implementation.HttpJsonRequest.<ReadResponseJsonAsync>d__35.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\Implementation\\HttpJsonRequest.cs:line 221 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Client.Connection.Async.AsyncServerClient.<>c__DisplayClass69_0.<<GetIndexAsync>b__0>d.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\Async\\AsyncServerClient.cs:line 726 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Client.Connection.ReplicationInformerBase1.d__341.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\ReplicationInformerBase.cs:line 417 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Raven.Client.Connection.ReplicationInformerBase1.d__331.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\ReplicationInformerBase.cs:line 316 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Client.Connection.Async.AsyncServerClient.<ExecuteWithReplication>d__1641.MoveNext() in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Connection\Async\AsyncServerClient.cs:line 0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Abstractions.Util.AsyncHelpers.<>c__DisplayClass1_11.<<RunSync>b__0>d.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Abstractions\\Util\\AsyncHelpers.cs:line 75 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Raven.Abstractions.Util.AsyncHelpers.RunSync[T](Func1 task) in C:\Builds\RavenDB-Stable-3.5\Raven.Abstractions\Util\AsyncHelpers.cs:line 89 at Raven.Client.Connection.ServerClient.GetIndex(String name) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Connection\ServerClient.cs:line 222\ at Raven.Client.Indexes.AbstractIndexCreationTask.Execute(IDatabaseCommands databaseCommands, DocumentConvention documentConvention) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Indexes\AbstractIndexCreationTask.cs:line 304 at Raven.Client.DocumentStoreBase.ExecuteIndex(AbstractIndexCreationTask indexCreationTask) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\DocumentStoreBase.cs:line 102 at Raven.Client.Indexes.AbstractIndexCreationTask.Execute(IDocumentStore store) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Indexes\AbstractIndexCreationTask.cs:line 221 at Persistence.Database.Adapter.RavenDb.RavenDbDocumentStoreFactory.CreateIndexes(IDocumentStore documentStore) in \my\route\Persistence.Database.Adapter\RavenDb\RavenDbDocumentStoreFactory.cs:line 50 at Persistence.Database.Adapter.RavenDb.RavenDbDocumentStoreFactory.ConfigureDocumentStore(IDocumentStore documentStore) in \my\route\Persistence.Database.Adapter\RavenDb\RavenDbDocumentStoreFactory.cs:line 38 at Persistence.Database.Adapter.RavenDb.RavenDbDocumentStoreFactory.Create(String ravenDbLocation, String ravenDbDatabase) in \my\route\Persistence.Database.Adapter\RavenDb\RavenDbDocumentStoreFactory.cs:line 22 at Persistence.Database.Adapter.PersistenceAdapter.<.ctor>b__8_0() in \my\route\Persistence.Database.Adapter\PersistenceAdapter.cs:line 53 at Persistence.Database.Adapter.PersistenceAdapter.RegisterRavenDbUtilities() in \my\route\Persistence.Database.Adapter\PersistenceAdapter.cs:line 175 at Persistence.Database.Adapter.PersistenceAdapter.RegisterRavenLogic() in \my\route\Persistence.Database.Adapter\PersistenceAdapter.cs:line 86 at Persistence.Database.Adapter.PersistenceAdapter.Initialize() in \my\route\Persistence.Database.Adapter\PersistenceAdapter.cs:line 74 at My-Program.ConfigurePersistentAdapter(Settings settings) in \my\route\MessageQueueListener\MessageQueueListenerService.cs:line 153 at My-Program.AddBootstrapperExtension() in \my\route\net-stock-purchasing-service.MessageQueueListener\MessageQueueListenerService.cs:line 118 at My-Program.Startup() in \my\route\net-stock-purchasing-service.MessageQueueListener\MessageQueueListenerService.cs:line 78" StatusCode: ServiceUnavailable TargetSite: {Void MoveNext()}

3
This typically means that there is some sort of a timeout. Depending on your index, it may take a LOT of time to prepare it. What does fiddler say?Ayende Rahien
@AyendeRahienwhy could there be a timeout? all indexes are very small in code, or do you mean on the amount of data that will be indexed due to it?evilpilaf
I'm not sure. The Fiddler trace should have more informationAyende Rahien
Any update on this? i'm facing same issue with an empty db & 5 indexes exactly in the line where i call store.ExecuteIndexes(...)Guillermo Rdguez Glez

3 Answers

4
votes

When RavenDB 3.5 was release, something broke in the client package.

If you are running RavenDB.Client from 3.0.30000 to 3.0.30179, then it should work.

If you are running a higher version, then you will encounter (in certain conditions) this exception. To resolve that, you can use an alternate API: store.DatabaseCommands.PutIndexes.

var indexes = new List<AbstractIndexCreationTask>();
indexes.Add(new MyIndex1());
indexes.Add(new MyIndex2());
indexes.Add(new MyIndex....());

var transfos = new List<AbstractTransformerCreationTask>();
transfos.Add(new MyTransformer1());
transfos.Add(new MyTransformer2());
transfos.Add(new MyTransformer...());

// put indexes in 1 command
var indexesToPut = IndexCreation.CreateIndexesToAdd(indexes, documentStore.Conventions);
documentStore.DatabaseCommands.PutIndexes(indexesToPut);

// don't forget transformers
foreach (var item in transfos)
{
    item.Execute(Store);
}

This should solve your problem.

I was encountering this problem after upgrading my client package. Note that the exception occurred only in console applications and not in my web applications.

1
votes

That solved the issue for me:

var indexes = IndexCreation.CreateIndexesToAdd(new List<AbstractIndexCreationTask> {...}, store.Conventions);

var alreadyExisting = store.DatabaseCommands.GetIndexes(0, 128)
            .ToDictionary(i => i.Name);

foreach (var index in indexes.Where(i => !alreadyExisting.ContainsKey(i.Name)))
    store.DatabaseCommands.PutIndex(index.Name, index.Definition);

store.DatabaseCommands.PutIndexes(indexes);
1
votes

In my case it turned out to be due to a mismatch of ravendb client library and the installed server. My application was running the latest version of the RavenDB client and the server is using version 3.0