dongqian0763 2010-12-09 03:59
浏览 48

处理现实世界中的交易

I'm rewriting this question because it got no responses.

I'm trying to figure out the correct way to work with db transactions. Everything I see about how to do transactions is very basic, along the lines of:

  1. query "begin" to start transaction
  2. run your queries.
  3. if everything ran fine, commit transaction.

I get that, but it's error (deadlock) handling I don't get. I've heard of two options:

  1. Show the user an error and say "try again"
  2. Try again on the spot until it succeeds.

To me, telling the user to try again because of a technical issue like this seems bad - do real applications do this regularly? Is that the "oops, something went wrong" one-off errors I sometimes see? This is for a website, so users shouldn't even be aware of the database.

So I have a few questions:

  1. Which failure handling approach should I take with data involving multiple users at once?
  2. If I do the "instant retry" option, what does that entail for a complex PHP script? Restart the whole request from the top? I'm worried this will cause more problems than it solves.
  3. Is there a third option I haven't seen?
  • 写回答

3条回答 默认 最新

  • doucan957495 2011-01-28 19:54
    关注

    A deadlock during a transaction would usually indicate that you were trying to update something that someone else also updated at the same time as you. Exactly how you handle that would be specific to the operation that the user was performing.

    In some cases it wouldn't be a problem and you would retry the operation, but I would think that in most cases you would generate an error to the user since you have know way of knowing which update was the "correct" one.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度