Skip to content

Commit

Permalink
Ping database in some commands (#435)
Browse files Browse the repository at this point in the history
`ping`, `hello`, `isMaster` commands now check database connection.
  • Loading branch information
AlekSi committed Apr 4, 2022
1 parent f65dd0f commit a64780c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/handlers/pg/msg_hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import (

// MsgHello returns a document that describes the role of the instance.
func (h *Handler) MsgHello(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, error) {
if err := h.pgPool.Ping(ctx); err != nil {
return nil, err
}

var reply wire.OpMsg
err := reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{must.NotFail(types.NewDocument(
Expand Down
4 changes: 4 additions & 0 deletions internal/handlers/pg/msg_ismaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import (

// MsgIsMaster returns a document that describes the role of the instance.
func (h *Handler) MsgIsMaster(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, error) {
if err := h.pgPool.Ping(ctx); err != nil {
return nil, err
}

var reply wire.OpMsg
err := reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{must.NotFail(types.NewDocument(
Expand Down
4 changes: 4 additions & 0 deletions internal/handlers/pg/msg_ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import (

// MsgPing OpMsg containing a ping, used to test whether a server is responding to commands.
func (h *Handler) MsgPing(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, error) {
if err := h.pgPool.Ping(ctx); err != nil {
return nil, err
}

var reply wire.OpMsg
err := reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{types.MustNewDocument(
Expand Down

0 comments on commit a64780c

Please sign in to comment.