From 6b0b6ff8f8acff721cb0d1b6ae302913a910a277 Mon Sep 17 00:00:00 2001 From: a631807682 <631807682@qq.com> Date: Sun, 14 Aug 2022 21:56:52 +0800 Subject: [PATCH] chore[ci skip]: improve code comments --- prepare_stmt.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/prepare_stmt.go b/prepare_stmt.go index 456204b8..3934bb97 100644 --- a/prepare_stmt.go +++ b/prepare_stmt.go @@ -79,8 +79,9 @@ func (db *PreparedStmtDB) prepare(ctx context.Context, conn ConnPool, isTransact // prepare completed defer close(cacheStmt.prepared) - // Reason why cannot lock conn.PrepareContext (suppose the maxopen is 1). - // 1. g1 begin tx, now `db.ConnPool` db.numOpen == 1 + // Reason why cannot lock conn.PrepareContext + // suppose the maxopen is 1, g1 is creating record and g2 is querying record. + // 1. g1 begin tx, g1 is requeued because of waiting for the system call, now `db.ConnPool` db.numOpen == 1. // 2. g2 select lock `conn.PrepareContext(ctx, query)`, now db.numOpen == db.maxOpen , wait for release. // 3. g1 tx exec insert, wait for unlock `conn.PrepareContext(ctx, query)` to finish tx and release. stmt, err := conn.PrepareContext(ctx, query)