开发者

reading from parallel MYSQL (.NEt connector) transactions

开发者 https://www.devze.com 2023-03-08 06:40 出处:网络
I came across a very problematic issue. I\'m developing a system of on开发者_开发问答line ordering (events that occur in the real world). user is ordering an event in my site (implementation is by a .

I came across a very problematic issue. I'm developing a system of on开发者_开发问答line ordering (events that occur in the real world). user is ordering an event in my site (implementation is by a .NET web Service that writes to a MYSQL DB). the 2 relevant tables are: EVENTS and EVENTonFIELD (FIELD is the resource that the user is ordering). (user can order a single or several resources)

My problem is - preventing ordering the same resource for the same time (possibly by a parallel call to my W.S). the implementation is a MYSQL .NET connector (in C#) transaction that includes the insert to EVENTS and EVENTonFIELD (among the other logic).

I came into a situation in which I have transaction A and transaction B (both identical: the same user X, resource Y, and time Z).

Transaction A is performed (after I validated that the resource is available). during this time (tn A is not committed yet), Transaction B is performed (when I validate if the resource is available, I see it is available since tn A is not committed yet). then - A is committed, B is committed and:

I have a double event for this user..

I can't use primary key here since in some cases I allow double resource ordering. Any ideas how to prevent such cases?

the only thing I thought of is during transaction B, somehow reading also parallel transactions (A) and checking if there's a collision.. is this possible?

Thanks!!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号