Skip to content

Commit

Permalink
Improve log messages caused by diagnostic connection events
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickTaibel committed Sep 12, 2023
1 parent f842258 commit c3154ac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
11 changes: 7 additions & 4 deletions connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func (this *Connection) authenticate() (err error) {

// Checks if the current connection is up or not
// If we do not get a response, or if we do not get a PONG reply, or if there is any error, returns false
// This is only used for diagnostic connections!
func (myConnection *Connection) CheckConnection() bool {
if myConnection.connection == nil {
return false
Expand All @@ -200,7 +201,8 @@ func (myConnection *Connection) CheckConnection() bool {
startWrite := time.Now()
err := protocol.WriteLine(protocol.SHORT_PING_COMMAND, myConnection.Writer, true)
if err != nil {
log.Error("CheckConnection: Could not write PING Err:%s Timing:%s", err, time.Now().Sub(startWrite))
log.Error("CheckConnection: Could not write PING on diagnostics connection. Err:%s Timing:%s",
err, time.Now().Sub(startWrite))
myConnection.Disconnect()
return false
}
Expand All @@ -212,11 +214,12 @@ func (myConnection *Connection) CheckConnection() bool {
return true
} else {
if err != nil {
log.Error("CheckConnection: Could not read PING. Error: %s Timing:%s", err, time.Now().Sub(startRead))
log.Error("CheckConnection: Could not read PING on diagnostics connection. Error: %s Timing:%s",
err, time.Now().Sub(startRead))
} else if isPrefix {
log.Error("CheckConnection: ReadLine returned prefix: %q", line)
log.Error("CheckConnection: ReadLine returned prefix on diagnostics connection: %q", line)
} else {
log.Error("CheckConnection: Expected PONG response. Got: %q", line)
log.Error("CheckConnection: Expected PONG response on diagnostics connection. Got: %q", line)
}
myConnection.Disconnect()
return false
Expand Down
9 changes: 2 additions & 7 deletions connection/connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (cp *ConnectionPool) getDiagnosticConnection() (connection *Connection, err
cp.diagnosticConnectionLock.Lock()

if err := cp.diagnosticConnection.ReconnectIfNecessary(); err != nil {
log.Error("The diangnostic connection is down for %s:%s : %s", cp.Protocol, cp.Endpoint, err)
log.Error("The diagnostic connection is down for %s:%s : %s", cp.Protocol, cp.Endpoint, err)
cp.diagnosticConnectionLock.Unlock()
return nil, err
}
Expand Down Expand Up @@ -172,6 +172,7 @@ func (cp *ConnectionPool) IsConnected() bool {

// Checks the state of connections in this connection pool
// If a remote server has severe lag, mysteriously goes away, or stops responding all-together, returns false
// This is only used for diagnostic connections!
func (cp *ConnectionPool) CheckConnectionState() (isUp bool) {
isUp = true
defer func() {
Expand All @@ -185,12 +186,6 @@ func (cp *ConnectionPool) CheckConnectionState() (isUp bool) {
}
defer cp.releaseDiagnosticConnection()

//If we failed to bind, or if our PING fails, the pool is down
if connection == nil || connection.connection == nil {
isUp = false
return
}

if !connection.CheckConnection() {
connection.Disconnect()
isUp = false
Expand Down
7 changes: 6 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,23 @@ func (this *RedisMultiplexer) AddConnection(remoteProtocol, remoteEndpoint strin
}
}

// Counts the number of active endpoints on the server
// Counts the number of active endpoints (connection pools) on the server
func (this *RedisMultiplexer) countActiveConnections() (activeConnections int) {
activeConnections = 0
for _, connectionPool := range this.ConnectionCluster {
if connectionPool.CheckConnectionState() {
activeConnections++
}
}

if this.activeConnectionCount < activeConnections {
log.Info("Connected diagnostics connection.")
}
return
}

// Checks the status of all connections, and calculates how many of them are currently up
// This only counts connection pools / diagnostic connections not real redis sessions
func (this *RedisMultiplexer) maintainConnectionStates() {
var m runtime.MemStats
for this.active {
Expand Down

0 comments on commit c3154ac

Please sign in to comment.