@@ -18,9 +18,11 @@ package smartconnpool
1818
1919import (
2020 "context"
21+ "math/rand"
2122 "sync"
2223
2324 "vitess.io/vitess/go/list"
25+ "vitess.io/vitess/go/vt/log"
2426)
2527
2628// waiter represents a client waiting for a connection in the waitlist
@@ -57,10 +59,14 @@ func (wl *waitlist[C]) waitForConn(ctx context.Context, setting *Setting) (*Pool
5759 wl .mu .Lock ()
5860 // add ourselves as a waiter at the end of the waitlist
5961 wl .list .PushBackValue (elem )
62+ log .Errorf ("========================== THIS IS WHAT THE WAITLIST LOOKS LIKE BEFORE I START WAITING:\n %+v" , wl )
6063 wl .mu .Unlock ()
6164
6265 // block on our waiter's semaphore until somebody can hand over a connection to us
66+ i := rand .Int ()
67+ log .Errorf ("======================= %d: I'M WAITING" , i )
6368 elem .Value .sema .wait ()
69+ log .Error ("======================== %d: I'M DONE WAITING" , i )
6470
6571 // we're awake -- the conn in our waiter contains the connection that was handed
6672 // over to us, or nothing if we've been waken up forcefully. save the conn before
@@ -108,6 +114,7 @@ func (wl *waitlist[C]) expire(force bool) {
108114func (wl * waitlist [D ]) tryReturnConn (conn * Pooled [D ]) bool {
109115 // fast path: if there's nobody waiting there's nothing to do
110116 if wl .list .Len () == 0 {
117+ log .Error ("======================= WE HIT THE FAST PATH, WE'RE RETURNING" )
111118 return false
112119 }
113120 // split the slow path into a separate function to enable inlining
@@ -146,9 +153,12 @@ func (wl *waitlist[D]) tryReturnConnSlow(conn *Pooled[D]) bool {
146153 // maybe there isn't anybody to hand over the connection to, because we've
147154 // raced with another client returning another connection
148155 if target == nil {
156+ log .Error ("====================== target was nil, we couldn't find someone to give the connection to" )
149157 return false
150158 }
151159
160+ log .Errorf ("===================== WE'VE FOUND A TARGET: %+v" , target )
161+
152162 // if we have a target to return the connection to, simply write the connection
153163 // into the waiter and signal their semaphore. they'll wake up to pick up the
154164 // connection.
0 commit comments