OrleansContrib / Orleans.Providers.MongoDB

A MongoDb implementation of the Orleans Providers: Membership, Storage and Reminders.
MIT License
100 stars 43 forks source link

Unique constraint violations are not propagated #124

Closed tomhreb closed 1 year ago

tomhreb commented 1 year ago

Hi,

if I define unique constraint and that constraint is violated, the exception is not propagated to the actor.

The issue is probably in the exception handling code - https://github.com/OrleansContrib/Orleans.Providers.MongoDB/blob/79f3754c0762c6b61cc00361d820acb9863da80b/Orleans.Providers.MongoDB/StorageProviders/MongoGrainStorageCollection.cs#L94

Steps to repro: Define a unique constraint on a property of your actor state model Create multiple actors & save the state -> duplicate actor does not receive any exception for WriteStateAsync()

I'll investigate further and possibly create a fix PR.

Tomas

SebastianStehle commented 1 year ago

What is a unique constraint in Orleans? AFAIK storages are just key-value stores

tomhreb commented 1 year ago

There's no such thing as unique constraint in Orleans, I meant MongoDB

{
    "v" : 2,
    "key" : {
        "_doc.Entity.Id" : 1
    },
    "name" : "_doc.Entity.Id_1",
    "unique" : true
}
SebastianStehle commented 1 year ago

The exception is used to detect concurrent updates. If you want to have your behavior, you have to change the exception handling so that it only handles unique constraint exceptions on the _id index. But you should provide a PR for that. Everything works as intended