Skip to content
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

prepare statement can't receive schema update #25482

Closed
ichn-hu opened this issue Jun 16, 2021 · 17 comments
Closed

prepare statement can't receive schema update #25482

ichn-hu opened this issue Jun 16, 2021 · 17 comments
Assignees
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@ichn-hu
Copy link
Contributor

ichn-hu commented Jun 16, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

start a session, execute:

use test;
create table t (a int);
create table t_a (a int);
insert into t values (1), (2), (3);

then, using the following code to connect

package main

import (
        // "bufio"

        "fmt"
        "log"
        "os"

        // "strings"
        "time"

        _ "github.com/go-sql-driver/mysql"
        "github.com/jmoiron/sqlx"
)

const (
        DBIp      = "127.0.0.1"
        DBPort    = "4000"
        DBUser    = "root"
        DBPwd     = ""
        DBName    = "test"
        SelectSQL = "SELECT count(*) as cnt,CONNECTION_ID() as conntid FROM t where a = ?"
        a1        = "1"
)

var (
        dBDsnWithName = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=latin1&autocommit=1&parseTime=true&loc=Local&timeout=3000s&writeTimeout=1000s&readTimeout=1000s", DBUser, DBPwd, DBIp, DBPort, DBName)
)

// User for test
type User struct {
        Count  int `db:"cnt"`
        Connid int `db:"conntid"`
}

func main() {
        db, err := sqlx.Open("mysql", dBDsnWithName)
        // db, err := sql.Open("mysql", dBDsnWithName)
        if err != nil {
                log.Fatalf("error in opening database: %+v", err)
                os.Exit(1)
        }
        db.SetMaxOpenConns(8)
        db.SetMaxIdleConns(2)
        log.Println("finished database initialization...")
        var u User
        var i int
        for i < 20 {
                err = db.Get(&u, SelectSQL, a1)
                // err := db.QueryRow(SelectSQL, c1).Scan(&cnt, &cnntid)
                if err != nil {
                        log.Printf("db error: %v", err)
                }
                log.Printf("user: %v", u)
                // log.Printf("cnt: %v , connect_id: %v", cnt, cnntid)
                time.Sleep(5 * time.Second)
                i++
        }
        log.Println("finished testing...")
}

while the above code is executing, rename the 2 tables in another session

alter table rename t to t_b;
alter table rename t_a to t;

2. What did you expect to see? (Required)

No error.

3. What did you see instead (Required)

$ go run ./test_main.go
2021/06/16 16:32:48 finished database initialization...
2021/06/16 16:32:48 user: {1 13}
2021/06/16 16:32:53 user: {1 13}
2021/06/16 16:32:58 user: {1 13}
2021/06/16 16:33:03 user: {1 13}
2021/06/16 16:33:08 user: {1 13}
2021/06/16 16:33:13 db error: Error 1146: Table 'test.t' doesn't exist
2021/06/16 16:33:13 user: {1 13}
2021/06/16 16:33:18 db error: Error 1146: Table 'test.t' doesn't exist
2021/06/16 16:33:18 user: {1 13}
2021/06/16 16:33:23 db error: Error 1146: Table 'test.t' doesn't exist
2021/06/16 16:33:23 user: {1 13}
2021/06/16 16:33:28 db error: Error 1146: Table 'test.t' doesn't exist
2021/06/16 16:33:28 user: {1 13}

4. What is your TiDB version? (Required)

select tidb_version();
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    15
Current database: las_tc

+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                                             |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v5.1.0-alpha-6-gd5d433e49
Edition: Community
Git Commit Hash: d5d433e49dd20420f9165005c92b3e1592ab8c6b
Git Branch: fix-prepare
UTC Build Time: 2021-06-15 11:23:23
GoVersion: go1.16
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
@xhebox
Copy link
Contributor

xhebox commented Jun 16, 2021

Can not reproduce. My output:

