-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
*: remove mock.NewContext()
usage when building table meta in production code
#56348
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -43,14 +43,14 @@ import ( | |||
"github.com/pingcap/tidb/pkg/lightning/mydump" | ||||
"github.com/pingcap/tidb/pkg/lightning/verification" | ||||
"github.com/pingcap/tidb/pkg/lightning/worker" | ||||
"github.com/pingcap/tidb/pkg/meta/metabuild" | ||||
"github.com/pingcap/tidb/pkg/meta/model" | ||||
"github.com/pingcap/tidb/pkg/parser" | ||||
"github.com/pingcap/tidb/pkg/parser/ast" | ||||
_ "github.com/pingcap/tidb/pkg/planner/core" // to setup expression.EvalAstExpr. Otherwise we cannot parse the default value | ||||
"github.com/pingcap/tidb/pkg/table/tables" | ||||
"github.com/pingcap/tidb/pkg/types" | ||||
"github.com/pingcap/tidb/pkg/util/dbterror" | ||||
"github.com/pingcap/tidb/pkg/util/mock" | ||||
pdhttp "github.com/tikv/pd/client/http" | ||||
"go.uber.org/zap" | ||||
) | ||||
|
@@ -428,15 +428,15 @@ func newTableInfo(createTblSQL string, tableID int64) (*model.TableInfo, error) | |||
log.L().Error(errMsg, zap.Error(err), zap.String("sql", createTblSQL)) | ||||
return nil, errors.Trace(err) | ||||
} | ||||
sctx := mock.NewContext() | ||||
createTableStmt, ok := astNode.(*ast.CreateTableStmt) | ||||
if !ok { | ||||
return nil, errors.New("cannot transfer the parsed SQL as an CREATE TABLE statement") | ||||
} | ||||
info, err := ddl.MockTableInfo(sctx, createTableStmt, tableID) | ||||
info, err := ddl.BuildTableInfoFromAST(metabuild.NewNonStrictContext(), createTableStmt) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems tidb/lightning/pkg/importer/get_pre_info.go Line 411 in b427e33
PTAL @lance6716 |
||||
if err != nil { | ||||
return nil, errors.Trace(err) | ||||
} | ||||
info.ID = tableID | ||||
info.State = model.StatePublic | ||||
return info, nil | ||||
} | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import ( | |
"github.com/pingcap/tidb/pkg/expression" | ||
"github.com/pingcap/tidb/pkg/infoschema" | ||
"github.com/pingcap/tidb/pkg/meta/autoid" | ||
"github.com/pingcap/tidb/pkg/meta/metabuild" | ||
"github.com/pingcap/tidb/pkg/meta/model" | ||
"github.com/pingcap/tidb/pkg/parser" | ||
"github.com/pingcap/tidb/pkg/parser/ast" | ||
|
@@ -43,12 +44,13 @@ func Init() { | |
p := parser.New() | ||
tbls := make([]*model.TableInfo, 0) | ||
dbID := autoid.PerformanceSchemaDBID | ||
ctx := metabuild.NewNonStrictContext() | ||
for _, sql := range perfSchemaTables { | ||
stmt, err := p.ParseOneStmt(sql, "", "") | ||
if err != nil { | ||
panic(err) | ||
} | ||
meta, err := ddl.BuildTableInfoFromAST(stmt.(*ast.CreateTableStmt)) | ||
meta, err := ddl.BuildTableInfoFromAST(ctx, stmt.(*ast.CreateTableStmt)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
@@ -62,6 +64,7 @@ func Init() { | |
c.ID = int64(i) + 1 | ||
} | ||
meta.DBID = dbID | ||
meta.State = model.StatePublic | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the master code lost this line to set the table state to public... Though it still works well without this state, I still fix it to make the meta complete. |
||
} | ||
dbInfo := &model.DBInfo{ | ||
ID: dbID, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,33 +17,17 @@ | |
package dbutiltest | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pingcap/errors" | ||
"github.com/pingcap/tidb/pkg/ddl" | ||
"github.com/pingcap/tidb/pkg/meta/metabuild" | ||
"github.com/pingcap/tidb/pkg/meta/model" | ||
"github.com/pingcap/tidb/pkg/parser" | ||
"github.com/pingcap/tidb/pkg/parser/ast" | ||
pmodel "github.com/pingcap/tidb/pkg/parser/model" | ||
_ "github.com/pingcap/tidb/pkg/planner/core" // to setup expression.EvalAstExpr. See: https://github.com/pingcap/tidb/blob/a94cff903cd1e7f3b050db782da84273ef5592f4/planner/core/optimizer.go#L202 | ||
"github.com/pingcap/tidb/pkg/types" | ||
"github.com/pingcap/tidb/pkg/util/dbutil" | ||
) | ||
|
||
// GetTableInfo returns table information. | ||
func GetTableInfo(ctx context.Context, db dbutil.QueryExecutor, schemaName string, tableName string) (*model.TableInfo, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. used by tiflow😓 |
||
createTableSQL, err := dbutil.GetCreateTableSQL(ctx, db, schemaName, tableName) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
|
||
parser2, err := dbutil.GetParserForDB(ctx, db) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
return GetTableInfoBySQL(createTableSQL, parser2) | ||
} | ||
|
||
// GetTableInfoBySQL returns table information by given create table sql. | ||
func GetTableInfoBySQL(createTableSQL string, parser2 *parser.Parser) (table *model.TableInfo, err error) { | ||
stmt, err := parser2.ParseOneStmt(createTableSQL, "", "") | ||
|
@@ -53,7 +37,7 @@ func GetTableInfoBySQL(createTableSQL string, parser2 *parser.Parser) (table *mo | |
|
||
s, ok := stmt.(*ast.CreateTableStmt) | ||
if ok { | ||
table, err := ddl.BuildTableInfoFromAST(s) | ||
table, err := ddl.BuildTableInfoFromAST(metabuild.NewContext(), s) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like an old tool to import data to tidb. But I think no one uses it now...