helloworld12
V2EX  ›  问与答

事务的理解

  •  
  •   helloworld12 · May 21, 2018 · 1749 views
    This topic created in 2942 days ago, the information mentioned may be changed or developed.

    下面这条要怎么理解:

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

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

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

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

    4 replies    2018-05-21 13:47:06 +08:00
    hubqin
        1
    hubqin  
       May 21, 2018
    看事务的原子性,并不干扰,这里`A 的余额减少,B 的余额增加`为一个`原子`,要么整个成功,要么整个失败滚回。A 向 C 转账,余额不足,这个事务滚回不进行任何操作。
    MiffyLiye
        2
    MiffyLiye  
       May 21, 2018
    "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  
       May 21, 2018
    所以事务有优先级啊,也有加锁啊。
    helloworld12
        4
    helloworld12  
    OP
       May 21, 2018
    @f2f2f 加锁了, 不就意味着干扰了?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3129 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 13:10 · PVG 21:10 · LAX 06:10 · JFK 09:10
    ♥ Do have faith in what you're doing.