2021/06/16 20:12:37 finished database initialization...
2021/06/16 20:12:37 user: {1 7}
2021/06/16 20:12:42 user: {1 7}
alter table t rename to t_b; alter table t_a rename to t;
2021/06/16 20:12:47 user: {0 7}
2021/06/16 20:12:52 user: {0 7}
2021/06/16 20:12:57 user: {0 7}
2021/06/16 20:13:02 user: {0 7}
2021/06/16 20:13:07 user: {0 7}
2021/06/16 20:13:12 user: {0 7}
2021/06/16 20:13:17 user: {0 7}
2021/06/16 20:13:22 user: {0 7}
2021/06/16 20:13:27 user: {0 7}
2021/06/16 20:13:32 user: {0 7}

Don't know why though, the problem of prepare does exist.

@ichn-hu
Copy link
Contributor Author

ichn-hu commented Jun 17, 2021

@xhebox to reproduce, you show run the two rename ddl separately, run the first rename, wait until the error occurred, and then run the second. it is expected that the error will disappear after the second ddl, but it doesn't.

@ichn-hu
Copy link
Contributor Author

ichn-hu commented Jun 17, 2021

@xhebox and I found it can be reproduced on v4.0.11, but not master.

@ichn-hu
Copy link
Contributor Author

ichn-hu commented Jun 17, 2021

and on d5d433e49dd20420f9165005c92b3e1592ab8c6b it can be reproduced.

@ichn-hu
Copy link
Contributor Author

ichn-hu commented Jun 17, 2021

and on d5d433e49dd20420f9165005c92b3e1592ab8c6b it can be reproduced.

sorry, this is my local development commit, the merge-base between it and master is

$ git merge-base HEAD d5d433e49dd20420f9165005c92b3e1592ab8c6b                                                                                          1 ↵
19e100c27a37601d674df625034ebddb5196a299

and it can be reproduced on the merge-base.

@ichn-hu
Copy link
Contributor Author

ichn-hu commented Jun 17, 2021

after bisect, I found it is fixed in bfdad7c, i.e. #24820

@xhebox
Copy link
Contributor

xhebox commented Jun 17, 2021

Why it can be reproduced on v4.0.11? I thought the problem is introduced by me. But I never cherry-pick them back to 4.0.

@ichn-hu
Copy link
Contributor Author

ichn-hu commented Jun 17, 2021

I think the problem exists already before your change

@ichn-hu
Copy link
Contributor Author

ichn-hu commented Jun 17, 2021

@ichn-hu
Copy link
Contributor Author

ichn-hu commented Jun 17, 2021

do you have any suggestions for the fix on v4.0.11?

@xhebox
Copy link
Contributor

xhebox commented Jun 17, 2021

OK, I remembered the case. Here is the issue, #24233. And it is not cherry-picked because they worry about the stability of these 3 PRs. These PRs are developed as some fixes for stale read feature.

By 3 PRs, I finally get most operations of getting infoschema consistent, and the problem may come from some inconsistent behaviors fixed by PRs. Maybe cherry-icking all 3 PRs will fix the problem...

@ichn-hu
Copy link
Contributor Author

ichn-hu commented Jun 17, 2021

@xhebox would you like to take over this issue?

@xhebox
Copy link
Contributor

xhebox commented Jun 17, 2021

Is it urgent? I don't think I have time today or tomorrow.

@ichn-hu
Copy link
Contributor Author

ichn-hu commented Jun 17, 2021 via email

@ichn-hu
Copy link
Contributor Author

ichn-hu commented Jun 17, 2021

/assign @xhebox

@wshwsh12 wshwsh12 added sig/sql-infra SIG: SQL Infra and removed sig/execution SIG execution labels Jun 24, 2021
@xiongjiwei
Copy link
Contributor

have been fixed in 5.1

@ti-srebot
Copy link
Contributor

Please edit this comment or add a new comment to complete the following information

Not a bug

  1. Remove the 'type/bug' label
  2. Add notes to indicate why it is not a bug

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: #20100

1. Root Cause Analysis (RCA) (optional)

2. Symptom (optional)

3. All Trigger Conditions (optional)

4. Workaround (optional)

5. Affected versions

6. Fixed versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants