System.NotSupportedException:“使用集群事务时不支持‘Taxes/353-A’的乐观并发。”在 RavenDB 中

Posted

技术标签:

【中文标题】System.NotSupportedException:“使用集群事务时不支持‘Taxes/353-A’的乐观并发。”在 RavenDB 中【英文标题】:System.NotSupportedException: 'Optimistic concurrency for 'Taxes/353-A' is not supported when using a cluster transaction.' in RavenDB 【发布时间】:2021-01-27 18:34:51 【问题描述】:

我们正在使用集群范围的事务,并且在更新文档时收到主题行中提到的错误。要更新文档,首先,我们从数据库中加载它,修改一些字段,然后使用提供的ChangeVectorId 保存它。我的理解是,提供ChangeVector 只能为该会话启用乐观并发,这是我们的意图。 这是代码sn-p:

var taxToUpdate = await session.LoadAsync<Tax>(myTax.Id, cancellationToken);
taxToUpdate.Description = "Updated description";
await session.StoreAsync(taxToUpdate , myTax.ChangeVector, myTax.Id, cancellationToken);
await session.SaveChangesAsync(cancellationToken);

堆栈跟踪显示为:

Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.ValidateClusterTransaction(SaveChangesData 导致 C:\Builds\RavenDB-Stable-5.1\51010\src\Raven.Client\Documents\Session\InMemoryDocumentSessionOperations.cs:line 883 在 Raven.Client.Documents.Session.Operations.BatchOperation.CreateRequest() 在 C:\Builds\RavenDB-Stable-5.1\51010\src\Raven.Client\Documents\Session\Operations\BatchOperation.cs:line 41 在 Raven.Client.Documents.Session.AsyncDocumentSession.d__31.MoveNext() 在 C:\Builds\RavenDB-Stable-5.1\51010\src\Raven.Client\Documents\Session\AsyncDocumentSession.cs:line 157 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 System.Runtime.CompilerServices.TaskAwaiter.GetResult()

由于在我们的应用程序上下文中必须使用ChangeVector,因此该问题的解决方案是什么?

【问题讨论】:

【参考方案1】:

不支持文档级别的乐观并发。 它使用比较交换功能进行处理。

https://ravendb.net/docs/article-page/5.1/Csharp/server/clustering/cluster-transactions#case-1-multiple-concurrent-cluster-transactions

【讨论】:

以上是关于System.NotSupportedException:“使用集群事务时不支持‘Taxes/353-A’的乐观并发。”在 RavenDB 中的主要内容,如果未能解决你的问题,请参考以下文章