Arash
Arash

Reputation: 4260

System.NotSupportedException: 'Optimistic concurrency for 'Taxes/353-A' is not supported when using a cluster transaction.' in RavenDB

We are using cluster-wide transactions and we get the error mentioned in the subject line when updating a document. To update the document, first, we load it from the database, modify some fields and then have it saved using the provided ChangeVector and the Id. My understanding is that supplying ChangeVector enables optimistic concurrency for that session only which is our intention. Here is the code snippet:

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

The stack trace reads as:

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

What is the solution for this problem as using ChangeVector is a must in our application's context?

Upvotes: 3

Views: 74

Answers (1)

Grisha Kotler
Grisha Kotler

Reputation: 457

Optimistic concurrency at the document level isn't supported. It is handled using the compare exchange feature.

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

Upvotes: 4

Related Questions