V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
helloworld12
V2EX  ›  问与答

事务的理解

  •  
  •   helloworld12 · 2018-05-21 11:39:26 +08:00 · 1237 次点击
    这是一个创建于 2179 天前的主题,其中的信息可能已经有所发展或是发生改变。

    下面这条要怎么理解:

    • 隔离性 (Isolation):一个事务的执行不能被其他事务干扰。

    假设有一个事务是: A 账号向 B 账号汇钱

    然后另一个事务是: A 账号向 C 账号汇钱

    但是 A 的钱只够给一个人汇款, 这样,不是相互干扰了?

    4 条回复    2018-05-21 13:47:06 +08:00
    hubqin
        1
    hubqin  
       2018-05-21 12:52:15 +08:00
    看事务的原子性,并不干扰,这里`A 的余额减少,B 的余额增加`为一个`原子`,要么整个成功,要么整个失败滚回。A 向 C 转账,余额不足,这个事务滚回不进行任何操作。
    MiffyLiye
        2
    MiffyLiye  
       2018-05-21 13:30:42 +08:00
    "Isolation in the sense of ACID means that concurrently executing transactions are isolated from each other: they cannot step on each other ’ s toes. The classic database textbooks formalize isolation as serializability, which means that each transaction can pretend that it is the only transaction running on the entire database. "
    当然现实世界大部分数据库默认的隔离级别并不保证可序列化。
    f2f2f
        3
    f2f2f  
       2018-05-21 13:32:08 +08:00
    所以事务有优先级啊,也有加锁啊。
    helloworld12
        4
    helloworld12  
    OP
       2018-05-21 13:47:06 +08:00
    @f2f2f 加锁了, 不就意味着干扰了?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1138 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:47 · PVG 06:47 · LAX 15:47 · JFK 18:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.