创建索引

时间:2017-07-05 14:00:51

标签: c# .net indexing ravendb

我在尝试在RavenDB 3.5上创建索引时遇到问题

当创建3个以上的索引时,应用程序就会死掉,得到一个

  

无法连接到远程服务器状态代码:ConnectFailure

索引创建代码非常简单:

    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);
    }

但如果

,也会发生同样的情况
  

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

调用

方法。任何订单上的列表中的任何3个索引都会发生这种情况。

完整堆栈跟踪是这样的:

  

例外   {“任务被取消。”}       数据:{System.Collections.ListDictionaryInternal}       Etag:null       HResult:-2146233088       HelpLink:null       InnerException:null       消息:“任务被取消了。”       响应:{StatusCode:503,ReasonPhrase:'Service Unavailable',版本:1.1,内容:,标题:   {   }}       ResponseString:“无法连接到远程服务器状态代码:ConnectFailure”       资料来源:“Raven.Client.Lightweight”       StackTrace:“在Raven.Client.Connection.Implementation.HttpJsonRequest。&lt;&gt; c__DisplayClass36_0。&lt; b__0&gt; d.MoveNext()在C:\ Builds \ RavenDB-Stable-3.5 \ Raven.Client.Lightweight \ Connection \ Implementation \ HttpJsonRequest.cs:第258行       ---从抛出异常的先前位置开始的堆栈跟踪结束---       在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)       在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)       在Raven.Client.Connection.Implementation.HttpJsonRequest.d__38 1.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.ReplicationInformerBase 1.d__34 1.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.ReplicationInformerBase 1.d__33 1.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__164 1.MoveNext()在C:\ Builds \ RavenDB-Stable-3.5 \ Raven.Client.Lightweight \ Connection \ Async \ AsyncServerClient.cs:第0行       ---从抛出异常的先前位置开始的堆栈跟踪结束---       在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)       在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)       at Raven.Abstractions.Util.AsyncHelpers。&lt;&gt; c__DisplayClass1_1 1.<<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](Func 1任务)在C:\ Builds \ RavenDB-Stable-3.5 \ Raven.Abstractions \ Util \ AsyncHelpers.cs:第89行       位于C:\ Builds \ RavenDB-Stable-3.5 \ Raven.Client.Lightweight \ Connection \ ServerClient.cs中的Raven.Client.Connection.ServerClient.GetIndex(String name):第222行      at Raven.Client.Indexes.AbstractIndexCreationTask.Execute(IDatabaseCommands databaseCommands,DocumentConvention documentConvention)在C:\ Builds \ RavenDB-Stable-3.5 \ Raven.Client.Lightweight \ Indexes \ AbstractIndexCreationTask.cs:第304行      在Raven.Client.DocumentStoreBase.ExecuteIndex(AbstractIndexCreationTask indexCreationTask)中的C:\ Builds \ RavenDB-Stable-3.5 \ Raven.Client.Lightweight \ DocumentStoreBase.cs:第102行      at Raven.Client.Indexes.AbstractIndexCreationTask.Execute(IDocumentStore store)在C:\ Builds \ RavenDB-Stable-3.5 \ Raven.Client.Lightweight \ Indexes \ AbstractIndexCreationTask.cs:第221行      在\ my \ route \ Persistence.Database.Adapter \ RavenDb \ RavenDbDocumentStoreFactory.cs中的Persistence.Database.Adapter.RavenDb.RavenDbDocumentStoreFactory.CreateIndexes(IDocumentStore documentStore):第50行      位于\ my \ route \ Persistence.Database.Adapter \ RavenDb \ RavenDbDocumentStoreFactory.cs中的Persistence.Database.Adapter.RavenDb.RavenDbDocumentStoreFactory.ConfigureDocumentStore(IDocumentStore documentStore):第38行      在\ my \ route \ Persistence.Database.Adapter \ RavenDb \ RavenDbDocumentStoreFactory.cs中的Persistence.Database.Adapter.RavenDb.RavenDbDocumentStoreFactory.Create(String ravenDbLocation,String ravenDbDatabase):第22行      at Persistence.Database.Adapter.PersistenceAdapter。&lt; .ctor&gt; b__8_0()位于\ my \ route \ Persistence.Database.Adapter \ PersistenceAdapter.cs:第53行      在\ my \ route \ Persistence.Database.Adapter \ PersistenceAdapter.cs中的Persistence.Database.Adapter.PersistenceAdapter.RegisterRavenDbUtilities():第175行      在\ my \ route \ Persistence.Database.Adapter \ PersistenceAdapter.cs中的Persistence.Database.Adapter.PersistenceAdapter.RegisterRavenLogic():第86行      在\ my \ route \ Persistence.Database.Adapter \ PersistenceAdapter.cs中的Persistence.Database.Adapter.PersistenceAdapter.Initialize():第74行      at my-Program.ConfigurePersistentAdapter(设置设置)在\ my \ route \ MessageQueueListener \ MessageQueueListenerService.cs:第153行      at my-Program.AddBootstrapperExtension()在\ my \ route \ net-stock-purchasing-service.MessageQueueListener \ MessageQueueListenerService.cs:第118行      在My-Program.Startup()的\ my \ route \ net-stock-purchasing-service.MessageQueueListener \ MessageQueueListenerService.cs:第78行“       StatusCode:ServiceUnavailable       TargetSite:{Void MoveNext()}

3 个答案:

答案 0 :(得分:4)

当RavenDB 3.5发布时,客户端软件包中出现了一些问题。

如果您从3.0.30000到3.0.30179运行RavenDB.Client,那么它应该可以正常工作。

如果您运行的是更高版本,则会遇到(在某些情况下)此异常。要解决此问题,您可以使用alternate APIstore.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);
}

这可以解决您的问题。

升级客户端软件包后遇到此问题。请注意,异常仅发生在控制台应用程序中,而不是在我的Web应用程序中。

答案 1 :(得分:1)

这解决了我的问题:

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);

答案 2 :(得分:1)

在我的情况下,结果是由于ravendb客户端库和已安装的服务器不匹配。我的应用程序运行的是最新版本的RavenDB客户端,服务器使用的是版本3.0