erikgrinaker / toydb

Distributed SQL database in Rust, written as an educational project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The MVCC anomaly_read_skew test seems to be written incorrectly.

Light-City opened this issue · comments

mvcc.rs: anomaly_read_skew function

 let t1 = mvcc.begin()?;
        let t2 = mvcc.begin()?;

        assert_eq!(t1.get(b"a")?, Some(vec![0]));
        t2.set(b"a", vec![2])?;
        t2.set(b"b", vec![2])?;
        t2.commit()?;
        assert_eq!(t1.get(b"a")?, Some(vec![0]));

The annotation explanation is:Read skew is when t1 reads a and b, but t2 modifies b in between the reads. Snapshot isolation prevents this.

At the same time, according to the explanation of this document, different read operations are performed before and after, and in the test, a was read before and after.

https://vladmihalcea.com/a-beginners-guide-to-read-and-write-skew-phenomena/

Therefore, we should instead read b last time