diff --git a/go/pools/smartconnpool/connection.go b/go/pools/smartconnpool/connection.go index e130018d7a0..cdb5720596e 100644 --- a/go/pools/smartconnpool/connection.go +++ b/go/pools/smartconnpool/connection.go @@ -20,8 +20,6 @@ import ( "context" "sync/atomic" "time" - - "vitess.io/vitess/go/vt/log" ) type Connection interface { @@ -47,7 +45,6 @@ func (dbc *Pooled[C]) Close() { } func (dbc *Pooled[C]) Recycle() { - log.Errorf("========================== IM RECYCLING THE CONNECTION\nconn:\n%+v\npool:\n%+v", dbc, dbc.pool) switch { case dbc.pool == nil: dbc.Conn.Close() diff --git a/go/pools/smartconnpool/pool.go b/go/pools/smartconnpool/pool.go index 6c7eda39bc4..adad5f790b2 100644 --- a/go/pools/smartconnpool/pool.go +++ b/go/pools/smartconnpool/pool.go @@ -397,7 +397,9 @@ func (pool *ConnPool[C]) put(conn *Pooled[C]) { } } + log.Error("========================== I'M TRYING TO RETURN A CONNECTION HERE") if !pool.wait.tryReturnConn(conn) { + log.Error("============================= tryReturnConn returned false, we're in that branch") connSetting := conn.Conn.Setting() if connSetting == nil { pool.clean.Push(conn) diff --git a/go/pools/smartconnpool/waitlist.go b/go/pools/smartconnpool/waitlist.go index f16215f4b14..9ba2f3aedfe 100644 --- a/go/pools/smartconnpool/waitlist.go +++ b/go/pools/smartconnpool/waitlist.go @@ -18,9 +18,11 @@ package smartconnpool import ( "context" + "math/rand" "sync" "vitess.io/vitess/go/list" + "vitess.io/vitess/go/vt/log" ) // 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 wl.mu.Lock() // add ourselves as a waiter at the end of the waitlist wl.list.PushBackValue(elem) + log.Errorf("========================== THIS IS WHAT THE WAITLIST LOOKS LIKE BEFORE I START WAITING:\n%+v", wl) wl.mu.Unlock() // block on our waiter's semaphore until somebody can hand over a connection to us + i := rand.Int() + log.Errorf("======================= %d: I'M WAITING", i) elem.Value.sema.wait() + log.Error("======================== %d: I'M DONE WAITING", i) // we're awake -- the conn in our waiter contains the connection that was handed // 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) { func (wl *waitlist[D]) tryReturnConn(conn *Pooled[D]) bool { // fast path: if there's nobody waiting there's nothing to do if wl.list.Len() == 0 { + log.Error("======================= WE HIT THE FAST PATH, WE'RE RETURNING") return false } // split the slow path into a separate function to enable inlining @@ -146,9 +153,12 @@ func (wl *waitlist[D]) tryReturnConnSlow(conn *Pooled[D]) bool { // maybe there isn't anybody to hand over the connection to, because we've // raced with another client returning another connection if target == nil { + log.Error("====================== target was nil, we couldn't find someone to give the connection to") return false } + log.Errorf("===================== WE'VE FOUND A TARGET: %+v", target) + // if we have a target to return the connection to, simply write the connection // into the waiter and signal their semaphore. they'll wake up to pick up the // connection.