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

fix issue 609,610,611 #612

Merged
merged 3 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/datasource/sql/conn_at.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (c *ATConn) QueryContext(ctx context.Context, query string, args []driver.N
Query: query,
NamedValues: args,
Conn: c.targetConn,
DBName: c.dbName,
funky-eyes marked this conversation as resolved.
Show resolved Hide resolved
IsSupportsSavepoints: true,
IsAutoCommit: c.GetAutoCommit(),
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/datasource/sql/datasource/base/meta_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ func (c *BaseTableMetaCache) GetTableMeta(ctx context.Context, dbName, tableName
c.lock.Lock()
defer c.lock.Unlock()

defer conn.Close()

v, ok := c.cache[tableName]
if !ok {
meta, err := c.trigger.LoadOne(ctx, dbName, tableName, conn)
Expand Down
12 changes: 6 additions & 6 deletions pkg/datasource/sql/exec/at/select_for_update_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,6 @@ func (s *selectForUpdateExecutor) doExecContext(ctx context.Context, f exec.Call
return nil, fmt.Errorf("not support savepoint. please check your db version")
}

// execute business SQL, try to get local lock
result, err = f(ctx, s.execContext.Query, s.execContext.NamedValues)
if err != nil {
return nil, err
}

// query primary key values
var lockKey string
_, err = s.exec(ctx, s.selectPKSQL, s.execContext.NamedValues, func(rows driver.Rows) {
Expand All @@ -194,6 +188,12 @@ func (s *selectForUpdateExecutor) doExecContext(ctx context.Context, f exec.Call
return nil, nil
}

// execute business SQL, try to get local lock
result, err = f(ctx, s.execContext.Query, s.execContext.NamedValues)
if err != nil {
return nil, err
}

// check global lock
lockable, err := datasource.GetDataSourceManager(branch.BranchTypeAT).LockQuery(ctx, rm.LockQueryParam{
Xid: s.execContext.TxCtx.XID,
Expand Down
Loading