File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -11,13 +11,23 @@ import (
11
11
12
12
// TpcState saves state for each thread
13
13
type TpcState struct {
14
+ DB * sql.DB
14
15
Conn * sql.Conn
15
16
16
17
R * rand.Rand
17
18
18
19
Buf * util.BufAllocator
19
20
}
20
21
22
+ func (t * TpcState ) RefreshConn (ctx context.Context ) error {
23
+ conn , err := t .DB .Conn (ctx )
24
+ if err != nil {
25
+ return err
26
+ }
27
+ t .Conn = conn
28
+ return nil
29
+ }
30
+
21
31
// NewTpcState creates a base TpcState
22
32
func NewTpcState (ctx context.Context , db * sql.DB ) * TpcState {
23
33
var conn * sql.Conn
@@ -32,6 +42,7 @@ func NewTpcState(ctx context.Context, db *sql.DB) *TpcState {
32
42
r := rand .New (rand .NewSource (time .Now ().UnixNano ()))
33
43
34
44
s := & TpcState {
45
+ DB : db ,
35
46
Conn : conn ,
36
47
R : r ,
37
48
Buf : util .NewBufAllocator (),
Original file line number Diff line number Diff line change @@ -192,8 +192,14 @@ func getTPCCState(ctx context.Context) *tpccState {
192
192
// Run implements Workloader interface
193
193
func (w * Workloader ) Run (ctx context.Context , threadID int ) error {
194
194
s := getTPCCState (ctx )
195
-
196
- if s .newOrderStmts == nil {
195
+ refreshConn := false
196
+ if err := s .Conn .PingContext (ctx ); err != nil {
197
+ if err := s .RefreshConn (ctx ); err != nil {
198
+ return err
199
+ }
200
+ refreshConn = true
201
+ }
202
+ if s .newOrderStmts == nil || refreshConn {
197
203
s .newOrderStmts = map [string ]* sql.Stmt {
198
204
newOrderSelectCustomer : prepareStmt (ctx , s .Conn , newOrderSelectCustomer ),
199
205
newOrderSelectDistrict : prepareStmt (ctx , s .Conn , newOrderSelectDistrict ),
You can’t perform that action at this time.
0 commit comments