Refine, log unhealthy replica

This commit is contained in:
binwiederhier
2026-03-11 21:07:58 -04:00
parent ac65df1e83
commit 85bdfc61ce
10 changed files with 86 additions and 60 deletions
+5 -6
View File
@@ -4,7 +4,6 @@ import (
"bytes"
"context"
"crypto/sha256"
"database/sql"
"embed"
"encoding/base64"
"encoding/json"
@@ -186,20 +185,20 @@ func New(conf *Config) (*Server, error) {
if err != nil {
return nil, err
}
var replicas []*sql.DB
var replicas []*db.Host
for _, replicaURL := range conf.DatabaseReplicaURLs {
r, err := pg.Open(replicaURL)
r, err := pg.OpenReplica(replicaURL)
if err != nil {
// Close already-opened replicas before returning
for _, opened := range replicas {
opened.Close()
opened.DB.Close()
}
primary.Close()
primary.DB.Close()
return nil, fmt.Errorf("failed to open database replica: %w", err)
}
replicas = append(replicas, r)
}
pool = db.NewDB(primary, replicas)
pool = db.New(primary, replicas)
}
messageCache, err := createMessageCache(conf, pool)
if err != nil {