问题上下文: 有一段代码试图在 NServiceBus 消息处理程序中向 RavenDB 添加新文档。
编码:
partial void HandleImplementation(SomeMessage message)
{
PutDataIntoCache(message.CacheKey, message.Document);
}
void PutDataIntoCache(string key, Document document)
{
using (var documentStore = new DocumentStore { Url = "http://localhost:8084" })
{
documentStore.Initialize();
using (IDocumentSession session = documentStore.OpenSession())
{
using (var tx = new TransactionScope())
{
session.Store(document, key);
session.SaveChanges();
tx.Complete();
}
}
}
}
错误
I'm getting the following error:
Raven.Abstractions.Exceptions.ConcurrencyException: A document with key: 'cache-fncwr10b' is currently created in another transaction
at Raven.Client.Connection.ServerClient.DirectBatch(IEnumerable`1 commandDatas, String operationUrl) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\ServerClient.cs:line 863
at Raven.Client.Connection.ServerClient.<>c__DisplayClass56.<Batch>b__55(String u) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\ServerClient.cs:line 837
at Raven.Client.Connection.ServerClient.TryOperation[T](Func`2 operation, String operationUrl, Boolean avoidThrowing, T& result) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\ServerClient.cs:line 222
at Raven.Client.Connection.ServerClient.ExecuteWithReplication[T](String method, Func`2 operation) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\ServerClient.cs:line 192
at Raven.Client.Connection.ServerClient.Batch(IEnumerable`1 commandDatas) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\ServerClient.cs:line 837
at Raven.Client.Document.DocumentSession.SaveChanges() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\DocumentSession.cs:line 441
at CacheWarmer.Listener.Caching.UpdateCacheEntryProcessor.PutDataIntoCache(String key, ConfgDataModel confgDataModel) in UpdateCacheEntryProcessor.cs
问题 有没有人遇到过这个?你是怎么解决的?这可能是什么原因造成的?
任何有用的意见或提示将不胜感激!