Skip to content

Commit 74f4e3f

Browse files
authored
Fixed reconnect option (#38)
1 parent 101a77b commit 74f4e3f

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

acronis-db-bench/engine/main.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,18 @@ func Main() {
201201

202202
if testOpts.DBOpts.Reconnect {
203203
b.WorkerPreRunFunc = func(worker *benchmark.BenchmarkWorker) {
204-
var workerData = worker.Data.(*DBWorkerData)
205-
206-
if workerData.workingConn != nil {
204+
if workerData, ok := worker.Data.(*DBWorkerData); ok && workerData.workingConn != nil {
207205
workerData.workingConn.Close()
208206
}
209-
210207
worker.Data = nil
208+
209+
// Reinitialize the worker
210+
var workerData DBWorkerData
211+
var err error
212+
if workerData.workingConn, err = NewDBConnector(&b.TestOpts.(*TestOpts).DBOpts, worker.WorkerID, false, worker.Logger, 1); err != nil {
213+
b.Exit(fmt.Sprintf("Failed to reinitialize database connection for worker %d: %v", worker.WorkerID, err))
214+
}
215+
worker.Data = &workerData
211216
}
212217
}
213218

acronis-db-bench/engine/workers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func initWorker(worker *benchmark.BenchmarkWorker, testDesc *TestDesc, rowsRequi
2727
var err error
2828

2929
if workerData.workingConn, err = NewDBConnector(&b.TestOpts.(*TestOpts).DBOpts, workerID, false, worker.Logger, 1); err != nil {
30-
return
30+
b.Exit(fmt.Sprintf("Failed to initialize database connection for worker %d: %v", workerID, err))
3131
}
3232

3333
worker.Data = &workerData

0 commit comments

Comments
 (0)