From 0b13e3e2a91f248fb4220623fc0d3d873929cfa2 Mon Sep 17 00:00:00 2001
From: Garet Halliday <me@garet.holiday>
Date: Fri, 15 Sep 2023 23:31:00 -0500
Subject: [PATCH] some debug prints

---
 lib/gat/modes/digitalocean_discovery/config.go |  8 ++++----
 lib/gat/pool/pool.go                           | 11 ++++++++---
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/lib/gat/modes/digitalocean_discovery/config.go b/lib/gat/modes/digitalocean_discovery/config.go
index e24ddb86..f09a0472 100644
--- a/lib/gat/modes/digitalocean_discovery/config.go
+++ b/lib/gat/modes/digitalocean_discovery/config.go
@@ -134,7 +134,7 @@ func (T *Config) ListenAndServe() error {
 					addr = net.JoinHostPort(cluster.Connection.Host, strconv.Itoa(cluster.Connection.Port))
 				}
 
-				p.AddRecipe("do", recipe.NewRecipe(recipe.Options{
+				p.AddRecipe(cluster.Name, recipe.NewRecipe(recipe.Options{
 					Dialer: dialer.Net{
 						Network:       "tcp",
 						Address:       addr,
@@ -163,7 +163,7 @@ func (T *Config) ListenAndServe() error {
 							replicaAddr = net.JoinHostPort(replica.Connection.Host, strconv.Itoa(replica.Connection.Port))
 						}
 
-						p2.AddRecipe("do", recipe.NewRecipe(recipe.Options{
+						p2.AddRecipe(replica.Name, recipe.NewRecipe(recipe.Options{
 							Dialer: dialer.Net{
 								Network:       "tcp",
 								Address:       replicaAddr,
@@ -172,8 +172,8 @@ func (T *Config) ListenAndServe() error {
 						}))
 					}
 
-					pools.Add(user.Name+"_ro", dbname, p2)
-					log.Printf("registered database user=%s database=%s", user.Name+"_ro", dbname)
+					pools.Add(creds2.Username, dbname, p2)
+					log.Printf("registered database user=%s database=%s", creds2.Username, dbname)
 				}
 			}
 		}
diff --git a/lib/gat/pool/pool.go b/lib/gat/pool/pool.go
index 5d093d1e..30d65423 100644
--- a/lib/gat/pool/pool.go
+++ b/lib/gat/pool/pool.go
@@ -147,6 +147,9 @@ func (T *Pool) removeRecipe(name string) {
 }
 
 func (T *Pool) scaleUp() {
+	log.Printf("scaling up")
+	defer log.Printf("finished scaling up")
+
 	backoff := T.options.ServerReconnectInitialTime
 	backingOff := false
 
@@ -206,6 +209,8 @@ func (T *Pool) scaleUp() {
 			backingOff = true
 		}
 
+		log.Printf("failed to dial server. trying again in %v", backoff)
+
 		time.Sleep(backoff)
 
 		backoff *= 2
@@ -356,7 +361,7 @@ func (T *Pool) ServeBot(
 	return T.serve(client, true)
 }
 
-func (T *Pool) serve(client *Client, initialize bool) error {
+func (T *Pool) serve(client *Client, initialized bool) error {
 	T.addClient(client)
 	defer T.removeClient(client)
 
@@ -375,7 +380,7 @@ func (T *Pool) serve(client *Client, initialize bool) error {
 		}
 	}()
 
-	if !initialize {
+	if !initialized {
 		server = T.acquireServer(client)
 
 		err, serverErr = Pair(T.options, client, server)
@@ -396,7 +401,7 @@ func (T *Pool) serve(client *Client, initialize bool) error {
 	for {
 		if server != nil && T.options.ReleaseAfterTransaction {
 			client.SetState(metrics.ConnStateIdle, uuid.Nil)
-			T.releaseServer(server) // TODO(garet) does this need to be a goroutine
+			T.releaseServer(server)
 			server = nil
 		}
 
-- 
GitLab