talent-plan / tinysql

A course to build the SQL layer of a distributed database.
Apache License 2.0
1.7k stars 519 forks source link

Fix `lock_test.go/TestLockTTL` #122

Open czt1999 opened 2 years ago

czt1999 commented 2 years ago

In lock_test.go, settings of lock TTL are shrunk together to speed up tests:

func init() {
    // Speed up tests.
    defaultLockTTL = 3
    maxLockTTL = 120
    ttlFactor = 6
    oracleUpdateInterval = 2
}

However, the remaining code still applies millisecond while computing elapsed time (ex.2pc.go/txnLockTTL), which will add a relatively large bias on the basic formula ttl = ttlFactor * sqrt(sizeInMiB).

In addition, ttlEquals ignores case that x < y, where float(x - y) will result in a wrong answer given x and y of uint type.