-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't allow reading a snapshot with the timestamp greater than the current max timestamp #25680
Comments
For stale read, which required There is a pitfall that if TiDB forgets to set the |
may tikv/tikv#10443 |
@NingLin-P @nolouch @sticnarf It seems package main
import (
"bytes"
"context"
"database/sql"
"log"
"net/http"
"time"
_ "github.com/go-sql-driver/mysql"
)
const (
dsn = "root:@tcp(172.16.4.180:31126)/test"
api = "http://172.16.4.180:30906/fail/"
)
func panicOnErr(err error) {
if err != nil {
panic(err)
}
}
func enablePauseBeforeCommit() {
req, err := http.NewRequest(http.MethodPut, api+"github.com/pingcap/tidb/store/tikv/beforeCommit", bytes.NewBufferString("pause"))
panicOnErr(err)
_, err = http.DefaultClient.Do(req)
panicOnErr(err)
}
func disablePauseBeforeCommit() {
req, err := http.NewRequest(http.MethodDelete, api+"github.com/pingcap/tidb/store/tikv/beforeCommit", nil)
panicOnErr(err)
_, err = http.DefaultClient.Do(req)
panicOnErr(err)
}
func main() {
disablePauseBeforeCommit()
ctx := context.Background()
log.Printf("init %s", dsn)
db, err := sql.Open("mysql", dsn)
panicOnErr(err)
_, err = db.Exec("drop table if exists t")
panicOnErr(err)
_, err = db.Exec("create table t (a int, b int, primary key (a))")
panicOnErr(err)
_, err = db.Exec("insert into t values (1, 10), (2, 20), (3, 30)")
panicOnErr(err)
c1, err := db.Conn(ctx)
panicOnErr(err)
c2, err := db.Conn(ctx)
panicOnErr(err)
_, err = c1.ExecContext(ctx, "set @@tidb_enable_async_commit = 0, @@tidb_enable_1pc = 0")
panicOnErr(err)
log.Printf("start tx1")
_, err = c1.ExecContext(ctx, "begin")
panicOnErr(err)
_, err = c1.ExecContext(ctx, "delete from t where a = 1")
panicOnErr(err)
_, err = c1.ExecContext(ctx, "insert into t values (1, 11)")
panicOnErr(err)
log.Printf("enable failpoint")
enablePauseBeforeCommit()
commitDone := make(chan struct{})
go func() {
defer close(commitDone)
log.Printf("commit tx1")
_, err = c1.ExecContext(ctx, "commit")
panicOnErr(err)
log.Printf("tx1 committed")
}()
time.Sleep(time.Second)
log.Printf("start tx2")
_, err = c2.ExecContext(ctx, "start transaction read only as of timestamp date_add(now(), interval 5 second)")
panicOnErr(err)
stmt, err := c2.PrepareContext(ctx, "select sum(a) from t where a < ?")
panicOnErr(err)
_, err = stmt.Exec(3)
panicOnErr(err)
log.Printf("disable failpoint")
disablePauseBeforeCommit()
log.Printf("rollback tx2")
_, err = c2.ExecContext(ctx, "rollback")
panicOnErr(err)
log.Printf("tx2 rollbacked")
<-commitDone
log.Printf("done")
} and here is the log.
|
Please edit this comment or add a new comment to complete the following informationNot a bug
Duplicate bug
BugNote: Make Sure that 'component', and 'severity' labels are added 1. Root Cause Analysis (RCA) (optional)2. Symptom (optional)3. All Trigger Conditions (optional)4. Workaround (optional)5. Affected versions6. Fixed versions |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
TiDB can read data with a user-defined timestamp(using
tidb_snapshot
or stale-read) which may be greater than the current max timestamp in PD. It can update the max_ts in TiKV and the async-commit transaction may commit data with the version which is greater than the next timestamp in PD, so the following transactions can't read it which means the transaction isolation is broken.2. What did you expect to see? (Required)
TiDB doesn't allow setting snapshot with the version which is greater than the current max version.
3. What did you see instead (Required)
4. What is your TiDB version? (Required)
v5.0.0-v5.0.2
The text was updated successfully, but these errors were encountered: