Skip to content

Commit

Permalink
tpch: check connection before each run iteration (#147)
Browse files Browse the repository at this point in the history
Signed-off-by: zyguan <[email protected]>

Signed-off-by: zyguan <[email protected]>
  • Loading branch information
zyguan authored Oct 9, 2022
1 parent c482fcf commit b1e0fb5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/workload/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type TpcState struct {
}

func (t *TpcState) RefreshConn(ctx context.Context) error {
if t.Conn != nil {
t.Conn.Close()
}
conn, err := t.DB.Conn(ctx)
if err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions tpch/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ func (w *Workloader) CheckPrepare(ctx context.Context, threadID int) error {
func (w *Workloader) Run(ctx context.Context, threadID int) error {
s := w.getState(ctx)
defer w.updateState(ctx)
if err := s.Conn.PingContext(ctx); err != nil {
if err := s.RefreshConn(ctx); err != nil {
return err
}
}

queryName := w.cfg.QueryNames[s.queryIdx%len(w.cfg.QueryNames)]
query := query(w.cfg.Driver, queryName)
Expand Down

0 comments on commit b1e0fb5

Please sign in to comment.