@@ -9,8 +9,12 @@ import (
99 "sort"
1010 "strings"
1111
12+ _ "net/http/pprof"
13+
1214 "github.com/acronis/perfkit/benchmark"
13- embeddedpostgres "github.com/fergusstrange/embedded-postgres" // embedder postgres
15+ "github.com/acronis/perfkit/db"
16+
17+ _ "github.com/acronis/perfkit/db/sql" // sql drivers
1418)
1519
1620// Version is a version of the acronis-db-bench
@@ -29,11 +33,10 @@ func printVersion() {
2933
3034// TestOpts is a structure to store all the test options
3135type TestOpts struct {
32- DBOpts benchmark.DatabaseOpts
33- BenchOpts BenchOpts
34- EmbeddedPostgresOpts EmbeddedPostgresOpts
35- TestcaseOpts TestcaseOpts
36- CTIOpts CTIOpts
36+ DBOpts DatabaseOpts
37+ BenchOpts BenchOpts
38+ TestcaseOpts TestcaseOpts
39+ CTIOpts CTIOpts
3740}
3841
3942// BenchOpts is a structure to store all the benchmark options
@@ -70,17 +73,17 @@ type TestcaseOpts struct {
7073
7174// DBTestData is a structure to store all the test data
7275type DBTestData struct {
73- TestDesc * TestDesc
74- EventBus * EventBus
75- EmbeddedPostgres * embeddedpostgres. EmbeddedPostgres
76- EffectiveBatch int // EffectiveBatch reflects the default value if the --batch option is not set, it can be different for different tests
76+ TestDesc * TestDesc
77+ EventBus * EventBus
78+ TenantsCache * TenantsCache
79+ EffectiveBatch int // EffectiveBatch reflects the default value if the --batch option is not set, it can be different for different tests
7780
7881 scores map [string ][]benchmark.Score
7982}
8083
8184// DBWorkerData is a structure to store all the worker data
8285type DBWorkerData struct {
83- conn * benchmark. DBConnector
86+ conn * DBConnector
8487}
8588
8689var header = strings .Repeat ("=" , 120 ) + "\n "
@@ -97,17 +100,12 @@ func Main() {
97100 var testOpts TestOpts
98101 b .Cli .AddFlagGroup ("Database options" , "" , & testOpts .DBOpts )
99102 b .Cli .AddFlagGroup ("acronis-db-bench specific options" , "" , & testOpts .BenchOpts )
100- b .Cli .AddFlagGroup ("Embedded Postgres specific options" , "" , & testOpts .EmbeddedPostgresOpts )
101103 b .Cli .AddFlagGroup ("Testcase specific options" , "" , & testOpts .TestcaseOpts )
102104 b .Cli .AddFlagGroup ("CTI-pattern simulation test options" , "" , & testOpts .CTIOpts )
103105
104106 return & testOpts
105107 }
106108
107- b .PreExit = func () {
108- finiEmbeddedPostgres (b )
109- }
110-
111109 b .PrintScore = func (score benchmark.Score ) {
112110 testData := b .Vault .(* DBTestData )
113111 var format string
@@ -148,15 +146,22 @@ func Main() {
148146 b .Vault .(* DBTestData ).EffectiveBatch = 1
149147 }
150148
149+ var dialectName , err = db .GetDialectName (b .TestOpts .(* TestOpts ).DBOpts .ConnString )
150+ if err != nil {
151+ b .Exit (err )
152+ }
153+
151154 if testOpts .BenchOpts .List {
152155 groups , _ := GetTests ()
153156 fmt .Printf (header ) //nolint:staticcheck
154157 for _ , g := range groups {
158+
155159 str := fmt .Sprintf (" -- %s" , g .name ) //nolint:perfsprint
156160 fmt .Printf ("\n %s %s\n \n " , str , strings .Repeat ("-" , 130 - len (str )))
161+
157162 var testsOutput []string
158163 for _ , t := range g .tests {
159- if testOpts . DBOpts . Driver != "" && ! t .dbIsSupported (testOpts . DBOpts . Driver ) {
164+ if dialectName != "" && ! t .dbIsSupported (dialectName ) {
160165 continue
161166 }
162167 testsOutput = append (testsOutput , fmt .Sprintf (" %-39s : %s : %s\n " , t .name , t .getDBs (), t .description ))
@@ -166,15 +171,13 @@ func Main() {
166171 }
167172 fmt .Printf ("\n " )
168173 fmt .Printf ("Databases symbol legend:\n \n " )
169- for _ , db := range benchmark .GetDatabases () {
174+ for _ , db := range db .GetDatabases () {
170175 fmt .Printf (" %s - %s;" , db .Symbol , db .Name )
171176 }
172177 fmt .Printf ("\n \n " )
173178 b .Exit ()
174179 }
175180
176- initEmbeddedPostgres (b )
177-
178181 if testOpts .BenchOpts .Describe {
179182 describeTest (b , testOpts )
180183 b .Exit ()
@@ -198,17 +201,24 @@ func Main() {
198201 if testOpts .DBOpts .Reconnect {
199202 b .PreWorker = func (workerId int ) {
200203 conn := b .WorkerData [workerId ].(* DBWorkerData ).conn
201- conn .Close ()
204+ conn .database . Close ()
202205 }
203206 }
204207
205208 c := dbConnector (b )
206209
207- driver , version := c .GetVersion ()
210+ driver , version , err := c .database .GetVersion ()
211+ if err != nil {
212+ b .Exit ("Failed to get database version: %v" , err )
213+ }
214+
208215 fmt .Printf ("Connected to '%s' database: %s\n " , driver , version )
209216 fmt .Printf (header ) //nolint:staticcheck
210217
211- content , dbInfo := c .GetInfo (version )
218+ content , dbInfo , err := c .database .GetInfo (version )
219+ if err != nil {
220+ b .Exit ("Failed to get database info: %v" , err )
221+ }
212222
213223 if testOpts .BenchOpts .Info || b .Logger .LogLevel > benchmark .LogInfo {
214224 if testOpts .BenchOpts .Info {
@@ -222,7 +232,7 @@ func Main() {
222232
223233 if testOpts .BenchOpts .ProfilerPort > 0 {
224234 go func () {
225- err : = http .ListenAndServe (fmt .Sprintf ("localhost:%d" , testOpts .BenchOpts .ProfilerPort ), nil )
235+ err = http .ListenAndServe (fmt .Sprintf ("localhost:%d" , testOpts .BenchOpts .ProfilerPort ), nil )
226236 if err != nil {
227237 b .Exit ("Failed to start profiler server: %v" , err )
228238 }
@@ -232,8 +242,10 @@ func Main() {
232242 }
233243
234244 b .Init = func () {
235- b .TenantsCache .SetTenantsWorkingSet (b .TestOpts .(* TestOpts ).BenchOpts .TenantsWorkingSet )
236- b .TenantsCache .SetCTIsWorkingSet (b .TestOpts .(* TestOpts ).BenchOpts .CTIsWorkingSet )
245+ b .Vault .(* DBTestData ).TenantsCache = NewTenantsCache (b )
246+
247+ b .Vault .(* DBTestData ).TenantsCache .SetTenantsWorkingSet (b .TestOpts .(* TestOpts ).BenchOpts .TenantsWorkingSet )
248+ b .Vault .(* DBTestData ).TenantsCache .SetCTIsWorkingSet (b .TestOpts .(* TestOpts ).BenchOpts .CTIsWorkingSet )
237249
238250 if b .Logger .LogLevel > benchmark .LogInfo && ! testOpts .BenchOpts .Info {
239251 b .Log (benchmark .LogTrace , 0 , getDBInfo (b , content ))
@@ -298,9 +310,15 @@ func executeTests(b *benchmark.Benchmark, testOpts *TestOpts) {
298310 if ! exists {
299311 b .Exit (fmt .Sprintf ("Test: '%s' doesn't exist, see the list of available tests using --list option\n " , testOpts .BenchOpts .Test ))
300312 }
313+
314+ var dialectName , err = db .GetDialectName (testOpts .DBOpts .ConnString )
315+ if err != nil {
316+ b .Exit (err )
317+ }
318+
301319 test := tests [testOpts .BenchOpts .Test ]
302- if ! test .dbIsSupported (testOpts . DBOpts . Driver ) {
303- b .Exit (fmt .Sprintf ("Test: '%s' doesn't support '%s' database\n " , testOpts .BenchOpts .Test , testOpts . DBOpts . Driver ))
320+ if ! test .dbIsSupported (dialectName ) {
321+ b .Exit (fmt .Sprintf ("Test: '%s' doesn't support '%s' database\n " , testOpts .BenchOpts .Test , dialectName ))
304322 }
305323 test .launcherFunc (b , test )
306324}
0 commit comments