Skip to content

Commit

Permalink
Add total connections in error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyang-hu committed Aug 29, 2023
1 parent 4b7909e commit 1946773
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
26 changes: 13 additions & 13 deletions x/mongo/driver/topology/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ func (e ServerSelectionError) Unwrap() error {

// WaitQueueTimeoutError represents a timeout when requesting a connection from the pool
type WaitQueueTimeoutError struct {
Wrapped error
pinnedConnections *pinnedConnections
maxPoolSize uint64
totalConnectionCount int
availableConnectionCount int
waitDuration time.Duration
Wrapped error
pinnedConnections *pinnedConnections
maxPoolSize uint64
totalConnections int
availableConnections int
waitDuration time.Duration
}

type pinnedConnections struct {
Expand All @@ -102,18 +102,18 @@ func (w WaitQueueTimeoutError) Error() string {
)
}

msg := fmt.Sprintf("%s; maxPoolSize: %d, ", errorMsg, w.maxPoolSize)
msg := fmt.Sprintf("%s; total connections: %d, maxPoolSize: %d, ", errorMsg, w.totalConnections, w.maxPoolSize)
if pinnedConnections := w.pinnedConnections; pinnedConnections != nil {
openConnectionCount := uint64(w.totalConnectionCount) -
(*pinnedConnections).cursorConnections -
(*pinnedConnections).transactionConnections
openConnectionCount := uint64(w.totalConnections) -
pinnedConnections.cursorConnections -
pinnedConnections.transactionConnections
msg += fmt.Sprintf("connections in use by cursors: %d, connections in use by transactions: %d, connections in use by other operations: %d, ",
(*pinnedConnections).cursorConnections,
(*pinnedConnections).transactionConnections,
pinnedConnections.cursorConnections,
pinnedConnections.transactionConnections,
openConnectionCount,
)
}
msg += fmt.Sprintf("idle connections: %d, wait duration: %s", w.availableConnectionCount, w.waitDuration.String())
msg += fmt.Sprintf("idle connections: %d, wait duration: %s", w.availableConnections, w.waitDuration.String())
return msg
}

Expand Down
10 changes: 5 additions & 5 deletions x/mongo/driver/topology/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,11 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
}

err := WaitQueueTimeoutError{
Wrapped: ctx.Err(),
maxPoolSize: p.maxSize,
totalConnectionCount: p.totalConnectionCount(),
availableConnectionCount: p.availableConnectionCount(),
waitDuration: duration,
Wrapped: ctx.Err(),
maxPoolSize: p.maxSize,
totalConnections: p.totalConnectionCount(),
availableConnections: p.availableConnectionCount(),
waitDuration: duration,
}
if p.loadBalanced {
err.pinnedConnections = &pinnedConnections{
Expand Down

0 comments on commit 1946773

Please sign in to comment.