Skip to content

Commit 9709b35

Browse files
authored
fix: AT mode queryContext error
1 parent 3534336 commit 9709b35

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

pkg/datasource/sql/conn_at.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func (c *ATConn) QueryContext(ctx context.Context, query string, args []driver.N
6262
Query: query,
6363
NamedValues: args,
6464
Conn: c.targetConn,
65+
DBName: c.dbName,
6566
IsSupportsSavepoints: true,
6667
IsAutoCommit: c.GetAutoCommit(),
6768
}

pkg/datasource/sql/datasource/base/meta_cache.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ func (c *BaseTableMetaCache) GetTableMeta(ctx context.Context, dbName, tableName
138138
c.lock.Lock()
139139
defer c.lock.Unlock()
140140

141+
defer conn.Close()
142+
141143
v, ok := c.cache[tableName]
142144
if !ok {
143145
meta, err := c.trigger.LoadOne(ctx, dbName, tableName, conn)

pkg/datasource/sql/exec/at/select_for_update_executor.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,6 @@ func (s *selectForUpdateExecutor) doExecContext(ctx context.Context, f exec.Call
174174
return nil, fmt.Errorf("not support savepoint. please check your db version")
175175
}
176176

177-
// execute business SQL, try to get local lock
178-
result, err = f(ctx, s.execContext.Query, s.execContext.NamedValues)
179-
if err != nil {
180-
return nil, err
181-
}
182-
183177
// query primary key values
184178
var lockKey string
185179
_, err = s.exec(ctx, s.selectPKSQL, s.execContext.NamedValues, func(rows driver.Rows) {
@@ -194,6 +188,12 @@ func (s *selectForUpdateExecutor) doExecContext(ctx context.Context, f exec.Call
194188
return nil, nil
195189
}
196190

191+
// execute business SQL, try to get local lock
192+
result, err = f(ctx, s.execContext.Query, s.execContext.NamedValues)
193+
if err != nil {
194+
return nil, err
195+
}
196+
197197
// check global lock
198198
lockable, err := datasource.GetDataSourceManager(branch.BranchTypeAT).LockQuery(ctx, rm.LockQueryParam{
199199
Xid: s.execContext.TxCtx.XID,

0 commit comments

Comments
 (0)