Skip to content

Commit

Permalink
Hide router notice msgs under extended debug setting (#212)
Browse files Browse the repository at this point in the history
* Fix main

* Hide router notice msgs under extended debug setting

* Rename setting
  • Loading branch information
reshke committed Jul 14, 2023
1 parent 031f0f7 commit 453c1a0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
6 changes: 4 additions & 2 deletions cmd/router/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,22 @@ var runCmd = &cobra.Command{
defer cancelCtx()

var pprofCpuFile *os.File

var pprofMemFile *os.File

if cpuProfile {
spqrlog.Zero.Fatal().Msg("starting cpu profile")
pprofCpuFile, err = os.Create(path.Join(path.Dir(profileFile), "cpu"+path.Base(profileFile)))

if err != nil {
spqrlog.Zero.Info().
Err(err).
Msg("got an error while starting cpu profile")
return err
}
if err := pprof.StartCPUProfile(pprofCpuFile); err != nil {

if err := pprof.StartCPUProfile(pprofCpuFile); err != nil {
spqrlog.Zero.Info().

Err(err).
Msg("got an error while starting cpu profile")
return err
Expand Down
1 change: 1 addition & 0 deletions pkg/config/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Router struct {

MaintainParams bool `json:"maintain_params" toml:"maintain_params" yaml:"maintain_params"`
WithJaeger bool `json:"with_jaeger" toml:"with_jaeger" yaml:"with_jaeger"`
PgprotoDebug bool `json:"pgproto_debug" toml:"pgproto_debug" yaml:"pgproto_debug"`

PidFileName string `json:"pid_filename" toml:"pid_filename" yaml:"pid_filename"`
LogFileName string `json:"log_filename" toml:"log_filename" yaml:"log_filename"`
Expand Down
7 changes: 3 additions & 4 deletions router/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,13 @@ func (cl *PsqlClient) ReplyDebugNotice(msg string) error {
}

func (cl *PsqlClient) ReplyDebugNoticef(fmtString string, args ...interface{}) error {
return cl.ReplyDebugNotice(fmt.Sprintf(fmtString, args...)) // TODO perfomance issue
return cl.ReplyDebugNotice(fmt.Sprintf(fmtString, args...))
}

func (cl *PsqlClient) ReplyWarningMsg(errmsg string) error {
for _, msg := range []pgproto3.BackendMessage{
&pgproto3.ErrorResponse{
Message: fmt.Sprintf("client %p: error %v", cl, errmsg), // TODO perfomance issue
Message: fmt.Sprintf("client %p: error %v", cl, errmsg),
Severity: "WARNING",
},
} {
Expand All @@ -410,7 +410,7 @@ func (cl *PsqlClient) ReplyWarningMsg(errmsg string) error {
}

func (cl *PsqlClient) ReplyWarningf(fmtString string, args ...interface{}) error {
return cl.ReplyWarningMsg(fmt.Sprintf(fmtString, args...)) // TODO perfomance issue
return cl.ReplyWarningMsg(fmt.Sprintf(fmtString, args...))
}

// Deprecated: use spqrlog.GetPointer instead
Expand Down Expand Up @@ -826,7 +826,6 @@ func (cl *PsqlClient) ProcQuery(query pgproto3.FrontendMessage, waitForResp bool
Str("server", cl.server.Name()).
Type("query-type", query).
Msg("client process query")
_ = cl.ReplyDebugNoticef("executing your query %v", query)
cl.mu.RLock()
defer cl.mu.RUnlock()
if cl.server == nil {
Expand Down
22 changes: 16 additions & 6 deletions router/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func procQuery(rst rulerouter.RelayStateMgr, query string, msg pgproto3.Frontend
case parser.ParseStateTXBegin:
if rst.TxStatus() != txstatus.TXIDLE {
// ignore this
_ = rst.Client().ReplyWarningf("there is already transaction in progress")
if rst.PgprotoDebug() {
_ = rst.Client().ReplyWarningf("there is already transaction in progress")
}
return rst.Client().ReplyCommandComplete(rst.TxStatus(), "BEGIN")
}
rst.AddSilentQuery(msg)
Expand All @@ -63,7 +65,9 @@ func procQuery(rst rulerouter.RelayStateMgr, query string, msg pgproto3.Frontend
return rst.Client().ReplyCommandComplete(rst.TxStatus(), "BEGIN")
case parser.ParseStateTXCommit:
if rst.TxStatus() != txstatus.TXACT {
_ = rst.Client().ReplyWarningf("there is no transaction in progress")
if rst.PgprotoDebug() {
_ = rst.Client().ReplyWarningf("there is no transaction in progress")
}
return rst.Client().ReplyCommandComplete(rst.TxStatus(), "COMMIT")
}
if !cmngr.ConnectionActive(rst) {
Expand All @@ -77,7 +81,9 @@ func procQuery(rst rulerouter.RelayStateMgr, query string, msg pgproto3.Frontend
return err
case parser.ParseStateTXRollback:
if rst.TxStatus() != txstatus.TXACT {
_ = rst.Client().ReplyWarningf("there is no transaction in progress")
if rst.PgprotoDebug() {
_ = rst.Client().ReplyWarningf("there is no transaction in progress")
}
return rst.Client().ReplyCommandComplete(rst.TxStatus(), "ROLLBACK")
}

Expand Down Expand Up @@ -239,8 +245,10 @@ func ProcessMessage(qr qrouter.QueryRouter, cmngr rulerouter.PoolMgr, rst rulero
Str("name", q.Name).
Str("query", q.Query).
Uint64("hash", hash)
if err := rst.Client().ReplyDebugNoticef("name %v, query %v, hash %d", q.Name, q.Query, hash); err != nil {
return err
if rst.PgprotoDebug() {
if err := rst.Client().ReplyDebugNoticef("name %v, query %v, hash %d", q.Name, q.Query, hash); err != nil {
return err
}
}
rst.Client().StorePreparedStatement(q.Name, q.Query)
// simply reply witch ok parse complete
Expand Down Expand Up @@ -332,7 +340,9 @@ func Frontend(qr qrouter.QueryRouter, cl client.RouterClient, cmngr rulerouter.P
Uint("client", spqrlog.GetPointer(cl)).
Msg("process frontend for route")

_ = cl.ReplyDebugNoticef("process frontend for route %s %s", cl.Usr(), cl.DB())
if rcfg.PgprotoDebug {
_ = cl.ReplyDebugNoticef("process frontend for route %s %s", cl.Usr(), cl.DB())
}
rst := rulerouter.NewRelayState(qr, cl, cmngr, rcfg)

defer rst.Close()
Expand Down
18 changes: 13 additions & 5 deletions router/rulerouter/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type RelayStateMgr interface {
ActiveShardsReset()
TxActive() bool

PgprotoDebug() bool

RelayStep(msg pgproto3.FrontendMessage, waitForResp bool, replyCl bool) (txstatus.TXStatus, error)

UnRouteWithError(shkey []kr.ShardKey, errmsg error) error
Expand Down Expand Up @@ -63,6 +65,8 @@ type RelayStateImpl struct {
WorldShardFallback bool
routerMode config.RouterMode

pgprotoDebug bool

routingState qrouter.RoutingState

Qr qrouter.QueryRouter
Expand All @@ -82,6 +86,10 @@ func (rst *RelayStateImpl) SetTxStatus(status txstatus.TXStatus) {
rst.txStatus = status
}

func (rst *RelayStateImpl) PgprotoDebug() bool {
return rst.pgprotoDebug
}

func (rst *RelayStateImpl) Client() client.RouterClient {
return rst.Cl
}
Expand Down Expand Up @@ -128,6 +136,7 @@ func NewRelayState(qr qrouter.QueryRouter, client client.RouterClient, manager P
WorldShardFallback: rcfg.WorldShardFallback,
routerMode: config.RouterMode(rcfg.RouterMode),
maintain_params: rcfg.MaintainParams,
pgprotoDebug: rcfg.PgprotoDebug,
}
}

Expand Down Expand Up @@ -186,9 +195,10 @@ func (rst *RelayStateImpl) procRoutes(routes []*qrouter.DataShardRoute) error {
for _, shr := range routes {
rst.activeShards = append(rst.activeShards, shr.Shkey)
}
// TDB: hide under setting
if err := rst.Cl.ReplyDebugNoticef("matched datashard routes %+v", routes); err != nil {
return err
if rst.PgprotoDebug() {
if err := rst.Cl.ReplyDebugNoticef("matched datashard routes %+v", routes); err != nil {
return err
}
}

if err := rst.Connect(routes); err != nil {
Expand Down Expand Up @@ -296,7 +306,6 @@ func (rst *RelayStateImpl) Connect(shardRoutes []*qrouter.DataShardRoute) error
return err
}


spqrlog.Zero.Debug().
Str("user", rst.Cl.Usr()).
Str("db", rst.Cl.DB()).
Expand Down Expand Up @@ -440,7 +449,6 @@ func (rst *RelayStateImpl) CompleteRelay(replyCl bool) error {
return nil
}


spqrlog.Zero.Debug().
Uint("client", spqrlog.GetPointer(rst.Client())).
Str("txstatus", rst.txStatus.String()).
Expand Down

0 comments on commit 453c1a0

Please sign in to comment.