EventFlow icon indicating copy to clipboard operation
EventFlow copied to clipboard

Ms SQL shoud throw OptimisticConcurrencyException on read model insert conflict

Open leotsarev opened this issue 4 years ago • 8 comments

If we got unique constraint violation on inserting read model it probably another thread already inserted read model and we need to start update again.

leotsarev avatar Jun 17 '20 18:06 leotsarev

Another option could be to implement retry directly in MsSQLReadStore, but we will lose ability to use RetryPolicies (or will really-really complicate MsSQLReadStore)

leotsarev avatar Jun 17 '20 18:06 leotsarev

If you have a 1-to-1 relationship between your read model and your aggregate, you could try the AggregateReadStoreManager which checks if the version is as expected, applies any missing events and the updates the read model.

rasmus avatar Jun 18 '20 05:06 rasmus

Thanks, that's interesting. It's +1 to this implementation (not retrying inside MsSQLReadStore). However for that to work we need read store to signal that concrete Sql exception is probably OptimisticConcurrencyException, because various generic ReadStoreManager do not know that concrete code of SqlException XXX could be retried specifically in case of INSERT. So, for me that change is net win. If you have time, could you please reword your comment to be more actionable (leotsarev, please investigate this or that, try another approach, also add fix here or there, request review from somebody, add tests...)

leotsarev avatar Jun 18 '20 08:06 leotsarev

@frankebersoll is this still relevant after you merged #768?

rasmus avatar Aug 20 '20 05:08 rasmus

I think it's still relevant. Before change + SingleAggregateReadStoreManager If two threads (A & B) will try to create read model in parallel, one of them could fail and lose change. Before change + AggregateReadStoreManager If two threads (A&B) will try to create read model in parallel, one of them could fail and lose change (say, B). Sometimes later when another update (C) to this aggregate happen, update B will be added to readmodel in correct order After change If two threads (A & B) will try to create read model in parallel, one of them could fail and signal OptimisticConcurrencyException. It will be retried.

leotsarev avatar Aug 20 '20 09:08 leotsarev

@rasmus ?

leotsarev avatar Oct 28 '20 14:10 leotsarev

Still relevant, haven't had the time to give it a go yet though

rasmus avatar Oct 28 '20 15:10 rasmus

Note: I'm not interested anymore in Eventflow because of my job change. I think that PR is still relevant.

leotsarev avatar Jun 06 '22 11:06 leotsarev

Hello there!

We hope this message finds you well. We wanted to let you know that we have noticed that there has been no activity on this pull request for the past 90 days, which makes it a stale pull request.

As a result, we will be closing this pull request within the next seven days. If you still think this pull request is necessary or relevant, please feel free to update it or leave a comment within the next seven days.

Thank you for your contributions and understanding.

Best regards, EventFlow

github-actions[bot] avatar Apr 08 '23 13:04 github-actions[bot]

Hello there! I'm a bot and I wanted to let you know that your pull request has been closed due to inactivity after being marked as stale for seven days. If you believe this was done in error, or if you still plan to work on this pull request, please don't hesitate to reopen it and let us know. We're always happy to review and merge high-quality contributions. Thank you for your interest in our project! Best regards, EventFlow

github-actions[bot] avatar Apr 16 '23 09:04 github-actions[bot]