.NET SDK 3.4.1 - increment counters

Hi ,
We have a document storing 3 counters and we are using the following code.
In some circumstances (heavy load) the counters are not updated.
How can we manage concurrency ?

await collection.MutateInAsync(segmentHistoryId, builder =>
builder
.Increment(“added”, (ulong)1)
.Increment(“change”, (ulong)1)
.Increment(“current”, (ulong)1)
);

Thank you

In some circumstances (heavy load) the counters are not updated.

It would be necessary to know what circumstances are resulting in the counters not being updated to propose a solution to avoid it. MutateIn operations are atomic and should not result in the counters not being updated. If the document was read, then the MutateIn increment operation was applied, then the now-updated document was overwritten with an upsert using the out-of-date document that was read - that would give the appearance of the counters not being updated. To avoid that, use replace (with the cas from the earlier read). replace() with an out-of-date case will fail, and then the document can be re-read and replaced.

  • Mike

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.