简体   繁体   English

当我们已经有了用于在线订购的交易时,是否需要记录级别锁定? (演唱会门票或飞机票的)

[英]Do we need Record Level Locking when we already have Transaction for online ordering? (of concert ticket or airline booking)

For online ordering of concert seats or airline tickets, do we need Record Level Locking or is Transaction good enough? 要在线订购音乐会座位或机票,我们需要记录级别锁定还是交易足够好?

For concert ticket (say, seat Number 20B), or airline ticket (even with overbooking, the limit is 210, for example), I think the website cannot lock any record or begin transaction when showing the ticket purchase screen. 对于音乐会门票(例如,座位号20B)或飞机票(即使预订过多,例如,限制为210),我认为网站在显示门票购买屏幕时无法锁定任何记录或开始交易。

But after the user clicks "Confirm Purchase", then the server should Begin a Transaction, Purchase Seat Number 20B, and try to Commit. 但是,在用户单击“确认购买”之后,服务器应开始交易,购买席位20B,然后尝试提交。

If another user already bought Seat 20B in a previous transaction, then it is the "Commit" part that the current transaction will fail? 如果另一个用户在先前的交易中已经购买了Seat 20B,那么当前交易失败是“提交”部分吗?

So... we don't need Record Level Locking? 所以...我们不需要记录级别锁定吗? Do Transactions always go serialized (one after another), so that's why we can know for sure there is no "race condition"? 事务是否总是序列化(一个接一个),所以这就是为什么我们可以确定不存在“竞争条件”的原因? In what situation is Record Level Locking needed then? 那么在什么情况下需要记录级别锁定?

Before Inserting the Row You might Check where entries with same SeatId exists. 在插入行之前,您可以检查具有相同SeatId的条目的位置。 If exists roll it back otherwise Insert the Row and Commit. 如果存在,则将其回滚,否则插入“行并提交”。 I am not even Cofident and I think If the service is quite busy you probabbly need locking before starting the insert operation. 我什至没有Cofident,我认为如果服务非常繁忙,则可能需要在开始插入操作之前锁定。

However There Is a Exciting Second Option . 但是, 还有第二种选择

You maintain a showId and seatId make an index with this two. 您维护一个showIdseatId使用这两个进行索引。 and create an unique Constraint on this Index. 并在此索引上创建唯一约束。 Now Start the Transaction with any locking. 现在以任何锁定方式启动事务。 if duplication exists. 如果存在重复。 it will obviously fail due to unique constraint. 由于独特的约束,它显然将失败。 and commit will be unsuccessful. 并且提交将失败。

Neel 尼尔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL:为什么我们需要进行机票预订交易? - SQL: why we need transaction for ticket booking? 我们真的需要在ThreadLocal中设置Transaction吗? - Do we really need to set the Transaction in ThreadLocal? 如果我们在数据库级别进行事务管理而不是将事务管理放在我们的代码中 - if we have transaction management at database level than why we put the transaction management in our code 我们如何使用jdbi强制Dropwizard中的资源(控制器)级别事务? - How do we force Resource(controller) level transaction in Dropwizard with jdbi? 我们需要多次还是仅一次启动未结交易? - Do we need open transaction multiple times or just once in start? 为什么我们需要setRollbackOnly,而不仅仅是回滚事务? - Why do we need setRollbackOnly, not just rollback the transaction? 与休眠一起使用时,是否每次都要使用事务? - Do we have to use transaction every time while using with hibernate? 高效的交易,记录锁定 - Efficient transaction, record locking 如果调用方函数中有@Transaction,被调用函数是否仍在事务中? - Will called function be still in transaction if we have a @Transaction in caller function? 如果正确定义了ACID属性,为什么我们拥有/接受不同的交易级别? - If ACID properties are well defined why do we have/accept different transaction levels?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM