当我们已经有在线订购交易时,我们还需要记录级别锁定吗? (演唱会门票或机票预订)

发布于 2024-08-30 08:10:03 字数 314 浏览 3 评论 0原文

对于在线订购音乐会座位或机票,我们是否需要记录级别锁定或交易是否足够好?

对于演唱会门票(比如20B号座位),或者机票(即使超额预订,限制也是210张),我认为网站在显示购票屏幕时无法锁定任何记录或开始交易。

但是当用户点击“确认购买”后,服务器应该开始一个交易,购买席位号20B,并尝试Commit。

如果另一个用户在之前的交易中已经购买了Seat 20B,那么当前交易会失败的是“Commit”部分吗?

那么...我们不需要记录级锁定?事务是否总是序列化(一个接一个),这就是为什么我们可以确定不存在“竞争条件”?那么什么情况下需要记录级锁定呢?

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.

But after the user clicks "Confirm Purchase", then the server should Begin a Transaction, Purchase Seat Number 20B, and try to Commit.

If another user already bought Seat 20B in a previous transaction, then it is the "Commit" part that the current transaction will fail?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请叫√我孤独 2024-09-06 08:10:03

在插入行之前,您可以检查具有相同 SeatId 的条目存在的位置。如果存在则回滚,否则插入行并提交。我什至不自信,我认为如果服务非常繁忙,您可能需要在开始插入操作之前锁定。

然而还有一个令人兴奋的第二种选择

您维护 showIdseatId
用这两个做一个索引。并在此索引上创建唯一的约束。
现在开始使用任何锁定的事务。
如果存在重复。由于独特的约束,它显然会失败。并且提交将会失败。

尼尔

Before Inserting the Row You might Check where entries with same SeatId exists. 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.

However There Is a Exciting Second Option.

You maintain a showId and seatId
make an index with this two. 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文