Skip to content

Commit

Permalink
fix: AT mode queryContext error
Browse files Browse the repository at this point in the history
  • Loading branch information
576470954 authored Feb 3, 2024
1 parent 3534336 commit 9709b35
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
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,
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

0 comments on commit 9709b35

Please sign in to comment.