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

create index concurrently lead to block #18456

Closed
GMHDBJD opened this issue Jul 9, 2020 · 2 comments · Fixed by #18468
Closed

create index concurrently lead to block #18456

GMHDBJD opened this issue Jul 9, 2020 · 2 comments · Fixed by #18468
Labels
sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@GMHDBJD
Copy link
Contributor

GMHDBJD commented Jul 9, 2020

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

package main

import (
	"database/sql"
	"fmt"
	"os"
	"sync"
	"time"

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

var (
	cases = []string{
		"drop database if exists %s",
		"create database if not exists %s",
		"create table %s.t (id int)",
		"alter table %s.t add column col int", // no need, but will increase the probability of reproduction
		"alter table %s.t add index idx(id)",
	}
	wg sync.WaitGroup
)

func runSQL(dbName string, db *sql.DB) {
	defer wg.Done()

	for _, sqlFormat := range cases {
		sql := fmt.Sprintf(sqlFormat, dbName)
		fmt.Printf("run sql: %s\n", sql)
		_, err := db.Exec(sql)
		if err != nil {
			fmt.Printf("%v\n", err)
			os.Exit(2)
		}
	}
}

func main() {
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/",
		"root", "", "127.0.0.1", 4000)
	db, err := sql.Open("mysql", dsn)
	if err != nil {
		fmt.Printf("fail to open db")
		os.Exit(2)
	}
	if err := db.Ping(); err != nil {
		fmt.Printf("fail to ping db")
		os.Exit(2)
	}

	for i := 1; i <= 10; i++ {
		fmt.Printf("round %d\n", i)
		wg.Add(2)
		go runSQL("test_a", db)
		go runSQL("test_b", db)
		wg.Wait()
		time.Sleep(1 * time.Second)
	}
}

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

success to execute alter table %s.t add index idx(id)

3. What did you see instead (Required)

the create index statement block

4. Affected version (Required)

v4.0.0-beta.2-737-g5f983b860

5. Root Cause Analysis

tidb log
debug-log.txt

@GMHDBJD GMHDBJD added the type/bug The issue is confirmed as a bug. label Jul 9, 2020
@Little-Wallace
Copy link
Contributor

/label component/ddl

@ti-srebot ti-srebot added the sig/sql-infra SIG: SQL Infra label Jul 9, 2020
@zimulala
Copy link
Contributor

zimulala commented Jul 9, 2020

@GMHDBJD
I checked the log file of debug-log.txt, this test is used "unistore". I tried it. Using "unistore" in the background does reproduce the problem, but using "tikv" does not. We will deal with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants